Skip to content

[AutoTP] Enalbe HF colwise_gather_output to support lm_head replace#8146

Open
jinyouzhi wants to merge 9 commits into
deepspeedai:masterfrom
jinyouzhi:lm_head_colwise
Open

[AutoTP] Enalbe HF colwise_gather_output to support lm_head replace#8146
jinyouzhi wants to merge 9 commits into
deepspeedai:masterfrom
jinyouzhi:lm_head_colwise

Conversation

@jinyouzhi

@jinyouzhi jinyouzhi commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Changes

Enable HF colwise_gather_output in tp_plan through AutoTP, allowing vocab parallelism for an untied lm_head.

Known Limitations

  • Only supports an untied lm_head. Tied lm_head falls back to the legacy implementation.
  • Uneven tensor parallelism is not supported in this PR.

@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: 386d2bf3bf

ℹ️ 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/module_inject/auto_tp.py
@jinyouzhi
jinyouzhi force-pushed the lm_head_colwise branch 3 times, most recently from 2ab4f47 to c63d2d4 Compare July 16, 2026 13:56
…iguration(`colwise_gather_output`/`colwise_rep`)

- Introduced `gather_output` option in `TPLayerSpec` for column-parallel layers.
- Added validation to prevent using gathered output with tied embeddings.
- Updated `LinearLayer` to handle gathered output during forward pass.
- Enhanced documentation to reflect new gathered column parallelism capabilities.
- Added tests for gathered column parallelism scenarios and configurations.

Signed-off-by: iLeGend <824040212@qq.com>
…e tp_plan extraction logic

Signed-off-by: iLeGend <824040212@qq.com>
… for fallback behavior

Signed-off-by: iLeGend <824040212@qq.com>
Signed-off-by: iLeGend <824040212@qq.com>
@PKUWZP
PKUWZP self-requested a review July 16, 2026 19:56
"""Create column-parallel layer (AllReduce in backward)."""
if spec.gather_output and self.mp_size is not None and self.mp_size > 1:
output_dim = module.weight.shape[0]
if output_dim % self.mp_size != 0:

@delock delock Jul 17, 2026

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.

Does this condition mean TP on lm_head is only possible when vocab size divisible by number of TP ranks?

@jinyouzhi jinyouzhi Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, let uneven fallback to legacy.

@PKUWZP PKUWZP 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.

Thanks for submitting the PR, a couple of suggestions:

  1. I don't see this PR leverages online softmax and in-place computation, this is the common optimization that saves GPU memory significantly.

  2. We need to run some profiling to measure the GPU footprint.

Happy to work closely together to have a separate PR for this.


# Column-parallel layer with replicated output (e.g., an untied LM head)
TPLayerSpec(
patterns=[".*\\.lm_head$"],

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.

pattern should be changed to *lm_head\.weight$ in order to be matched.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fix

"""Create column-parallel layer (AllReduce in backward)."""
if spec.gather_output and self.mp_size is not None and self.mp_size > 1:
output_dim = module.weight.shape[0]
if output_dim % self.mp_size != 0:

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 you also add a test to test checkpoint are correct in uneven case? i.e. even number vocab size, with 3 ranks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added.

@jinyouzhi

Copy link
Copy Markdown
Contributor Author

Thanks for submitting the PR, a couple of suggestions:

  1. I don't see this PR leverages online softmax and in-place computation, this is the common optimization that saves GPU memory significantly.
  2. We need to run some profiling to measure the GPU footprint.

Happy to work closely together to have a separate PR for this.

Thank you for your suggestions! You‘re absolutely right, this PR is far from the target. I've refined the PR description, and I'll submit a separate PR for those optimizations.

Signed-off-by: iLeGend <824040212@qq.com>
Signed-off-by: iLeGend <824040212@qq.com>
Signed-off-by: iLeGend <824040212@qq.com>
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.

3 participants