Repository navigation
[graph_trainer] Support marked symbolic input dims in tracing - #3362
Conversation
07f3629 to
1ee37b9
Compare
60ac042 to
3178797
Compare
d7fa96e to
0fb48ed
Compare
0fb48ed to
b243510
Compare
1734678 to
01f60ba
Compare
01f60ba to
c9c815c
Compare
| } | ||
|
|
||
|
|
||
| def _can_guard_true(expr) -> bool: |
There was a problem hiding this comment.
nit: why not just use guard_or_false?
There was a problem hiding this comment.
Removed the _can_guard_true() wrapper and used guard_or_false directly.
| return fwd_bwd_step | ||
|
|
||
|
|
||
| def _materialize_grad_for_param_layout( |
There was a problem hiding this comment.
Existing coverage is TestMinimalFXTracerDynamicShapes.test_materialize_grad_for_param_layout_restores_param_strides.
There was a problem hiding this comment.
The test checks that a dense grad with a different stride is materialized to the parameter stride and that the helper is a no-op when the grad already satisfies the parameter layout contract.
@SherlockNoMad Added an EP-overlap section to the GraphTrainer README and a shorter developer |
| # D2H scalar reads (token dispatcher split sizes). Each | ||
| # recomputation triggers a CUDA synchronize; saving the tiny | ||
| # CPU scalar avoids re-executing the counts all-to-all chain. | ||
| torch.ops.aten._local_scalar_dense.default, |
There was a problem hiding this comment.
There was a problem hiding this comment.
But anyways, now that Simon has already added routed input shape to be the output size of repeat_interleave and torch.arange I no longer need it so removing it.
There was a problem hiding this comment.
Also FYI, when you use to_list() on a integer tensor these ops are generated or when you create a cpu scalar from gpu scalar
There was a problem hiding this comment.
as of recently, we already assert this chunk divisibility in init time right ? otherwise checks look fine to me
There was a problem hiding this comment.
init time asserts are fine for me they don't get traced
| # D2H scalar reads (token dispatcher split sizes). Each | ||
| # recomputation triggers a CUDA synchronize; saving the tiny | ||
| # CPU scalar avoids re-executing the counts all-to-all chain. | ||
| torch.ops.aten._local_scalar_dense.default, |
tianyu-l
left a comment
There was a problem hiding this comment.
please address remaining comments
| if positions is None: | ||
| # No explicit positions: use the prefix cache and broadcast it over batch. | ||
| rope_cache = rope_cache[0:seqlen] | ||
| assert rope_cache.shape == (seqlen, cache_width) |
There was a problem hiding this comment.
please move to comment, not delete
|
|
||
| # Concrete/provable singleton positions can use the cheaper prefix-shaped | ||
| # view path. If singleton-ness is symbolic, fall through to gather below. | ||
| if guard_or_false(positions.size(0) == 1): |
| # writes, which use one chunk length for each write offset. | ||
| def _chunk_local(t): | ||
| return tuple(c.contiguous() for c in torch.chunk(t, num_chunks, dim=1)) | ||
| return ChunkedCELoss._split_equal_chunks(t, num_chunks) |
There was a problem hiding this comment.
using a static method inside an inline function sounds strange -- can we also inline _split_equal_chunks?
Add the graph_trainer tracing prerequisites needed by later EP chunking work without introducing the chunking passes themselves. minimal_fx_tracer now accepts mark_unbacked and mark_dynamic metadata on plain tensor inputs, preserves Dynamo dynamic-range annotations during fakeification, and keeps wrapper-subclass inputs rejected so DTensor-style layouts do not silently lose their metadata. Make RoPE singleton-position handling symbolic-shape friendly without adding tracer-specific runtime checks, make no-op cleanup passes guard symbolic comparisons, and materialize traced gradients to the parameter layout before assigning param.grad. Move AutoParallel CI checks after the graph_trainer checks in the default and H100 workflows so a stale AutoParallel package cannot hide the graph_trainer signal from this stack. Test Plan:\n- conda run -n pt-dev pytest -q torchtitan/experiments/graph_trainer/tests/test_trace_module.py -k 'fakeify_input_copies_only_shape_annotations or mark_dynamic_min_max_preserves_range or mark_dynamic_batch_and_seq_dims_with_rope or mark_unbacked_positions_batch_dim_with_rope or rope_symbolic_positions_compile_fullgraph or materialize_grad_for_param_layout_restores_param_strides or nested_wrapper_subclass_marked_inner_rejected or mark_dynamic_wrapper_subclass_rejected or dtensor_mark_unbacked_rejected'\n- conda run -n pt-dev python -m pytest -q tests/unit_tests/test_loss.py::TestChunkedCELoss::test_equal_split_chunks_match_torch_chunk_for_supported_shapes tests/unit_tests/test_loss.py::TestChunkedCELoss::test_equal_split_chunks_backward_matches_torch_chunk tests/unit_tests/test_loss.py::TestChunkedCELoss::test_symbolic_seq_len_traces_chunking tests/unit_tests/test_loss.py::TestChunkedCELoss::test_rejects_non_divisible_sequence_length tests/unit_tests/test_loss.py::TestChunkedCELoss::test_single_token_chunks_match_torch_chunk_reference torchtitan/experiments/graph_trainer/tests/test_chunked_loss.py::TestChunkedCELossWithParamGrads::test_bitwise_equal_with_chunked_celoss stack-info: PR: #3362, branch: sanketpurandare/stack/16
Stacked PRs:
[graph_trainer] Support marked symbolic input dims in tracing
Add the graph_trainer tracing prerequisites needed by later EP chunking work without introducing the chunking passes themselves. minimal_fx_tracer now accepts mark_unbacked and mark_dynamic metadata on plain tensor inputs, preserves Dynamo dynamic-range annotations during fakeification, and keeps wrapper-subclass inputs rejected so DTensor-style layouts do not silently lose their metadata.
Make RoPE singleton-position handling symbolic-shape friendly without adding tracer-specific runtime checks, make no-op cleanup passes guard symbolic comparisons, and materialize traced gradients to the parameter layout before assigning param.grad.
Move AutoParallel CI checks after the graph_trainer checks in the default and H100 workflows so a stale AutoParallel package cannot hide the graph_trainer signal from this stack.
Test Plan:\n- conda run -n pt-dev pytest -q torchtitan/experiments/graph_trainer/tests/test_trace_module.py -k 'fakeify_input_copies_only_shape_annotations or mark_dynamic_min_max_preserves_range or mark_dynamic_batch_and_seq_dims_with_rope or mark_unbacked_positions_batch_dim_with_rope or rope_symbolic_positions_compile_fullgraph or materialize_grad_for_param_layout_restores_param_strides or nested_wrapper_subclass_marked_inner_rejected or mark_dynamic_wrapper_subclass_rejected or dtensor_mark_unbacked_rejected'\n- conda run -n pt-dev python -m pytest -q tests/unit_tests/test_loss.py::TestChunkedCELoss::test_equal_split_chunks_match_torch_chunk_for_supported_shapes tests/unit_tests/test_loss.py::TestChunkedCELoss::test_equal_split_chunks_backward_matches_torch_chunk tests/unit_tests/test_loss.py::TestChunkedCELoss::test_symbolic_seq_len_traces_chunking tests/unit_tests/test_loss.py::TestChunkedCELoss::test_rejects_non_divisible_sequence_length tests/unit_tests/test_loss.py::TestChunkedCELoss::test_single_token_chunks_match_torch_chunk_reference torchtitan/experiments/graph_trainer/tests/test_chunked_loss.py::TestChunkedCELossWithParamGrads::test_bitwise_equal_with_chunked_celoss