Non-strict tracing can pass raw unbacked SymInt values into a nested Dynamo trace. FlexAttention hits this when BlockMask.seq_lengths are derived from an unbacked query/key sequence dimension and then passed through block_mask.as_tuple() to the nested flex_attention_hop wrapper.
VariableBuilder previously only handled raw SymInt inputs when they had a guardable hint. Unhinted raw SymInt inputs graph-broke immediately, even if the nested graph only needed to carry them symbolically. This change keeps that support narrow: outside non-strict tracing, raw unbacked SymInt wrapping still graph-breaks. Inside non-strict tracing, Dynamo asks the active ShapeEnv to transfer the foreign unbacked SymInt as a ShapeEnv-owned input, reuses it for repeated occurrences of the same source expression, and preserves transferred range/source/hint metadata through the existing foreign-ShapeEnv transfer helpers.
The full non-strict FlexAttention repro also exposed a tracing-only issue: same-frame guard validation eagerly evaluates generated guards against fake inputs whose unbacked sizes cannot be concretized. The runtime guards are still produced, but the same-frame sanity check is skipped while inside the non-strict tracing context.
This keeps the important safety property unchanged: if user code branches on a raw unbacked SymInt, Dynamo still raises the normal data-dependent-symbol error instead of specializing on an optimization hint.
Fixes #187272
This PR was authored with assistance from an AI assistant.
Test Plan:
PYTORCH_TEST_WITH_DYNAMO=1 python -m pytest test/test_fake_tensor.py::FakeTensorTest::test_cudnn_sdpa_unbacked_batch_dim -q -spython -m pytest test/dynamo/test_repros.py -q -s -k flex_attention_non_strict_unbacked_sequence_lengthpython -m pytest test/dynamo/test_dynamic_spec.py -q -s -k non_strict_raw_unbacked_symint_input_raises_dde_on_branchingpython -m pytest test/functorch/test_control_flow.py::TestControlFlowTraced::test_cond_unbacked_symint_closure -q -spython -m pytest test/test_dynamic_shapes.py -q -s -k "unbacked_hint_overrides_transferred or mixed_static_backed_unbacked"python -m pytest test/inductor/test_unbacked_symints.py::TestUnbackedSymintsCPU -q -s -k override_optimization_hintlintrunner -astack-info: PR: #187273, branch: sanketpurandare/stack/20
SOCIAL SHARE CARD GENERATOR