Skip to content

torch._dynamo.exc.InternalTorchDynamoError: TypeError: cannot create weak reference to 'torch.Event' object #1969

@shangerxin

Description

@shangerxin

🐛 Describe the bug

After migrate the test test_ctx_manager.py to XPU. The test case est_gpu_event_across_graph_break failed with error.

Error Message

____________________________________________________ CtxManagerTests.test_gpu_event_across_graph_break _____________________________________________________
Traceback (most recent call last):
File "/home/erxin/torch-ut/v/lib/python3.10/unittest/case.py", line 59, in testPartExecutor
yield
File "/home/erxin/torch-ut/v/lib/python3.10/unittest/case.py", line 591, in run
self._callTestMethod(testMethod)
File "/home/erxin/torch-ut/v/lib/python3.10/unittest/case.py", line 549, in _callTestMethod
method()
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/testing/_internal/common_utils.py", line 3224, in wrapper
method(*args, **kwargs)
File "/home/erxin/torch-ut/pytorch/test/dynamo/test_ctx_manager.py", line 450, in test_gpu_event_across_graph_break
res = opt_fn(x)
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/eval_frame.py", line 804, in compile_wrapper
return fn(*args, **kwargs)
File "/home/erxin/torch-ut/pytorch/test/dynamo/test_ctx_manager.py", line 439, in fn
print("foo")
File "/home/erxin/torch-ut/pytorch/test/dynamo/test_ctx_manager.py", line 441, in torch_dynamo_resume_in_fn_at_439
torch.accelerator.current_stream().wait_event(e)
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 1723, in call
result = self._torchdynamo_orig_backend(
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 1476, in call
result = self._inner_convert(
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 693, in call
result = _compile(
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 1346, in _compile
raise InternalTorchDynamoError(
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 1281, in _compile
guarded_code, tracer_output = compile_inner(
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_utils_internal.py", line 92, in wrapper_function
return function(*args, **kwargs)
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 971, in compile_inner
return _compile_inner(code, one_graph, hooks, transform)
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 1006, in _compile_inner
dynamo_output = compile_frame(code, transform, restart_reasons)
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 855, in compile_frame
bytecode, tracer_output = transform_code_object(code, transform)
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/bytecode_transformation.py", line 1468, in transform_code_object
tracer_output = transformations(instructions, code_options)
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 935, in transform
tracer_output = trace_frame(
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 311, in _fn
return fn(*args, **kwargs)
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 820, in trace_frame
run_tracer()
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/convert_frame.py", line 802, in run_tracer
tracer.run()
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 3611, in run
super().run()
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 1424, in run
while self.step():
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 1326, in step
self.dispatch_table[inst.opcode](self, inst)
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 892, in wrapper
return inner_fn(self, inst)
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 2248, in CALL_FUNCTION
self.call_function(fn, args, {})
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/symbolic_convert.py", line 1245, in call_function
self.push(fn.call_function(self, args, kwargs)) # type: ignore[arg-type]
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/variables/misc.py", line 1115, in call_function
return self.obj.call_method(tx, self.name, args, kwargs)
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/variables/ctx_manager.py", line 1294, in call_method
"call_method", name, *proxy_args_kwargs([self] + args, kwargs)
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/utils.py", line 1236, in proxy_args_kwargs
proxy_args = tuple(arg.as_proxy() for arg in args)
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/utils.py", line 1236, in
proxy_args = tuple(arg.as_proxy() for arg in args)
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/variables/lazy.py", line 212, in realize_and_forward
return getattr(self.realize(), name)(*args, **kwargs)
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/variables/lazy.py", line 72, in realize
self._cache.realize()
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/variables/lazy.py", line 33, in realize
self.vt = builder.VariableBuilder(tx, self.source)(self.value)
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/variables/builder.py", line 445, in call
vt = self._wrap(value)
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/variables/builder.py", line 1043, in _wrap
torch._dynamo.utils.store_user_object_weakref(value)
File "/home/erxin/torch-ut/v/lib/python3.10/site-packages/torch/_dynamo/utils.py", line 4689, in store_user_object_weakref
user_obj_id_to_weakref[obj_id] = weakref.ref(obj)
torch._dynamo.exc.InternalTorchDynamoError: TypeError: cannot create weak reference to 'torch.Event' object

from user code:
File "/home/erxin/torch-ut/pytorch/test/dynamo/test_ctx_manager.py", line 441, in torch_dynamo_resume_in_fn_at_441
torch.accelerator.current_stream().wait_event(e)

Set TORCHDYNAMO_VERBOSE=1 for the internal stack trace (please do this especially if you're reporting a bug to PyTorch). For even more developer context, set TORCH_LOGS="+dynamo"

To execute this test, run the following from the base repo dir:
python test/dynamo/test_ctx_manager.py CtxManagerTests.test_gpu_event_across_graph_break

This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0

Reproduce with

python -m pytest ./test_ctx_manager.py

Branch info

main branch

Versions

2025-08-27 06:49:51 (27.4 MB/s) - ‘collect_env.py’ saved [30687/30687]

Collecting environment information...
PyTorch version: 2.9.0.dev20250825+xpu
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.4 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: version 4.1.0
Libc version: glibc-2.35

Python version: 3.10.18 | packaged by conda-forge | (main, Jun 4 2025, 14:45:41) [GCC 13.3.0] (64-bit runtime)
Python platform: Linux-5.15.0-73-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
Is XPU available: True
XPU used to build PyTorch: 20250101
Intel GPU driver version:

  • level-zero: 1.0.0-92~u22.04
  • intel-opencl-icd: 25.05.32567.19-1099~22.04
  • libze1: 1.20.2.0-1098~22.04
    Intel GPU models onboard:
  • Intel(R) Data Center GPU Max 1100
  • Intel(R) Data Center GPU Max 1100
  • Intel(R) Data Center GPU Max 1100
  • Intel(R) Data Center GPU Max 1100
  • Intel(R) Data Center GPU Max 1100
  • Intel(R) Data Center GPU Max 1100
  • Intel(R) Data Center GPU Max 1100
    Intel GPU models detected:
  • [0] _XpuDeviceProperties(name='Intel(R) Data Center GPU Max 1100', platform_name='Intel(R) oneAPI Unified Runtime over Level-Zero', type='gpu', device_id=0xBDA, driver_version='1.6.32567+19', total_memory=49152MB, max_compute_units=448, gpu_eu_count=448, gpu_subslice_count=56, max_work_group_size=1024, max_num_sub_groups=64, sub_group_sizes=[16 32], has_fp16=1, has_fp64=1, has_atomic64=1)
  • [1] _XpuDeviceProperties(name='Intel(R) Data Center GPU Max 1100', platform_name='Intel(R) oneAPI Unified Runtime over Level-Zero', type='gpu', device_id=0xBDA, driver_version='1.6.32567+19', total_memory=49152MB, max_compute_units=448, gpu_eu_count=448, gpu_subslice_count=56, max_work_group_size=1024, max_num_sub_groups=64, sub_group_sizes=[16 32], has_fp16=1, has_fp64=1, has_atomic64=1)
  • [2] _XpuDeviceProperties(name='Intel(R) Data Center GPU Max 1100', platform_name='Intel(R) oneAPI Unified Runtime over Level-Zero', type='gpu', device_id=0xBDA, driver_version='1.6.32567+19', total_memory=49152MB, max_compute_units=448, gpu_eu_count=448, gpu_subslice_count=56, max_work_group_size=1024, max_num_sub_groups=64, sub_group_sizes=[16 32], has_fp16=1, has_fp64=1, has_atomic64=1)
  • [3] _XpuDeviceProperties(name='Intel(R) Data Center GPU Max 1100', platform_name='Intel(R) oneAPI Unified Runtime over Level-Zero', type='gpu', device_id=0xBDA, driver_version='1.6.32567+19', total_memory=49152MB, max_compute_units=448, gpu_eu_count=448, gpu_subslice_count=56, max_work_group_size=1024, max_num_sub_groups=64, sub_group_sizes=[16 32], has_fp16=1, has_fp64=1, has_atomic64=1)
  • [4] _XpuDeviceProperties(name='Intel(R) Data Center GPU Max 1100', platform_name='Intel(R) oneAPI Unified Runtime over Level-Zero', type='gpu', device_id=0xBDA, driver_version='1.6.32567+19', total_memory=49152MB, max_compute_units=448, gpu_eu_count=448, gpu_subslice_count=56, max_work_group_size=1024, max_num_sub_groups=64, sub_group_sizes=[16 32], has_fp16=1, has_fp64=1, has_atomic64=1)
  • [5] _XpuDeviceProperties(name='Intel(R) Data Center GPU Max 1100', platform_name='Intel(R) oneAPI Unified Runtime over Level-Zero', type='gpu', device_id=0xBDA, driver_version='1.6.32567+19', total_memory=49152MB, max_compute_units=448, gpu_eu_count=448, gpu_subslice_count=56, max_work_group_size=1024, max_num_sub_groups=64, sub_group_sizes=[16 32], has_fp16=1, has_fp64=1, has_atomic64=1)
  • [6] _XpuDeviceProperties(name='Intel(R) Data Center GPU Max 1100', platform_name='Intel(R) oneAPI Unified Runtime over Level-Zero', type='gpu', device_id=0xBDA, driver_version='1.6.32567+19', total_memory=49152MB, max_compute_units=448, gpu_eu_count=448, gpu_subslice_count=56, max_work_group_size=1024, max_num_sub_groups=64, sub_group_sizes=[16 32], has_fp16=1, has_fp64=1, has_atomic64=1)
    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: 46 bits physical, 57 bits virtual
Byte Order: Little Endian
CPU(s): 192
On-line CPU(s) list: 0-191
Vendor ID: GenuineIntel
Model name: Intel(R) Xeon(R) Platinum 8468V
CPU family: 6
Model: 143
Thread(s) per core: 2
Core(s) per socket: 48
Socket(s): 2
Stepping: 8
Frequency boost: enabled
CPU max MHz: 2401.0000
CPU min MHz: 800.0000
BogoMIPS: 4800.00
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 tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cat_l2 cdp_l3 invpcid_single intel_ppin cdp_l2 ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect avx_vnni avx512_bf16 wbnoinvd dtherm ida arat pln pts avx512vbmi umip pku ospke waitpkg avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid bus_lock_detect cldemote movdiri movdir64b enqcmd fsrm md_clear serialize tsxldtrk pconfig arch_lbr amx_bf16 avx512_fp16 amx_tile amx_int8 flush_l1d arch_capabilities
Virtualization: VT-x
L1d cache: 4.5 MiB (96 instances)
L1i cache: 3 MiB (96 instances)
L2 cache: 192 MiB (96 instances)
L3 cache: 195 MiB (2 instances)
NUMA node(s): 2
NUMA node0 CPU(s): 0-47,96-143
NUMA node1 CPU(s): 48-95,144-191
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Retbleed: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected

Versions of relevant libraries:
[pip3] dpcpp-cpp-rt==2025.1.1
[pip3] impi-rt==2021.15.0
[pip3] intel-cmplr-lib-rt==2025.1.1
[pip3] intel-cmplr-lib-ur==2025.1.1
[pip3] intel-cmplr-lic-rt==2025.1.1
[pip3] intel-opencl-rt==2025.1.1
[pip3] intel-openmp==2025.1.1
[pip3] intel-pti==0.12.3
[pip3] intel-sycl-rt==2025.1.1
[pip3] mkl==2025.1.0
[pip3] numpy==2.2.6
[pip3] oneccl==2021.15.2
[pip3] oneccl-devel==2021.15.2
[pip3] onemkl-sycl-blas==2025.1.0
[pip3] onemkl-sycl-dft==2025.1.0
[pip3] onemkl-sycl-lapack==2025.1.0
[pip3] onemkl-sycl-rng==2025.1.0
[pip3] onemkl-sycl-sparse==2025.1.0
[pip3] optree==0.17.0
[pip3] pytorch-triton-xpu==3.4.0+git0958dc9b
[pip3] tbb==2022.1.0
[pip3] tcmlib==1.3.0
[pip3] torch==2.9.0.dev20250825+xpu
[pip3] umf==0.10.0
[conda] dpcpp-cpp-rt 2025.1.1 pypi_0 pypi
[conda] impi-rt 2021.15.0 pypi_0 pypi
[conda] intel-cmplr-lib-rt 2025.1.1 pypi_0 pypi
[conda] intel-cmplr-lib-ur 2025.1.1 pypi_0 pypi
[conda] intel-cmplr-lic-rt 2025.1.1 pypi_0 pypi
[conda] intel-opencl-rt 2025.1.1 pypi_0 pypi
[conda] intel-openmp 2025.1.1 pypi_0 pypi
[conda] intel-pti 0.12.3 pypi_0 pypi
[conda] intel-sycl-rt 2025.1.1 pypi_0 pypi
[conda] mkl 2025.1.0 pypi_0 pypi
[conda] numpy 2.2.6 pypi_0 pypi
[conda] oneccl 2021.15.2 pypi_0 pypi
[conda] oneccl-devel 2021.15.2 pypi_0 pypi
[conda] onemkl-sycl-blas 2025.1.0 pypi_0 pypi
[conda] onemkl-sycl-dft 2025.1.0 pypi_0 pypi
[conda] onemkl-sycl-lapack 2025.1.0 pypi_0 pypi
[conda] onemkl-sycl-rng 2025.1.0 pypi_0 pypi
[conda] onemkl-sycl-sparse 2025.1.0 pypi_0 pypi
[conda] optree 0.17.0 pypi_0 pypi
[conda] pytorch-triton-xpu 3.4.0+git0958dc9b pypi_0 pypi
[conda] tbb 2022.1.0 pypi_0 pypi
[conda] tcmlib 1.3.0 pypi_0 pypi
[conda] torch 2.9.0.dev20250825+xpu pypi_0 pypi
[conda] umf 0.10.0 pypi_0 pypi

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions