Skip to content

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

Open
jinyouzhi wants to merge 5 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 5 commits into
deepspeedai:masterfrom
jinyouzhi:lm_head_colwise

Conversation

@jinyouzhi

Copy link
Copy Markdown
Contributor

Change

Enable HF colwise_gather_output in tp_plan via AutoTP, which support vocab parallel for lm_head.
For now, only available for untied lm head, tied fallback legacy.

Plan

Here is a plan to implement the issue "Extend AutoTP capabilities by integrating Liger Kernel (sharding LM heads and adopting Online Softmax)" in #8104

  1. (This PR) Aim to enable the Vocab Parallel for lm_head (untied part) via AutoTP with HF colwise_gather_output.
  2. Support the shard LM heads with gather_output=False and parallel CE loss feature (integrating Liger kernel).
  3. Unify the untied and tied path for LM heads.

@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?

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

"""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.

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