Bucketing traces small collective rewrite helpers with make_fx while reusing the FakeTensorMode from the surrounding graph. When that shared ShapeEnv already has pending fresh unbacked symbols from an outer dynamic-shape trace, make_fx's unbacked binding validation can try to account for symbols that are unrelated to the bucket inputs and outputs.
This shows up when a static bucket trace runs after a graph trace that introduced unbacked activation symbols: the bucket trace itself only sees static parameter or gradient tensors, but compute_unbacked_bindings observes the ShapeEnv's global pending_fresh_unbacked_symbols and errors on ambient symbols it cannot bind.
Snapshot and clear pending/ignorable fresh unbacked symbols around the nested bucketing make_fx trace, then restore the ambient state afterward. This keeps bucketing responsible only for symbols produced by its own trace while preserving the outer ShapeEnv bookkeeping for the caller.
Add a regression that creates an ambient pending unbacked symbol in a FakeTensorMode, traces a static bucketing helper, and verifies the ambient symbol remains pending after the trace.
Test Plan:
python test/distributed/test_inductor_collectives.py -k test_trace_ignores_ambient_pending_unbacked_symbols -v
lintrunner --config=.lintrunner.toml torch/_inductor/fx_passes/bucketing.py test/distributed/test_inductor_collectives.py
stack-info: PR: #183495, branch: sanketpurandare/stack/8
SOCIAL SHARE CARD GENERATOR