pytorch - 💡(How to fix) Fix torch.compile + torch.func.grad: superlinear compile time with MaxPool2d → log/clamp → pow → AdaptiveAvgPool2d [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#181428Fetched 2026-04-25 06:02:34
View on GitHub
Comments
0
Participants
1
Timeline
68
Reactions
0
Participants
Timeline (top)
mentioned ×30subscribed ×30labeled ×8

Error Message

The traceback (when a timeout is applied externally) points to sympy.simplify being called inside torch/_inductor/codegen/cpp.py at stride_at, suggesting the composed gradient expression — a product of MaxPool2d argmax gradients, log/clamp conditionals, and AdaptiveAvgPool2d index arithmetic — creates a SymPy expression that is expensive to simplify.

Error logs

Fix Action

Fix / Workaround

compile time: 25.9s I0424 14:50:06.424000 2891746 torch/_dynamo/eval_frame.py:701] TorchDynamo attempted to trace the following frames: [ I0424 14:50:06.424000 2891746 torch/_dynamo/eval_frame.py:701] * wrapper /home/.venv/lib/python3.10/site-packages/torch/_functorch/apis.py:432 I0424 14:50:06.424000 2891746 torch/_dynamo/eval_frame.py:701] ] I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] TorchDynamo compilation metrics: I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] Function, Runtimes (s) I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] _compile.compile_inner, 24.8579 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] compile_attempt_0, 24.8000 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] bytecode_tracing, 0.2581 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] get_fake_value, 0.0308 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] create_proxy, 0.0065 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] wrap_to_fake_tensor_and_record, 0.0022 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] variable_builder_call, 0.0742 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] insert_deferred_runtime_asserts, 0.0028 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] OutputGraph.call_user_compiler, 24.5275 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] _recursive_pre_grad_passes, 0.0058 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.pre_grad_passes.group_batch_fusion_passes, 0.0000 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.pre_grad_passes.efficient_conv_bn_eval_pass, 0.0001 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.pre_grad_passes.apply_gumbel_max_trick_pass, 0.0000 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] inductor_codecache_torch_key, 0.1513 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] create_aot_dispatcher_function, 24.0582 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] aot_collect_metadata, 0.0163 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] compile_fx.<locals>.fw_compiler_base, 23.9580 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] _recursive_joint_graph_passes, 0.4283 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.joint_graph_passes.remove_noop_ops, 0.0002 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.joint_graph_passes.constant_fold_uniform_value, 0.0037 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.joint_graph_passes.pass_pattern_0, 0.0001 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.joint_graph_passes.pass_pattern_1, 0.0000 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] compile_fx_inner, 23.5294 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] fx_codegen_and_compile, 23.5286 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] additional_fake_tensor_prop, 0.0080 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] _recursive_post_grad_passes, 0.0207 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.reorder_for_locality, 0.0001 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.remove_profiler_ops, 0.0000 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.post_grad_custom_pre_pass, 0.0001 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.remove_noop_ops, 0.0001 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.remove_assert_ops, 0.0000 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.pass_pattern_0, 0.0000 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.pass_pattern_1, 0.0009 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.pass_pattern_2, 0.0001 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.stable_sort, 0.0001 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.move_constructors_to_cuda, 0.0001 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.reinplace_inplaceable_ops, 0.0003 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.decompose_triton_kernel_wrapper_functional, 0.0001 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.decompose_auto_functionalized, 0.0001 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.decompose_scan_to_while_loop, 0.0000 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.decompose_map_to_while_loop, 0.0000 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] GraphLowering.run, 0.0647 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] GraphLowering.compile_to_fn, 23.4156 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] GraphLowering.compile_to_module, 23.4155 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] GraphLowering.codegen, 22.1561 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] Scheduler.init, 0.3856 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] Scheduler.fused_nodes, 0.0040 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] Scheduler.codegen, 21.7645 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] compile_file, 7.3502 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] PythonWrapperCodegen.generate, 0.0036 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] PyCodeCache.load_by_key_path, 1.2574 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] async_compile.wait, 1.0114 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] TritonBundler.collect, 0.0001 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] build_guards, 0.0502 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] gc, 0.0008 V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats constrain_symbol_range: CacheInfo(hits=0, misses=0, maxsize=None, currsize=0) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats guard_or_defer_runtime_assert: CacheInfo(hits=0, misses=0, maxsize=256, currsize=0) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats _inner_evaluate_expr: CacheInfo(hits=6, misses=2, maxsize=256, currsize=2) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats _simplify_floor_div: CacheInfo(hits=0, misses=0, maxsize=None, currsize=0) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats _maybe_guard_rel: CacheInfo(hits=0, misses=0, maxsize=256, currsize=0) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats _find: CacheInfo(hits=10, misses=6, maxsize=None, currsize=6) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats has_hint: CacheInfo(hits=0, misses=0, maxsize=256, currsize=0) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats size_hint: CacheInfo(hits=0, misses=0, maxsize=256, currsize=0) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats simplify: CacheInfo(hits=86, misses=22, maxsize=None, currsize=22) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats _update_divisible: CacheInfo(hits=1, misses=1, maxsize=None, currsize=1) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats replace: CacheInfo(hits=1, misses=23, maxsize=None, currsize=23) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats _maybe_evaluate_static: CacheInfo(hits=39, misses=26, maxsize=None, currsize=26) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats get_implications: CacheInfo(hits=75, misses=7, maxsize=None, currsize=7) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats get_axioms: CacheInfo(hits=31, misses=1, maxsize=None, currsize=1) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats _maybe_evaluate_static_worker: CacheInfo(hits=6, misses=8, maxsize=None, currsize=8) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats safe_expand: CacheInfo(hits=6, misses=24, maxsize=256, currsize=24) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats uninteresting_files: CacheInfo(hits=67, misses=1, maxsize=None, currsize=1)

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 9684X 96-Core Processor CPU family: 25 Model: 17 Thread(s) per core: 2 Core(s) per socket: 96 Socket(s): 2 Stepping: 2 BogoMIPS: 5099.98 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 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 user_shstk avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin cppc amd_ibpb_ret 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 la57 rdpid overflow_recov succor smca fsrm flush_l1d debug_swap ibpb_exit_to_user Virtualization: AMD-V L1d cache: 6 MiB (192 instances) L1i cache: 6 MiB (192 instances) L2 cache: 192 MiB (192 instances) L3 cache: 2.3 GiB (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: Mitigation; Safe RET 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; STIBP always-on; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected Vulnerability Vmscape: Mitigation; IBPB before exit to userspace

Code Example

import os, tempfile, time
os.environ.setdefault("TORCHINDUCTOR_CACHE_DIR", tempfile.mkdtemp())

import torch
import torch.nn as nn
import torch.func as F

torch.manual_seed(0)
t = torch.randn([12, 8, 5, 13])

m1 = nn.MaxPool2d(2)
m2 = nn.AdaptiveAvgPool2d((1, 1))

def fn(x):
    x = m1(x)
    x = torch.log(torch.clamp(x, min=1e-6))
    x = torch.pow(x, 2)
    x = m2(x)
    return x.mean()

# eager: fast
_ = F.grad(fn)(t)

# compiled: slow (~15s, superlinear relative to individual operators)
t0 = time.time()
torch.compile(F.grad(fn))(t)
elapsed = time.time() - t0
print(f"compile time: {elapsed:.1f}s")
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

torch.compile(torch.func.grad(fn)) exhibits superlinear compile time when fn contains the chain MaxPool2d → log(clamp) → pow → AdaptiveAvgPool2d. Each operator individually compiles in under 1.1 s; all four together take ~25 s on the same input. The slowdown is not proportional to model complexity. From ablation (all with torch.func.grad + torch.compile, input [12, 8, 5, 13]):

ChainCompile time
MaxPool2d + log(clamp) + pow + AdaptiveAvgPool2d~25 s
Remove any one operator< 1.1 s

The traceback (when a timeout is applied externally) points to sympy.simplify being called inside torch/_inductor/codegen/cpp.py at stride_at, suggesting the composed gradient expression — a product of MaxPool2d argmax gradients, log/clamp conditionals, and AdaptiveAvgPool2d index arithmetic — creates a SymPy expression that is expensive to simplify.

import os, tempfile, time
os.environ.setdefault("TORCHINDUCTOR_CACHE_DIR", tempfile.mkdtemp())

import torch
import torch.nn as nn
import torch.func as F

torch.manual_seed(0)
t = torch.randn([12, 8, 5, 13])

m1 = nn.MaxPool2d(2)
m2 = nn.AdaptiveAvgPool2d((1, 1))

def fn(x):
    x = m1(x)
    x = torch.log(torch.clamp(x, min=1e-6))
    x = torch.pow(x, 2)
    x = m2(x)
    return x.mean()

# eager: fast
_ = F.grad(fn)(t)

# compiled: slow (~15s, superlinear relative to individual operators)
t0 = time.time()
torch.compile(F.grad(fn))(t)
elapsed = time.time() - t0
print(f"compile time: {elapsed:.1f}s")

Error logs

compile time: 25.9s I0424 14:50:06.424000 2891746 torch/_dynamo/eval_frame.py:701] TorchDynamo attempted to trace the following frames: [ I0424 14:50:06.424000 2891746 torch/_dynamo/eval_frame.py:701] * wrapper /home/.venv/lib/python3.10/site-packages/torch/_functorch/apis.py:432 I0424 14:50:06.424000 2891746 torch/_dynamo/eval_frame.py:701] ] I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] TorchDynamo compilation metrics: I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] Function, Runtimes (s) I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] _compile.compile_inner, 24.8579 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] compile_attempt_0, 24.8000 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] bytecode_tracing, 0.2581 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] get_fake_value, 0.0308 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] create_proxy, 0.0065 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] wrap_to_fake_tensor_and_record, 0.0022 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] variable_builder_call, 0.0742 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] insert_deferred_runtime_asserts, 0.0028 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] OutputGraph.call_user_compiler, 24.5275 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] _recursive_pre_grad_passes, 0.0058 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.pre_grad_passes.group_batch_fusion_passes, 0.0000 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.pre_grad_passes.efficient_conv_bn_eval_pass, 0.0001 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.pre_grad_passes.apply_gumbel_max_trick_pass, 0.0000 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] inductor_codecache_torch_key, 0.1513 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] create_aot_dispatcher_function, 24.0582 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] aot_collect_metadata, 0.0163 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] compile_fx.<locals>.fw_compiler_base, 23.9580 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] _recursive_joint_graph_passes, 0.4283 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.joint_graph_passes.remove_noop_ops, 0.0002 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.joint_graph_passes.constant_fold_uniform_value, 0.0037 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.joint_graph_passes.pass_pattern_0, 0.0001 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.joint_graph_passes.pass_pattern_1, 0.0000 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] compile_fx_inner, 23.5294 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] fx_codegen_and_compile, 23.5286 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] additional_fake_tensor_prop, 0.0080 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] _recursive_post_grad_passes, 0.0207 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.reorder_for_locality, 0.0001 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.remove_profiler_ops, 0.0000 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.post_grad_custom_pre_pass, 0.0001 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.remove_noop_ops, 0.0001 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.remove_assert_ops, 0.0000 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.pass_pattern_0, 0.0000 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.pass_pattern_1, 0.0009 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.pass_pattern_2, 0.0001 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.stable_sort, 0.0001 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.move_constructors_to_cuda, 0.0001 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.reinplace_inplaceable_ops, 0.0003 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.decompose_triton_kernel_wrapper_functional, 0.0001 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.decompose_auto_functionalized, 0.0001 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.decompose_scan_to_while_loop, 0.0000 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] pass.post_grad_passes.decompose_map_to_while_loop, 0.0000 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] GraphLowering.run, 0.0647 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] GraphLowering.compile_to_fn, 23.4156 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] GraphLowering.compile_to_module, 23.4155 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] GraphLowering.codegen, 22.1561 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] Scheduler.init, 0.3856 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] Scheduler.fused_nodes, 0.0040 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] Scheduler.codegen, 21.7645 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] compile_file, 7.3502 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] PythonWrapperCodegen.generate, 0.0036 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] PyCodeCache.load_by_key_path, 1.2574 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] async_compile.wait, 1.0114 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] TritonBundler.collect, 0.0001 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] build_guards, 0.0502 I0424 14:50:06.425000 2891746 torch/_dynamo/utils.py:910] gc, 0.0008 V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats constrain_symbol_range: CacheInfo(hits=0, misses=0, maxsize=None, currsize=0) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats guard_or_defer_runtime_assert: CacheInfo(hits=0, misses=0, maxsize=256, currsize=0) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats _inner_evaluate_expr: CacheInfo(hits=6, misses=2, maxsize=256, currsize=2) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats _simplify_floor_div: CacheInfo(hits=0, misses=0, maxsize=None, currsize=0) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats _maybe_guard_rel: CacheInfo(hits=0, misses=0, maxsize=256, currsize=0) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats _find: CacheInfo(hits=10, misses=6, maxsize=None, currsize=6) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats has_hint: CacheInfo(hits=0, misses=0, maxsize=256, currsize=0) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats size_hint: CacheInfo(hits=0, misses=0, maxsize=256, currsize=0) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats simplify: CacheInfo(hits=86, misses=22, maxsize=None, currsize=22) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats _update_divisible: CacheInfo(hits=1, misses=1, maxsize=None, currsize=1) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats replace: CacheInfo(hits=1, misses=23, maxsize=None, currsize=23) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats _maybe_evaluate_static: CacheInfo(hits=39, misses=26, maxsize=None, currsize=26) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats get_implications: CacheInfo(hits=75, misses=7, maxsize=None, currsize=7) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats get_axioms: CacheInfo(hits=31, misses=1, maxsize=None, currsize=1) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats _maybe_evaluate_static_worker: CacheInfo(hits=6, misses=8, maxsize=None, currsize=8) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats safe_expand: CacheInfo(hits=6, misses=24, maxsize=256, currsize=24) V0424 14:50:06.425000 2891746 torch/fx/experimental/symbolic_shapes.py:189] lru_cache_stats uninteresting_files: CacheInfo(hits=67, misses=1, maxsize=None, currsize=1)

Versions

Collecting environment information... PyTorch version: 2.11.0+cu130 Is debug build: False CUDA used to build PyTorch: 13.0 ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.5 LTS (x86_64) GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0 Clang version: 15.0.0 ([email protected]:llvm/llvm-project.git 4ba6a9c9f65bbc8bd06e3652cb20fd4dfc846137) CMake version: version 3.22.1 Libc version: glibc-2.35

Python version: 3.10.12 (main, Mar 3 2026, 11:56:32) [GCC 11.4.0] (64-bit runtime) Python platform: Linux-6.8.0-94-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: 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 9684X 96-Core Processor CPU family: 25 Model: 17 Thread(s) per core: 2 Core(s) per socket: 96 Socket(s): 2 Stepping: 2 BogoMIPS: 5099.98 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 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 user_shstk avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin cppc amd_ibpb_ret 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 la57 rdpid overflow_recov succor smca fsrm flush_l1d debug_swap ibpb_exit_to_user Virtualization: AMD-V L1d cache: 6 MiB (192 instances) L1i cache: 6 MiB (192 instances) L2 cache: 192 MiB (192 instances) L3 cache: 2.3 GiB (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: Mitigation; Safe RET 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; STIBP always-on; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected Vulnerability Vmscape: Mitigation; IBPB before exit to userspace

Versions of relevant libraries: [pip3] numpy==2.2.6 [pip3] nvidia-cublas==13.1.0.3 [pip3] nvidia-cuda-cupti==13.0.85 [pip3] nvidia-cuda-nvrtc==13.0.88 [pip3] nvidia-cuda-runtime==13.0.96 [pip3] nvidia-cudnn-cu13==9.19.0.56 [pip3] nvidia-cufft==12.0.0.61 [pip3] nvidia-curand==10.4.0.35 [pip3] nvidia-cusolver==12.0.4.66 [pip3] nvidia-cusparse==12.6.3.3 [pip3] nvidia-cusparselt-cu13==0.8.0 [pip3] nvidia-nccl-cu13==2.28.9 [pip3] nvidia-nvjitlink==13.0.88 [pip3] nvidia-nvtx==13.0.85 [pip3] torch==2.11.0 [pip3] triton==3.6.0 [conda] Could not collect

cc @chauhang @penguinwu @Chillee @samdow @kshitij12345 @ezyang @bobrenjc93 @aditvenk @laithsakka @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @aakhundov @coconutruben @jataylo @oulgen @jamesjwu @aorenste @anijain2305 @masnesral

extent analysis

TL;DR

The most likely fix is to avoid using torch.compile with the given chain of operators or to simplify the composed gradient expression to reduce the compilation time.

Guidance

  • The issue seems to be related to the expensive simplification of the SymPy expression created by the composed gradient of the given chain of operators.
  • To mitigate this, you can try removing any one of the operators from the chain, as the compilation time is significantly reduced in this case.
  • Another possible approach is to simplify the gradient expression manually before passing it to torch.compile.
  • You can also try updating PyTorch to the latest version, as this issue might be fixed in a newer release.

Example

No code snippet is provided as the issue is more related to the interaction between PyTorch and SymPy, and the given code is already a minimal example.

Notes

The provided information suggests that the issue is specific to the given chain of operators and the version of PyTorch being used. The solution might not be applicable to other versions or operator combinations.

Recommendation

Apply a workaround by simplifying the gradient expression or removing one of the operators from the chain, as the root cause of the issue is not explicitly stated and might require further investigation.

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