pytorch - 💡(How to fix) Fix [dynamo] Builtin class methods (bool.__new__, bool.from_bytes) not constant-folded during tracing [1 comments, 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#178717Fetched 2026-04-08 01:48:29
View on GitHub
Comments
1
Participants
1
Timeline
135
Reactions
0
Participants
Timeline (top)
mentioned ×61subscribed ×61labeled ×6referenced ×4

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

Code Example

PYTORCH_TEST_WITH_DYNAMO=1 python test/dynamo/cpython/3_13/test_bool.py BoolTest.test_bool_new
PYTORCH_TEST_WITH_DYNAMO=1 python test/dynamo/cpython/3_13/test_bool.py BoolTest.test_from_bytes
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

BuiltinVariable.call_method only constant-folds float.fromhex, float.hex, and complex.from_number .It misses int/bool class methods entirely, and is hardcoded to single-argument calls. This causes bool.new(bool, ...) and bool.from_bytes(bytes, byteorder) to fail during tracing.

Failing CPython 3.13 conformance tests:

PYTORCH_TEST_WITH_DYNAMO=1 python test/dynamo/cpython/3_13/test_bool.py BoolTest.test_bool_new
PYTORCH_TEST_WITH_DYNAMO=1 python test/dynamo/cpython/3_13/test_bool.py BoolTest.test_from_bytes

Versions

PyTorch version: 2.12.0a0+git65a288f Is debug build: False CUDA used to build PyTorch: 12.8 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 4.3.0 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: True CUDA runtime version: 12.8.93 CUDA_MODULE_LOADING set to: 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: False HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True 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

Versions of relevant libraries: [pip3] numpy==2.4.3 [pip3] optree==0.19.0 [pip3] torch==2.12.0a0+git3c180b1 [pip3] triton==3.6.0

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

extent analysis

Fix Plan

To fix the issue with BuiltinVariable.call_method not constant-folding int/bool class methods and being hardcoded to single-argument calls, we need to modify the call_method function to handle these cases. Here are the steps:

  • Modify the BuiltinVariable.call_method function to handle int and bool class methods.
  • Add support for multi-argument calls.
  • Update the function to constant-fold bool.__new__(bool, ...) and bool.from_bytes(bytes, byteorder).

Example code:

def call_method(self, method_name, args, kwargs):
    # Handle int and bool class methods
    if method_name in ['__new__', 'from_bytes']:
        if self.type == 'bool':
            # Constant-fold bool.__new__(bool, ...) and bool.from_bytes(bytes, byteorder)
            if method_name == '__new__':
                return bool(args[0])
            elif method_name == 'from_bytes':
                return bool(int.from_bytes(args[0], args[1]))
        elif self.type == 'int':
            # Handle int class methods
            if method_name == '__new__':
                return int(args[0])
            # Add more int class methods as needed

    # Handle multi-argument calls
    if len(args) > 1:
        # Update the function to handle multiple arguments
        if method_name == 'from_bytes':
            return bool(int.from_bytes(args[0], args[1]))

    # Default behavior
    return self.default_call_method(method_name, args, kwargs)

Verification

To verify that the fix worked, run the failing CPython 3.13 conformance tests:

PYTORCH_TEST_WITH_DYNAMO=1 python test/dynamo/cpython/3_13/test_bool.py BoolTest.test_bool_new
PYTORCH_TEST_WITH_DYNAMO=1 python test/dynamo/cpython/3_13/test_bool.py BoolTest.test_from_bytes

If the tests pass, the fix is successful.

Extra Tips

  • Make sure to update the BuiltinVariable.call_method function to handle all relevant int and bool class methods.
  • Test the fix thoroughly to ensure it works correctly for all cases.
  • Consider adding more test cases to cover different scenarios and edge 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