text: Title: Inconsistent results in using torch.jit.script API from API documentation.
  Body: ### 🐛 Describe the bug
  
  Expects an AttributeError is raised since the ignored_method is skipped in compiling as per API documentation.
  
  ```python
  def test_script_module_with_ignored_method(self):
          class IgnoredMethodModule(nn.Module):
              def forward(self, x):
                  return x * 2
  
              @torch.jit.ignore
              def ignored_method(self, x):
                  return x * 3
  
          module = IgnoredMethodModule()
          scripted_module = torch.jit.script(module)
          input_tensor = torch.tensor(5)
          self.assertEqual(scripted_module(input_tensor), module(input_tensor))
          # Ensure ignored method is not part of the scripted module
          with self.assertRaises(AttributeError):
              scripted_module.ignored_method(input_tensor)
  ```
  
  ```
  ======================================================================
  FAIL: test_script_module_with_ignored_method (__main__.TestTorchJitScript)
  ----------------------------------------------------------------------
  Traceback (most recent call last):
    File "/home/user/projects/api_guided_testgen/out/bug_detect_gpt4o/exec/basic_rag_apidoc/torch/torch.jit.script.py", line 70, in test_script_module_with_ignored_method
      scripted_module.ignored_method(input_tensor)
  AssertionError: AttributeError not raised
  ```
  
  ### Versions
  
  Collecting environment information...
  PyTorch version: 2.5.0
  Is debug build: False
  CUDA used to build PyTorch: None
  ROCM used to build PyTorch: N/A
  
  OS: Ubuntu 22.04.5 LTS (x86_64)
  GCC version: (Ubuntu 9.5.0-1ubuntu1~22.04) 9.5.0
  Clang version: 14.0.0-1ubuntu1.1
  CMake version: version 3.22.1
  Libc version: glibc-2.35
  
  Python version: 3.9.21 (main, Dec 11 2024, 16:24:11)  [GCC 11.2.0] (64-bit runtime)
  Python platform: Linux-6.8.0-52-generic-x86_64-with-glibc2.35
  Is CUDA available: False
  CUDA runtime version: No CUDA
  CUDA_MODULE_LOADING set to: N/A
  GPU models and configuration: No CUDA
  Nvidia driver version: No CUDA
  cuDNN version: No CUDA
  HIP runtime version: N/A
  MIOpen runtime version: N/A
  Is XNNPACK available: True
  
  CPU:
  Architecture:                         x86_64
  CPU op-mode(s):                       32-bit, 64-bit
  Address sizes:                        39 bits physical, 48 bits virtual
  Byte Order:                           Little Endian
  CPU(s):                               4
  On-line CPU(s) list:                  0-3
  Vendor ID:                            GenuineIntel
  Model name:                           Intel(R) Xeon(R) E-2224G CPU @ 3.50GHz
  CPU family:                           6
  Model:                                158
  Thread(s) per core:                   1
  Core(s) per socket:                   4
  Socket(s):                            1
  Stepping:                             10
  CPU max MHz:                          4700.0000
  CPU min MHz:                          800.0000
  BogoMIPS:                             6999.82
  Flags:                                fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb pti ssbd ibrs ibpb stibp tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp vnmi md_clear flush_l1d arch_capabilities
  Virtualization:                       VT-x
  L1d cache:                            128 KiB (4 instances)
  L1i cache:                            128 KiB (4 instances)
  L2 cache:                             1 MiB (4 instances)
  L3 cache:                             8 MiB (1 instance)
  NUMA node(s):                         1
  NUMA node0 CPU(s):                    0-3
  Vulnerability Gather data sampling:   Mitigation; Microcode
  Vulnerability Itlb multihit:          KVM: Mitigation: VMX disabled
  Vulnerability L1tf:                   Mitigation; PTE Inversion; VMX conditional cache flushes, SMT disabled
  Vulnerability Mds:                    Mitigation; Clear CPU buffers; SMT disabled
  Vulnerability Meltdown:               Mitigation; PTI
  Vulnerability Mmio stale data:        Mitigation; Clear CPU buffers; SMT disabled
  Vulnerability Reg file data sampling: Not affected
  Vulnerability Retbleed:               Mitigation; IBRS
  Vulnerability Spec rstack overflow:   Not affected
  Vulnerability Spec store bypass:      Mitigation; Speculative Store Bypass disabled via prctl
  Vulnerability Spectre v1:             Mitigation; usercopy/swapgs barriers and __user pointer sanitization
  Vulnerability Spectre v2:             Mitigation; IBRS; IBPB conditional; STIBP disabled; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
  Vulnerability Srbds:                  Mitigation; Microcode
  Vulnerability Tsx async abort:        Mitigation; TSX disabled
  
  Versions of relevant libraries:
  [pip3] numpy==2.0.1
  [pip3] torch==2.5.0
  [pip3] torchaudio==2.5.0
  [pip3] torchvision==0.20.0
  [conda] blas                      1.0                         mkl  
  [conda] cpuonly                   2.0                           0    pytorch
  [conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
  [conda] libjpeg-turbo             2.0.0                h9bf148f_0    pytorch
  [conda] mkl                       2023.1.0         h213fc3f_46344  
  [conda] mkl-service               2.4.0            py39h5eee18b_2  
  [conda] mkl_fft                   1.3.11           py39h5eee18b_0  
  [conda] mkl_random                1.2.8            py39h1128e8f_0  
  [conda] numpy                     2.0.1            py39h5f9d8c6_1  
  [conda] numpy-base                2.0.1            py39hb5e798b_1  
  [conda] pytorch                   2.5.0               py3.9_cpu_0    pytorch
  [conda] pytorch-mutex             1.0                         cpu    pytorch
  [conda] torchaudio                2.5.0                  py39_cpu    pytorch
  [conda] torchvision               0.20.0                 py39_cpu    pytorch
  
  cc @EikanWang @jgong5 @wenzhe-nrv @sanchitintel