Skip to content

(1/2) Implementing Compiler Pass for AutoTP - #8204

Open
therealnaveenkamal wants to merge 6 commits into
deepspeedai:masterfrom
therealnaveenkamal:feature/autotp
Open

(1/2) Implementing Compiler Pass for AutoTP#8204
therealnaveenkamal wants to merge 6 commits into
deepspeedai:masterfrom
therealnaveenkamal:feature/autotp

Conversation

@therealnaveenkamal

Copy link
Copy Markdown
Contributor

Working on #8104

  • Added support for AutoTP. Added two primitives: copy_to_tp and reduce_from_tp - the f and g nodes.
  • Identifies column/row-parallel matmuls by the injected layer type in nn_module_stack, reading back.
  • Wrote a test to verify correctness of module injection and compiler pass.

cc @tohtana

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a3a2bb41dd

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread deepspeed/compile/passes/tp_compile.py Outdated
Comment thread deepspeed/compile/passes/tp_compile.py Outdated

@tohtana tohtana left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @therealnaveenkamal, this is amazing!
I don't see any critical issue in the code. The approach that reuses existing AutoTP's patterns is great. It gives consistent results with non-DeepCompile AutoTP.

One remaining work is validating the correctness in a more realistic setting. I think it would be good to compare loss values from existing AutoTP and this one. I did similar work for AutoEP. The harness for the verification might be useful if you don't have such a script. We should check different configs like DP1/TP4 and DP2/TP2.

I left a few comments about details. Please consider addressing them. Also, please fix the commit to pass DCO check.

Comment thread deepspeed/compile/custom_ops/tp_collectives.py Outdated
Comment thread tests/unit/compile/test_tp_compile.py Outdated
@tohtana

tohtana commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Can you also share your plan for the the next step as this PR has 1/2 in the title.
I think it would be good to start with the combination with ZeRO. Probably we could do further optimizations based on profiling.

Signed-off-by: Naveenraj Kamalakannan <therealnaveenkamal@gmail.com>
Signed-off-by: Naveenraj Kamalakannan <therealnaveenkamal@gmail.com>
Signed-off-by: Naveenraj Kamalakannan <therealnaveenkamal@gmail.com>
Signed-off-by: Naveenraj Kamalakannan <therealnaveenkamal@gmail.com>
Signed-off-by: Naveenraj Kamalakannan <therealnaveenkamal@gmail.com>
therealnaveenkamal added a commit to therealnaveenkamal/DeepSpeedExamples that referenced this pull request Aug 9, 2026
Results of comparing AutoTP module injection against the DeepCompile
autotp pass (deepspeedai/DeepSpeed#8204) on dense Qwen3.5 (618M, hybrid
GatedDeltaNet/attention, 4xA100): 1.31x speedup at DP2/TP2 and 1.45x at
DP1/TP4 with loss agreement at the bf16 noise floor. Includes the writeup,
plots, per-run metrics, and pinned environment.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Naveenraj Kamalakannan <therealnaveenkamal@gmail.com>
therealnaveenkamal added a commit to therealnaveenkamal/DeepSpeedExamples that referenced this pull request Aug 9, 2026
Results of comparing AutoTP module injection against the DeepCompile
autotp pass (deepspeedai/DeepSpeed#8204) on dense Qwen3.5 (618M, hybrid
GatedDeltaNet/attention, 4xA100): 1.31x speedup at DP2/TP2 and 1.45x at
DP1/TP4 with loss agreement at the bf16 noise floor. Includes the writeup,
plots, per-run metrics, and pinned environment.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Naveenraj Kamalakannan <therealnaveenkamal@gmail.com>

@tohtana tohtana left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @therealnaveenkamal,
Thank you for the update! I think the earlier issues have been addressed.
I also found some correctness issues in the current code. Can you check them?

Any tensor-parallel layer the pass cannot rewrite is rejected rather than left on the
module-level path.
"""
for name, module in model.named_modules():

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we set the flag defer_collectives_to_compiler only all modules passed the check?
If this raises an error in the loop, only some modules have defer_collectives_to_compiler=True. But the outer code might catch the error and fallback to eager. In that case, some communication collectives will be skipped.


assert specs is not None
by_type = {spec.partition_type for spec in specs}
assert PartitionType.ROW in by_type, "the supported entry should still be applied"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this expectation (and the code) is wrong. To make TP work, COLUMN and ROW should be paired. Partially skipping the conversion breaks it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue with Llama4 MoE router should be addressed in another PR. How about making it fail when any unsupported style is found.

# already records the partitioning decision the pass needs.

COLUMN_PARALLEL_LAYERS = (LinearLayer, SubParamLinearLayer)
ROW_PARALLEL_LAYERS = (LinearAllreduce, SubParamLinearAllreduce)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SubParamLinearAllreduce.forward() always executes its module-level row all-reduce, while the compiler pass classifies that layer as row parallel and inserts another graph all-reduce.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants