Repository navigation
[graph_trainer] AutoParallel AOT FX Trace Integration - #2725
Conversation
2d2fb54 to
bd097f8
Compare
9f9cc4c to
b0f0cc3
Compare
b0f0cc3 to
cd1af1a
Compare
cd1af1a to
0d30cb5
Compare
0d30cb5 to
e00f2a7
Compare
d78b736 to
032e8d3
Compare
032e8d3 to
ccb2a00
Compare
ccb2a00 to
2b55583
Compare
2b55583 to
9ecc531
Compare
|
|
||
| def _run_autoparallel_llama3_loss_compare() -> bool: | ||
| """Run loss_compare for eager llama3 vs graph_trainer AutoParallel llama3.""" | ||
| return run_loss_compare_close( |
There was a problem hiding this comment.
do we understand why it's not bitwise match?
There was a problem hiding this comment.
Yes. The reasons are similar to what we root-caused for DeepSeek V3. The AutoParallel path can produce a different SPMD graph than the manually parallelized eager path: it may choose different sharding, introduce different collective schedules/reductions, and lower some operators differently before GraphTrainer sees the graph. For DSv3, the strongest concrete arithmetic mismatch is RMSNorm: native GraphTrainer preserves fused RMSNorm while AP decomposes it before Inductor. The AP graph also has a different collective surface because it materializes the solver-selected placement. I added the same caveat to the README and gathered detailed evidence in the DSv3 AP numerics analysis.
| ), | ||
| baseline_ngpus=4, | ||
| test_ngpus=4, | ||
| rtol=5e-4, |
There was a problem hiding this comment.
I can imagine, if autoparallel ended up with a different placement, it would incur different communication, and different reduction, which could change numercis?
Can we produce 2 tlparse for the same model, one with original parallel, one with autoparallel, to understand better?
Also, we should caution in the md file, that autoparallel would change numerics.
There was a problem hiding this comment.
Done. I produced tlparse reports for the same DSv3 config with native GraphTrainer parallelization and with AutoParallel enabled. I also uploaded the full DSv3 AP numerics analysis.
Summary: native GraphTrainer is bitwise exact against eager for this config, while AP differs by -3.8147e-06 in first-step loss. The strongest root cause is RMSNorm: native GraphTrainer preserves fused RMSNorm, while AP decomposes it before Inductor. AP also has a different collective surface because it materializes the solver-selected SPMD placement; rank0 has more all-gather/reduce-scatter nodes and integer token-count all-reduces from local-map MoE dispatch. I updated the README wording to caution that AP may choose different sharding, collective schedules, and operator lowerings, so numerics tests use tight close checks rather than strict bitwise equality.
There was a problem hiding this comment.
DeepSeek V3 GraphTrainer AutoParallel Numerics Report
Artifacts
- Non-AutoParallel Manifold tlparse:
https://manifold.edge.x2p.facebook.net/v0/read/tree/logs/sanketpurandare/30730055-a956-4e1e-9c1a-8a4a4a76d440/custom/index.html?bucketName=tlparse_reports&apiKey=tlparse_reports-key&withPayload=1&timeoutMsec=10000 - AutoParallel Manifold tlparse:
https://manifold.edge.x2p.facebook.net/v0/read/tree/logs/sanketpurandare/d1549434-dea6-4efe-b71a-b9ea7174802e/custom/index.html?bucketName=tlparse_reports&apiKey=tlparse_reports-key&withPayload=1&timeoutMsec=10000
Commands
Both runs used 4 GPUs, NCCL_NVLS_ENABLE=0, one step, and the same DP/EP shape:
--parallelism.data_parallel_shard_degree=4 \
--parallelism.expert_parallel_degree=2 \
--parallelism.disable_loss_parallelThe non-AutoParallel test path added:
--compile.mode aot_fx_traceThe AutoParallel test path added:
--compile.mode aot_fx_trace --compile.enable_autoparallelNumerics Result
Non-AutoParallel GraphTrainer DSv3 vs eager is bitwise exact:
baseline: 8.087531089782715
test: 8.087531089782715
diff: 0.0
AutoParallel GraphTrainer DSv3 vs eager is close, but not bitwise:
baseline: 8.087531089782715
test: 8.08752727508545
diff: -3.814697265625e-06
Primary Root Cause
The first concrete arithmetic mismatch is RMSNorm lowering, before Inductor codegen.
The non-AutoParallel GraphTrainer graph preserves fused RMSNorm:
aten._fused_rms_norm.default: 38
aten._fused_rms_norm_backward.default: 19
aten.pow.Tensor_Scalar: 0
aten.mean.dim: 0
aten.rsqrt.default: 0
The AutoParallel GraphTrainer graph decomposes RMSNorm into primitive arithmetic:
aten._fused_rms_norm.default: 0
aten._fused_rms_norm_backward.default: 0
aten.pow.Tensor_Scalar: 38
aten.mean.dim: 38
aten.rsqrt.default: 38
This comes from AutoParallel graph construction/lowering using
torch._inductor.decomposition.select_decomp_table(). That decomposition table
contains decompositions for aten.rms_norm.default and
aten._fused_rms_norm.default, so the AP graph is already arithmetically
different before GraphTrainer codegen or Inductor can be blamed.
A standalone check confirms the two RMSNorm forms are not bitwise equivalent:
equal False
max_abs 0.015625
num_diff 11
So the current AP graph cannot be bitwise equal to eager TorchTitan DSv3 unless
AutoParallel preserves the fused RMSNorm op or otherwise exactly matches its
arithmetic.
Secondary Graph Differences
Counting only the first unprofiled generated function body in rank0 FX:
non-AP AP
all_gather 25 61
reduce_scatter 13 68
all_reduce 0 10
all_to_all 60 55
aten._softmax 10 0
aten.exp 0 60
The extra collectives are expected from the AP contract being different from
TorchTitan's native DSv3 parallelization:
-
AutoParallel solves a full SPMD placement over the 2D
(efsdp, ep)mesh,
then materializes that placement as local tensor code plus explicit
collectives. Native GraphTrainer follows TorchTitan's existing SimpleFSDP +
EP program and then captures that program. -
AP introduces more parameter/input redistributions than native SimpleFSDP.
In the generated AP graph, additional all-gather chains appear around AP
local tensor boundaries and AP-selected placements. GraphTrainer's FSDP
overlap pass then rewrites/buckets those chains, which is why the AP graph
has substantially more all-gathers and waits. -
AP introduces many more reduce-scatters because AP placement can produce
partial results/gradients over mesh axes that must be reduced back into the
solved local layouts. Native GraphTrainer only has the SimpleFSDP/EP gradient
reduction schedule from the original TorchTitan program. -
The AP
all_reducenodes are integer token-count reductions in the local-map
DSv3 MoE path, not dense matmul reductions. Representative graph lines point
atautoparallel/collectives.py:_all_reduceand the local-map DSv3 token
dispatch path:all_reduce: "i64[8]" = torch.ops._c10d_functional.all_reduce.default(histc, 'sum', '33') File: autoparallel/collectives.py:130 in _all_reduceThese are used to compute global/per-group expert token counts for local-map
dispatch. TorchTitan's native DSv3 token dispatcher does not express that
same token-count exchange as standaloneall_reducenodes in the captured
graph. -
AP also decomposes router softmax. Native GraphTrainer preserves
aten._softmax.default; AP emitsamax/exp/sum/div. In the standalone check
for float32 softmax over the router-sized tensor this was bitwise equal for
random input, so RMSNorm is the stronger concrete explanation for the
observed first-step loss delta. Still, this is another place where AP is not
preserving the same operator surface as TorchTitan eager.
Conclusion
The AP path is not currently a bitwise-preserving
rewrite of TorchTitan DSv3. The root cause is not Inductor. The AP graph differs
before Inductor because AutoParallel uses Inductor decompositions while building
and lowering the AP graph, and RMSNorm is decomposed into primitive arithmetic
that is not bitwise equivalent to TorchTitan/eager's fused RMSNorm.
The remaining collective schedule differences should be evaluated
separately; those affect distributed ordering and may still prevent strict
bitwise equivalence if AP is allowed to choose a different SPMD schedule than
TorchTitan native parallelization.
There was a problem hiding this comment.
Thanks for the investigation.
I think bitwise different can be addressed by forcing empty decomp table when calling aot_export_joint_with_descriptor in AP.
I am not sure if AP solver would prefer a decomposed graph tho?
Having a bitwise identity is just a very nice property, coz it will make it the numerical doubts of an optimization goes away.
There was a problem hiding this comment.
|
|
||
| Uses AutoParallelGraph to apply solver-based SPMD sharding on AutoParallel's | ||
| local_map DSv3 model (whose ops the solver supports), then feeds the pre-built | ||
| JWD into graph_trainer's AOT pipeline. Requires a 2D sparse mesh (EFSDP+EP). |
There was a problem hiding this comment.
I would expect somewhere in the file, this 2D sparse mesh is asserted.
There was a problem hiding this comment.
Addressed. DSv3 now explicitly requires the ("efsdp", "ep") axes, rejects missing axes, and validates that the resulting sparse mesh is exactly 2D with those mesh axis names.
| Uses AutoParallelGraph to apply solver-based SPMD sharding, then feeds | ||
| the pre-built JointWithDescriptors into graph_trainer's AOT compilation |
There was a problem hiding this comment.
no long using JointWithDescriptors, update docstring.
There was a problem hiding this comment.
Addressed. The Llama AutoParallel module docstring no longer mentions JointWithDescriptors; it now describes the placed-module contract and the normal GraphTrainer aot_fx_trace train-step pipeline.
|
|
||
| Uses AutoParallelGraph to apply solver-based SPMD sharding, then feeds | ||
| the pre-built JointWithDescriptors into graph_trainer's AOT compilation | ||
| pipeline (CompiledModule + joint_graph_builder). |
There was a problem hiding this comment.
Addressed. Removed the stale wording about feeding a pre-built JointWithDescriptors into GraphTrainer.
| if parallel_dims.cp_enabled: | ||
| raise ValueError("AutoParallel Llama3 does not support CP yet") | ||
| if parallel_dims.pp_enabled: | ||
| raise ValueError("AutoParallel Llama3 does not support PP yet") |
There was a problem hiding this comment.
nice. I don't remember see similar assertion in dsv3?
There was a problem hiding this comment.
Added the DSv3 checks. It now rejects DDP/CP/PP/TP for this path, requires both EFSDP and EP axes, and validates that the sparse mesh is exactly ("efsdp", "ep").
| **Key features:** | ||
| - **Full train step graph capture** — `make_fx`-based `minimal_fx_tracer` traces forward + loss + backward (and optionally `optimizer.step`) into a single FX graph, without AOTAutograd partitioning, giving full visibility and control over the entire computation. | ||
| - **[SimpleFSDP](https://arxiv.org/abs/2411.00284)** — A compiler-based FSDP that represents sharding as parameterized collectives within the computation graph, making it fully tracer-friendly while achieving memory and throughput improvements over eager FSDP2. | ||
| - **AutoParallel** — Automatic model placement for supported `aot_fx_trace` models, while keeping the normal GraphTrainer graph pass pipeline. |
There was a problem hiding this comment.
Given it doesn't support CP on dense, and only support EFSDP+EP for sparse. Do you mind marking this as experimental?and move it as a latter bullet?
Sry I know this might be an offensive ask, but I need to keep the Key Feature section crisp. This is our user landing page, and I have to gate this.
After all, this is for power user!
There was a problem hiding this comment.
Agreed. I removed AutoParallel from the key-feature list and moved it into a later Experimental AutoParallel Sharding section so the landing page keeps the core GraphTrainer features first. The dedicated section still calls out the supported usage and the numerics caveat.
SherlockNoMad
left a comment
There was a problem hiding this comment.
thanks a lot for merging the experiment, I am really happy that it can fully compose as a parallel module fn!
|
fyi, also need to manually tag ciflow/h100.8 to trigger H100 CI. |
Make AutoParallel a first-class GraphTrainer aot_fx_trace integration. AutoParallel solves SPMD placement and returns an AOT-backed parallel module; GraphTrainer then traces the full train step and applies its normal aot_fx_trace pass and compilation pipeline. Supported paths are Llama3 FSDP+TP and DeepSeek V3 EFSDP+EP. The DeepSeek V3 path temporarily depends on autoparallel._testing.models.dsv3 because AutoParallel requires the local_map-based model definition. The standalone torchtitan.experiments.autoparallel experiment and workflow are removed; AutoParallel coverage now lives in the GraphTrainer workflow and tests. stack-info: PR: #2725, branch: sanketpurandare/stack/4
9ecc531 to
f294ad9
Compare
Stacked PRs:
TorchTitan AutoParallel GraphTrainer PR Summary
High-Level Intent
This PR moves AutoParallel support out of the old standalone
torchtitan.experiments.autoparallelexperiment and into GraphTrainer'saot_fx_tracepath. The new contract is:aot_fx_tracememory policy, selective remat,CPU offload, bucketing, regional/full Inductor, and CUDA graph passes used by
manually parallelized GraphTrainer models.
This is the cleaner design compared with treating AutoParallel as a separate
TorchTitan backend. AutoParallel is responsible for placement, not for owning the
whole compile stack.
Files Removed
The PR deletes the standalone AutoParallel experiment and its stale CI:
.github/workflows/integration_test_8gpu_autoparallel.yamltorchtitan/experiments/autoparallel/**This is appropriate because the active integration is now under
torchtitan/experiments/graph_trainer/. The top-level experiments README alsoremoves the standalone AutoParallel row.
Config and Validation
torchtitan/experiments/graph_trainer/configs.pyadds:GraphTrainerCompileConfig.enable_autoparallel: bool = Falsevalidate_autoparallel_config(...)The validation is narrow and non-intrusive: AutoParallel is only rejected when
enabled with a compile mode other than
aot_fx_trace. This avoids touching themain trainer and keeps AutoParallel-specific validation in GraphTrainer config
code.
AutoParallel Graph Adapter
torchtitan/experiments/graph_trainer/autoparallel_api.pyaddsAutoParallelGraph, a small subclass of AutoParallel with one supported entrypoint:
apply_placement_for_fx_module(...)Important behavior:
aot_compile_joint_with_descriptors(...).local tensors for DTensor params so gradients flow back through the wrapped
module's parameters.
(args, kwargs)when positional-only flattening does not match the traced inputarity.
vocab sharding.
Llama3 Path
torchtitan/experiments/graph_trainer/llama3/parallelize_autoparallel.pyaddsthe Llama AutoParallel route.
Supported shape:
The path:
fsdp_reshard_after_forwardthrough the same helper used by themanual FSDP path.
loss_parallel.apply_compile(...).This is a clean integration point: the model registry only branches on
compile_config.enable_autoparallel, and all substantial logic lives in the newAutoParallel-specific parallelizer.
DeepSeek V3 Path
torchtitan/experiments/graph_trainer/deepseek_v3/parallelize_autoparallel.pyadds the DeepSeek V3 AutoParallel route.
Supported shape:
The path intentionally replaces TorchTitan's DSv3 module with
autoparallel._testing.models.dsv3.DeepSeekV3Model. This is the one remainingknown workaround in the PR. It is documented in the file: AutoParallel's
solver currently needs the local_map-based DSv3 definition and does not support
TorchTitan's token dispatcher op path yet.
The path preserves TorchTitan-facing MoE attributes needed by downstream
GraphTrainer and optimizer hooks after creating the placed AP model.
Pass Interaction
The PR keeps AutoParallel composable with GraphTrainer's normal pass list.
The unit test
test_autoparallel_graph_pass_selection_uses_regular_memory_policyguards that AutoParallel does not remove:
tag_with_memory_policy_passselective_activation_remat_passapply_cpu_offload_passjoint_transformer_block_bucketing_reordering_passThis matches the intended contract: AP placement happens before full train-step
capture, then GraphTrainer owns memory policy and remat.
Integration Tests and CI
The PR adds GraphTrainer AutoParallel integration suites:
graph_trainer_autoparallelgraph_trainer_autoparallel_h100CI changes:
integration suite, and runs the Llama AP numerics test.
suite with
NCCL_NVLS_ENABLE=0, and runs the DSv3 AP numerics test withNCCL_NVLS_ENABLE=0.This placement is sound: Llama stays in regular CI, while DSv3 AP is kept on the
H100 path because the DSv3 numerics/debug model requirements are H100-oriented.
Numerics Tests
test_numerics.pyadds close-numerics tests rather than bitwise tests forAutoParallel:
rtol=5e-4The close comparison is intentional. AutoParallel can choose different sharding,
collective schedules, operator decompositions, and reduction ordering from the
manual eager/GraphTrainer paths. The test still checks tight agreement by
extracting TensorBoard losses from
scripts/loss_compare.pyoutput and comparingall recorded steps.
Documentation
torchtitan/experiments/graph_trainer/README.mdadds anExperimental AutoParallel Shardingsection.Cleanliness Assessment
folders.
composition, FX-module path selection, and numerics.
Intentional caveats:
autoparallel._testing.models.dsv3. This isexplicitly documented and is the only significant temporary workaround.
sharding and collective/reduction schedules.
(
_check_forward_args,_compute_expected_inputs). This is acceptable for theexperiment but should become a supported AutoParallel API before treating the
integration as stable.
Validation
rtol=5e-4andatol=1e-4.rtol=5e-4.