[AutoTP] Fix training lm_head routing - #8302
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 986497b54f
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Thank you for contributing this great PR! @gaoxiaomo Could you check whether the unit test coverage for I also wanted to better understand how the column-parallel and legacy paths are selected, particularly which scenarios still require the legacy path—for example, tied embeddings. CC @delock for visibility. Please feel free to share any thoughts or comments. |
|
TP > 1 legacy training is unusable after PR-A alone (Hunk 1) The training-path
The old path was equally unusable for training ( Suggestion: pass @jinyouzhi could you confirm whether this matches your RFC #8173 roadmap intent for PR-A? |
|
The new routing reads a sticky process-global mode — this breaks the OPD/OPSD same-process rollout case
training_column_lm_head = is_autotp_training_mode() and legacy_lm_head # _replace
... and not is_autotp_training_mode() # _create_row_parallel_layerIn OPD/OPSD the teacher rollout engine and training live in one process (the RFC #8173 motivation scenario): after Suggestion: these two new routing decisions should not read the global. Pass an explicit |
Signed-off-by: gaoxiaomo <165135449+gaoxiaomo@users.noreply.github.com>
Signed-off-by: gaoxiaomo <165135449+gaoxiaomo@users.noreply.github.com>
986497b to
52ca79d
Compare
|
Thanks @jinyouzhi and @delock. I updated the PR to address both review points.
I also added a real TP=2 distributed regression test with an uneven vocabulary size of 269. Before the fix, the two ranks emitted Validation on the rebased branch:
The branch is now rebased on current |
|
Thanks for the quick turnaround — the The row-parallel point isn't closed yet, though. In Two ways to close it — I'd prefer (b) for this PR: (a) Implement the (b) Raise Either way the test needs One related gap: the tied fallback in |
|
Thanks, @delock. I agree with your suggestions. The column-parallel direction matches the RFC #8173 plan. The legacy training path now uses For a generic explicit I also agree that training support for explicit ROW-parallel output heads should be tracked as a separate follow-up item in RFC #8173. For PR-A, training + explicit ROW + |
Assisted-by: AI assistant Signed-off-by: gaoxiaomo <165135449+gaoxiaomo@users.noreply.github.com>
|
Thanks @delock and @jinyouzhi. I implemented option (b) in
Validation:
The row-parallel autograd implementation, including input slicing and the required |
Summary
This implements the independently mergeable PR-A described in #8173.
training_modeto AutoTP and propagate it from the training and inference entry points. Layer-type routing no longer depends on the sticky process-global AutoTP mode.lm_head/embed_outto the column-parallelLinearLayerwithgather_output=True. Every TP rank therefore receives full-vocabulary logits and can continue to use standard cross entropy with autograd.LmHeadLinearAllreducerouting unchanged.Here, the legacy path means AutoTP model injection without a converted HF/custom partition-plan rule for the output head. Vocabulary-parallel cross entropy remains a separate follow-up: it can later switch the gathered training output to sharded logits together with the matching loss implementation.
Why
gather_output=TrueColumn-parallelizing the vocabulary dimension without gathering leaves each rank with only its local vocabulary shard. Standard cross entropy then either rejects labels outside that shard or computes an incorrect denominator over a partial vocabulary. Gathering restores full logits on every rank, while
GatherFromTensorParallelRegionpreserves the backward path to each local weight shard.Tests
pytest -q tests/unit/module_inject/test_tp_partition_config_path.py: 14 passed[4, 269]5.73517322540283201.1175870895385742e-08[4, 135]and[4, 134]268failed withIndexError: Target 268 is out of boundspre-commit run --files ...: all applicable hooks passedgit diff --check: passedThe branch is rebased on current
masterat6e3bd087.Duplicate check
No open PR was found for #8173 PR-A or these two
lm_headrouting cases. #8241 touches the same AutoTP area but addresses per-model metadata isolation and does not change this routing behavior.