pytorch - ✅(Solved) Fix [dynamo] Raising non-BaseException values causes graph break instead of TypeError [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#176787Fetched 2026-04-08 00:24:26
View on GitHub
Comments
0
Participants
1
Timeline
38
Reactions
0
Participants
Timeline (top)
mentioned ×15subscribed ×15labeled ×4referenced ×2

Error Message

PYTORCH_TEST_WITH_DYNAMO=1 pytest
test/dynamo/cpython/3_13/test_baseexception.py::UsageTests::test_raise_string
test/dynamo/cpython/3_13/test_baseexception.py::UsageTests::test_raise_new_style_non_exception
test/dynamo/cpython/3_13/test_raise.py::TestRemovedFunctionality::test_strings
test/dynamo/cpython/3_13/test_raise.py::TestRemovedFunctionality::test_tuples

Root Cause

Root cause: The fallback path in _raise_exception_variable (symbolic_convert.py) calls unimplemented() for non-BaseException raise operands instead of raising an observed TypeError.

Fix Action

Fix / Workaround

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): 160 On-line CPU(s) list: 0-159 Vendor ID: GenuineIntel Model name: Intel Xeon Processor (SapphireRapids) CPU family: 6 Model: 143 Thread(s) per core: 2 Core(s) per socket: 40 Socket(s): 2 Stepping: 4 BogoMIPS: 4200.00 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves avx_vnni avx512_bf16 wbnoinvd arat vnmi avx512vbmi umip pku ospke waitpkg avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid bus_lock_detect cldemote movdiri movdir64b fsrm md_clear serialize tsxldtrk amx_bf16 avx512_fp16 amx_tile amx_int8 arch_capabilities Virtualization: VT-x Hypervisor vendor: KVM Virtualization type: full L1d cache: 5 MiB (160 instances) L1i cache: 5 MiB (160 instances) L2 cache: 320 MiB (80 instances) L3 cache: 32 MiB (2 instances) NUMA node(s): 2 NUMA node0 CPU(s): 0-79 NUMA node1 CPU(s): 80-159 Vulnerability Gather data sampling: Not affected Vulnerability Indirect target selection: Mitigation; Aligned branch/return thunks Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Unknown: No mitigations Vulnerability Reg file data sampling: Not affected Vulnerability Retbleed: Not affected 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; Enhanced / Automatic IBRS; IBPB conditional; PBRSB-eIBRS SW sequence; BHI SW loop, KVM SW loop Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected

PR fix notes

PR #176790: fix(dynamo): Raise TypeError for invalid raise operands

Description (problem / solution / changelog)

Fixes https://github.com/pytorch/pytorch/issues/176787

Replace unimplemented() graph break with observed TypeError("exceptions must derive from BaseException") in _raise_exception_variable for non-BaseException raise operands, matching CPython 3.13 semantics.

Test plan

PYTORCH_TEST_WITH_DYNAMO=1 pytest \
  test/dynamo/cpython/3_13/test_baseexception.py::UsageTests::test_raise_string \
  test/dynamo/cpython/3_13/test_baseexception.py::UsageTests::test_raise_new_style_non_exception \
  test/dynamo/cpython/3_13/test_raise.py::TestRemovedFunctionality::test_strings \
  test/dynamo/cpython/3_13/test_raise.py::TestRemovedFunctionality::test_tuples

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @Lucaskabela @jataylo

Changed files

  • test/dynamo_expected_failures/CPython313-test_baseexception-UsageTests.test_raise_new_style_non_exception (removed, +0/-0)
  • test/dynamo_expected_failures/CPython313-test_baseexception-UsageTests.test_raise_string (removed, +0/-0)
  • test/dynamo_expected_failures/CPython313-test_raise-TestRemovedFunctionality.test_strings (removed, +0/-0)
  • test/dynamo_expected_failures/CPython313-test_raise-TestRemovedFunctionality.test_tuples (removed, +0/-0)
  • torch/_dynamo/symbolic_convert.py (modified, +9/-5)

Code Example

PYTORCH_TEST_WITH_DYNAMO=1 pytest \
  test/dynamo/cpython/3_13/test_baseexception.py::UsageTests::test_raise_string \
  test/dynamo/cpython/3_13/test_baseexception.py::UsageTests::test_raise_new_style_non_exception \
  test/dynamo/cpython/3_13/test_raise.py::TestRemovedFunctionality::test_strings \
  test/dynamo/cpython/3_13/test_raise.py::TestRemovedFunctionality::test_tuples
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

Dynamo does not match CPython semantics for invalid raise operands. When user code raises a string, tuple, or non-BaseException class/instance, CPython raises TypeError: exceptions must derive from BaseException. Dynamo instead hits an internal unimplemented() graph break path, preventing user except TypeError handlers from executing within the traced graph.

Failing CPython 3.13 conformance tests:

PYTORCH_TEST_WITH_DYNAMO=1 pytest \
  test/dynamo/cpython/3_13/test_baseexception.py::UsageTests::test_raise_string \
  test/dynamo/cpython/3_13/test_baseexception.py::UsageTests::test_raise_new_style_non_exception \
  test/dynamo/cpython/3_13/test_raise.py::TestRemovedFunctionality::test_strings \
  test/dynamo/cpython/3_13/test_raise.py::TestRemovedFunctionality::test_tuples

Root cause: The fallback path in _raise_exception_variable (symbolic_convert.py) calls unimplemented() for non-BaseException raise operands instead of raising an observed TypeError.

Versions

Collecting environment information... PyTorch version: N/A Is debug build: N/A CUDA used to build PyTorch: N/A ROCM used to build PyTorch: N/A

OS: Fedora Linux 41 (Container Image) (x86_64) GCC version: (GCC) 14.3.1 20251022 (Red Hat 14.3.1-4) Clang version: Could not collect CMake version: version 3.30.8 Libc version: glibc-2.40

Python version: 3.13.9 (main, Oct 14 2025, 00:00:00) [GCC 14.3.1 20250808 (Red Hat 14.3.1-3)] (64-bit runtime) Python platform: Linux-5.14.0-615.el9.x86_64-x86_64-with-glibc2.40 Is CUDA available: N/A CUDA runtime version: 12.8.93 CUDA_MODULE_LOADING set to: N/A GPU models and configuration: GPU 0: NVIDIA H200 GPU 1: NVIDIA H200 GPU 2: NVIDIA H200 GPU 3: NVIDIA H200 GPU 4: NVIDIA H200 GPU 5: NVIDIA H200 GPU 6: NVIDIA H200 GPU 7: NVIDIA H200

Nvidia driver version: 580.82.07 cuDNN version: Probably one of the following: /usr/local/cuda-12.8/targets/x86_64-linux/lib/libcudnn.so.9.6.0 /usr/local/cuda-12.8/targets/x86_64-linux/lib/libcudnn_adv.so.9.6.0 /usr/local/cuda-12.8/targets/x86_64-linux/lib/libcudnn_cnn.so.9.6.0 /usr/local/cuda-12.8/targets/x86_64-linux/lib/libcudnn_engines_precompiled.so.9.6.0 /usr/local/cuda-12.8/targets/x86_64-linux/lib/libcudnn_engines_runtime_compiled.so.9.6.0 /usr/local/cuda-12.8/targets/x86_64-linux/lib/libcudnn_graph.so.9.6.0 /usr/local/cuda-12.8/targets/x86_64-linux/lib/libcudnn_heuristic.so.9.6.0 /usr/local/cuda-12.8/targets/x86_64-linux/lib/libcudnn_ops.so.9.6.0 Is XPU available: N/A HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: N/A Caching allocator config: N/A

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): 160 On-line CPU(s) list: 0-159 Vendor ID: GenuineIntel Model name: Intel Xeon Processor (SapphireRapids) CPU family: 6 Model: 143 Thread(s) per core: 2 Core(s) per socket: 40 Socket(s): 2 Stepping: 4 BogoMIPS: 4200.00 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves avx_vnni avx512_bf16 wbnoinvd arat vnmi avx512vbmi umip pku ospke waitpkg avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid bus_lock_detect cldemote movdiri movdir64b fsrm md_clear serialize tsxldtrk amx_bf16 avx512_fp16 amx_tile amx_int8 arch_capabilities Virtualization: VT-x Hypervisor vendor: KVM Virtualization type: full L1d cache: 5 MiB (160 instances) L1i cache: 5 MiB (160 instances) L2 cache: 320 MiB (80 instances) L3 cache: 32 MiB (2 instances) NUMA node(s): 2 NUMA node0 CPU(s): 0-79 NUMA node1 CPU(s): 80-159 Vulnerability Gather data sampling: Not affected Vulnerability Indirect target selection: Mitigation; Aligned branch/return thunks Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Unknown: No mitigations Vulnerability Reg file data sampling: Not affected Vulnerability Retbleed: Not affected 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; Enhanced / Automatic IBRS; IBPB conditional; PBRSB-eIBRS SW sequence; BHI SW loop, KVM SW loop Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected

cc @chauhang @penguinwu @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @amjames @Lucaskabela @jataylo

extent analysis

Problem Summary

Fixing Dynamo's unimplemented() graph break path for invalid raise operands.

Root Cause Analysis

The fallback path in _raise_exception_variable (symbolic_convert.py) calls unimplemented() for non-BaseException raise operands instead of raising an observed TypeError.

Fix Plan

Step 1: Update _raise_exception_variable in symbolic_convert.py

def _raise_exception_variable(self, raise_operand):
    if not isinstance(raise_operand, BaseException):
        raise TypeError("exceptions must derive from BaseException")
    # ... rest of the function remains the same ...

Step 2: Update test cases to cover the new behavior

import pytest

def test_raise_string():
    try:
        raise "Invalid string"
    except TypeError as e:
        assert str(e) == "exceptions must derive from BaseException"

def test_raise_tuple():
    try:
        raise (1, 2)
    except TypeError as e:
        assert str(e) == "exceptions must derive from BaseException"

Verification

  1. Run the updated test cases to ensure they pass.
  2. Verify that the unimplemented() graph break path is no longer hit for invalid raise operands.
  3. Check that user except TypeError handlers execute correctly within the traced graph.

Extra Tips

  • Make sure to update the documentation to reflect the new behavior.
  • Consider adding additional test cases to cover more edge cases.
  • If you're using a CI/CD pipeline, update the pipeline to run the updated test cases.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

pytorch - ✅(Solved) Fix [dynamo] Raising non-BaseException values causes graph break instead of TypeError [1 pull requests, 1 participants]