pytorch - ✅(Solved) Fix [Bug] FakeMode in `fullgraph=True` fails [1 pull requests, 3 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#178887Fetched 2026-04-08 01:57:08
View on GitHub
Comments
3
Participants
1
Timeline
79
Reactions
0
Participants
Assignees
Timeline (top)
mentioned ×34subscribed ×34labeled ×6commented ×3

Error Message

── Bug: FakeTensorMode() in fullgraph=True compiled code ─────────────

class Model(nn.Module): def forward(self, x): # Simulates DTensor sharding propagation creating FakeTensorMode # during compiled dispatch (see _sharding_prop.py:468) _mode = FakeTensorMode() return x + 1

model = Model() model.compile(backend="eager", fullgraph=True)

x = torch.randn(4) try: out = model(x) print(f"Unexpected success: {out}") except torch._dynamo.exc.Unsupported as e: print(f"Error: {type(e).name}") print(f" {e}")

Fix Action

Fix / Workaround

class Model(nn.Module): def forward(self, x): # Simulates DTensor sharding propagation creating FakeTensorMode # during compiled dispatch (see _sharding_prop.py:468) _mode = FakeTensorMode() return x + 1

PR fix notes

PR #178908: [Bugfix] Enable fakemode trace through in pre/post forward hooks

Description (problem / solution / changelog)

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

Summary

Registers FakeTensorMode as a recognized Dynamo context manager and handles its construction as a NullContextVariable (no-op) during tracing, preventing a fullgraph=True graph break caused by FakeTensorMode.init being in MOD_SKIPLIST.

Three tests cover construction, context-manager usage, and graph-break resume.

Test plan

python test/dynamo/test_modes.py TorchDispatchModeTests.test_fake_tensor_mode_fullgraph TorchDispatchModeTests.test_fake_tensor_mode_graph_break_resume -v
test_fake_tensor_mode_fullgraph (__main__.TorchDispatchModeTests) ... ok
test_fake_tensor_mode_graph_break_resume (__main__.TorchDispatchModeTests) ... ok

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

Changed files

  • test/dynamo/test_modes.py (modified, +41/-0)
  • torch/_dynamo/variables/torch.py (modified, +7/-0)

Code Example

# ── Bug: FakeTensorMode() in fullgraph=True compiled code ─────────────

class Model(nn.Module):
    def forward(self, x):
        # Simulates DTensor sharding propagation creating FakeTensorMode
        # during compiled dispatch (see _sharding_prop.py:468)
        _mode = FakeTensorMode()
        return x + 1


model = Model()
model.compile(backend="eager", fullgraph=True)

x = torch.randn(4)
try:
    out = model(x)
    print(f"Unexpected success: {out}")
except torch._dynamo.exc.Unsupported as e:
    print(f"Error: {type(e).__name__}")
    print(f"  {e}")
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

We try to run module.compile() in torchtitan and discovered that due to SequenceParallel integration in MOE, there is a FakeMode initialized in pre hooks. This causes failure in graph compilation under fullgraph=True since the FakeMode init has traceback inside of it, which is an untraceable generator

# ── Bug: FakeTensorMode() in fullgraph=True compiled code ─────────────

class Model(nn.Module):
    def forward(self, x):
        # Simulates DTensor sharding propagation creating FakeTensorMode
        # during compiled dispatch (see _sharding_prop.py:468)
        _mode = FakeTensorMode()
        return x + 1


model = Model()
model.compile(backend="eager", fullgraph=True)

x = torch.randn(4)
try:
    out = model(x)
    print(f"Unexpected success: {out}")
except torch._dynamo.exc.Unsupported as e:
    print(f"Error: {type(e).__name__}")
    print(f"  {e}")

Versions

Collecting environment information... PyTorch version: 2.12.0a0+gite7bcaf2 Is debug build: False CUDA used to build PyTorch: 12.9 ROCM used to build PyTorch: N/A

OS: CentOS Stream 9 (x86_64) GCC version: (GCC) 11.5.0 20240719 (Red Hat 11.5.0-14) Clang version: 21.1.7 (CentOS 21.1.7-1.el9) CMake version: version 4.3.0 Libc version: glibc-2.34

Python version: 3.10.20 (main, Mar 11 2026, 17:46:40) [GCC 14.3.0] (64-bit runtime) Python platform: Linux-6.13.2-0_fbk12_0_g0b66b3635210-x86_64-with-glibc2.34 Is CUDA available: True CUDA runtime version: 12.9.86 CUDA_MODULE_LOADING set to: GPU models and configuration: GPU 0: NVIDIA H100 GPU 1: NVIDIA H100 GPU 2: NVIDIA H100 GPU 3: NVIDIA H100 GPU 4: NVIDIA H100 GPU 5: NVIDIA H100 GPU 6: NVIDIA H100 GPU 7: NVIDIA H100

Nvidia driver version: 580.82.07 cuDNN version: Could not collect 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: 52 bits physical, 57 bits virtual Byte Order: Little Endian CPU(s): 384 On-line CPU(s) list: 0-383 Vendor ID: AuthenticAMD Model name: AMD EPYC 9654 96-Core Processor CPU family: 25 Model: 17 Thread(s) per core: 2 Core(s) per socket: 96 Socket(s): 2 Stepping: 1 Frequency boost: enabled CPU(s) scaling MHz: 100% CPU max MHz: 2400.0000 CPU min MHz: 1500.0000 BogoMIPS: 4792.43 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good amd_lbr_v2 nopl xtopology nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba perfmon_v2 ibrs ibpb stibp ibrs_enhanced vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif x2avic v_spec_ctrl vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid overflow_recov succor smca fsrm flush_l1d debug_swap Virtualization: AMD-V L1d cache: 6 MiB (192 instances) L1i cache: 6 MiB (192 instances) L2 cache: 192 MiB (192 instances) L3 cache: 768 MiB (24 instances) NUMA node(s): 2 NUMA node0 CPU(s): 0-95,192-287 NUMA node1 CPU(s): 96-191,288-383 Vulnerability Gather data sampling: Not affected Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Not affected Vulnerability Reg file data sampling: Not affected Vulnerability Retbleed: Not affected Vulnerability Spec rstack overflow: Vulnerable Vulnerability Spec store bypass: Vulnerable Vulnerability Spectre v1: Vulnerable: __user pointer sanitization and usercopy barriers only; no swapgs barriers Vulnerability Spectre v2: Vulnerable; IBPB: disabled; STIBP: disabled; PBRSB-eIBRS: Not affected; BHI: Not affected Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected

Versions of relevant libraries: [pip3] intel-cmplr-lib-ur==2025.3.3 [pip3] intel-openmp==2025.3.3 [pip3] mkl-include==2025.3.1 [pip3] mkl-static==2025.3.1 [pip3] mypy_extensions==1.1.0 [pip3] numpy==2.2.6 [pip3] nvidia-cudnn-frontend==1.18.0 [pip3] onemkl-license==2025.3.1 [pip3] optree==0.19.0 [pip3] tbb==2022.3.1 [pip3] tbb-devel==2022.3.1 [pip3] tcmlib==1.4.1 [pip3] torch==2.12.0a0+gite7bcaf2 [pip3] torch_c_dlpack_ext==0.1.5 [pip3] torchao==0.17.0 [pip3] torchdata==0.11.0 [pip3] torchmonarch==0.3.0 [pip3] torchstore==0.0.0.dev0 [pip3] torchtitan==0.2.2 [pip3] torchx-nightly==2026.3.26 [pip3] triton==3.6.0+git7e48d5df [pip3] umf==1.0.3 [conda] intel-cmplr-lib-ur 2025.3.3 pypi_0 pypi [conda] intel-openmp 2025.3.3 pypi_0 pypi [conda] mkl-include 2025.3.1 pypi_0 pypi [conda] mkl-static 2025.3.1 pypi_0 pypi [conda] numpy 2.2.6 pypi_0 pypi [conda] nvidia-cudnn-frontend 1.18.0 pypi_0 pypi [conda] onemkl-license 2025.3.1 pypi_0 pypi [conda] optree 0.19.0 pypi_0 pypi [conda] tbb 2022.3.1 pypi_0 pypi [conda] tbb-devel 2022.3.1 pypi_0 pypi [conda] tcmlib 1.4.1 pypi_0 pypi [conda] torch 2.12.0a0+gite7bcaf2 pypi_0 pypi [conda] torch-c-dlpack-ext 0.1.5 pypi_0 pypi [conda] torchao 0.17.0 pypi_0 pypi [conda] torchdata 0.11.0 pypi_0 pypi [conda] torchmonarch 0.3.0 pypi_0 pypi [conda] torchstore 0.0.0.dev0 pypi_0 pypi [conda] torchtitan 0.2.2 pypi_0 pypi [conda] torchx-nightly 2026.3.26 pypi_0 pypi [conda] triton 3.6.0+git7e48d5df pypi_0 pypi [conda] umf 1.0.3 pypi_0 pypi

cc @chauhang @penguinwu @eellison @aorenste @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @amjames @jataylo @bdhirsh @bobrenjc93

extent analysis

TL;DR

The issue can be mitigated by modifying the FakeTensorMode initialization to avoid untraceable generators or by disabling fullgraph=True in the model.compile method.

Guidance

  • Identify the source of the FakeTensorMode initialization in the code and modify it to avoid using untraceable generators.
  • Consider disabling fullgraph=True in the model.compile method to bypass the graph compilation issue.
  • Review the PyTorch and torchtitan documentation to ensure that the module.compile method is being used correctly with the fullgraph=True parameter.
  • Verify that the issue is specific to the fullgraph=True mode by testing the model compilation with fullgraph=False.

Example

# Modified code to avoid FakeTensorMode initialization
class Model(nn.Module):
    def forward(self, x):
        # Avoid initializing FakeTensorMode
        return x + 1

model = Model()
model.compile(backend="eager", fullgraph=False)  # Disable fullgraph=True

Notes

The provided code snippet and environment information suggest that the issue is related to the FakeTensorMode initialization in the fullgraph=True mode. However, without further information about the FakeTensorMode class and its usage, it is difficult to provide a more specific solution.

Recommendation

Apply a workaround by disabling fullgraph=True in the model.compile method, as this may allow the model to compile successfully while avoiding the FakeTensorMode initialization issue.

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 [Bug] FakeMode in `fullgraph=True` fails [1 pull requests, 3 comments, 1 participants]