Skip to content

[AutoTP] Enable HF colwise_gather_output to support lm_head replace - #8146

Merged
delock merged 12 commits into
deepspeedai:masterfrom
jinyouzhi:lm_head_colwise
Jul 29, 2026
Merged

[AutoTP] Enable HF colwise_gather_output to support lm_head replace#8146
delock merged 12 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
Comment thread deepspeed/module_inject/auto_tp.py

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

Comment thread deepspeed/module_inject/autotp_config.py Outdated
Comment thread deepspeed/module_inject/auto_tp.py
@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>
@delock

delock commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

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.

Suggest profile GPU foot print with the separate PR. Online softmax and in-place computate could save memory for OPSD teacher TP sharding.

@delock
delock enabled auto-merge July 24, 2026 08:01
@jinyouzhi

Copy link
Copy Markdown
Contributor Author
  1. saves GPU memory significantly.

Great! list the keypoints into an issue to track #8173

@delock
delock requested a review from PKUWZP July 25, 2026 08:04
@jinyouzhi

Copy link
Copy Markdown
Contributor Author

Hi @PKUWZP, Could you have a look?

@jinyouzhi jinyouzhi changed the title [AutoTP] Enalbe HF colwise_gather_output to support lm_head replace [AutoTP] Enable HF colwise_gather_output to support lm_head replace Jul 28, 2026
@delock
delock disabled auto-merge July 28, 2026 08:02
@delock
delock enabled auto-merge July 28, 2026 08:03

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

LGTM.

@delock
delock added this pull request to the merge queue Jul 29, 2026
Merged via the queue into deepspeedai:master with commit 48d54e0 Jul 29, 2026
13 checks passed
banxingmjj pushed a commit to openanolis/DeepSpeed that referenced this pull request Jul 30, 2026
…an (deepspeedai#8187)

## Summary

Attach AutoTP universal checkpoint metadata before returning from a
successfully converted HuggingFace `tp_plan`.

Previously, this path replaced modules and returned without preserving
the metadata required by `ds_to_universal`, unlike custom-config and
heuristic AutoTP paths.

## Testing

Add coverage for:

- `colwise`
- `rowwise`
- replicated row-parallel bias
- `colwise_gather_output` (Due to  deepspeedai#8146 merged)

---------

Signed-off-by: iLeGend <824040212@qq.com>
Co-authored-by: Ma, Guokai <guokai.ma@gmail.com>
pull Bot pushed a commit to fish003/DeepSpeed that referenced this pull request Aug 20, 2026
…eepspeedai#8185)

Follow up deepspeedai#8146.

## Summary
This pull request introduces support for uneven sub-parameter sharding
in DeepSpeed's universal checkpoint conversion, updating the universal
checkpoint format to version 0.4. The changes ensure that partitioned
parameters with sub-parameters of varying sizes are correctly handled
during checkpoint conversion, merging, and restoration. Additionally,
the PR adds validation to prevent conversion of unsupported checkpoint
layouts and improves error handling and metadata validation.

Key updates by theme:

**Universal Checkpoint Format and Metadata:**
- Bumped the universal checkpoint version to 0.4 and introduced the
`SUB_PARAM_SHARD_WIDTHS` field to record per-rank widths for each
sub-parameter, enabling correct handling of uneven sub-parameter
layouts. (`deepspeed/checkpoint/constants.py`,
`deepspeed/checkpoint/ds_to_universal.py`)
[[1]](diffhunk://#diff-7dfbb96f4f4bdab1e2be9ef97bda5a23e25e32d7e218991c268aea8065aec05eL61-R64)
[[2]](diffhunk://#diff-7dfbb96f4f4bdab1e2be9ef97bda5a23e25e32d7e218991c268aea8065aec05eR93-R97)
[[3]](diffhunk://#diff-ef90f4743f09a5fcb81bcf3487a1d0f4b638e1191ca2c08c1d1d1f2b2c6b6f76R35)
[[4]](diffhunk://#diff-ef90f4743f09a5fcb81bcf3487a1d0f4b638e1191ca2c08c1d1d1f2b2c6b6f76R302-R303)
[[5]](diffhunk://#diff-ef90f4743f09a5fcb81bcf3487a1d0f4b638e1191ca2c08c1d1d1f2b2c6b6f76L335-R441)
- Added `AUTOTP_UNSUPPORTED_PARAMETER_PATTERNS` to checkpoint metadata
and implemented validation to prevent conversion if unsupported
parameter patterns are present. (`deepspeed/checkpoint/constants.py`,
`deepspeed/checkpoint/ds_to_universal.py`)
[[1]](diffhunk://#diff-7dfbb96f4f4bdab1e2be9ef97bda5a23e25e32d7e218991c268aea8065aec05eL61-R64)
[[2]](diffhunk://#diff-ef90f4743f09a5fcb81bcf3487a1d0f4b638e1191ca2c08c1d1d1f2b2c6b6f76R47)
[[3]](diffhunk://#diff-ef90f4743f09a5fcb81bcf3487a1d0f4b638e1191ca2c08c1d1d1f2b2c6b6f76R950-R957)
[[4]](diffhunk://#diff-ef90f4743f09a5fcb81bcf3487a1d0f4b638e1191ca2c08c1d1d1f2b2c6b6f76R1134-R1139)

**Parameter Merging and Sharding Logic:**
- Enhanced the merging logic to correctly handle missing fragments for
ranks with no data in uneven parameter sharding, ensuring proper
alignment of slices and placeholder insertion.
(`deepspeed/checkpoint/ds_to_universal.py`)
[[1]](diffhunk://#diff-ef90f4743f09a5fcb81bcf3487a1d0f4b638e1191ca2c08c1d1d1f2b2c6b6f76R239-R248)
[[2]](diffhunk://#diff-ef90f4743f09a5fcb81bcf3487a1d0f4b638e1191ca2c08c1d1d1f2b2c6b6f76R273-R285)
- Refactored the sub-parameter merging code to use the new shard widths
metadata, supporting both legacy (even) and new (uneven) layouts. Added
logic to reconstruct logical shapes with placeholder dimensions.
(`deepspeed/checkpoint/ds_to_universal.py`)
[[1]](diffhunk://#diff-ef90f4743f09a5fcb81bcf3487a1d0f4b638e1191ca2c08c1d1d1f2b2c6b6f76L302-R327)
[[2]](diffhunk://#diff-ef90f4743f09a5fcb81bcf3487a1d0f4b638e1191ca2c08c1d1d1f2b2c6b6f76L335-R441)
[[3]](diffhunk://#diff-ef90f4743f09a5fcb81bcf3487a1d0f4b638e1191ca2c08c1d1d1f2b2c6b6f76R463-R482)

**Validation and Error Handling:**
- Added early validation for unsupported AutoTP conversions to fail fast
before expensive extraction steps.
(`deepspeed/checkpoint/ds_to_universal.py`)
[[1]](diffhunk://#diff-ef90f4743f09a5fcb81bcf3487a1d0f4b638e1191ca2c08c1d1d1f2b2c6b6f76R950-R957)
[[2]](diffhunk://#diff-ef90f4743f09a5fcb81bcf3487a1d0f4b638e1191ca2c08c1d1d1f2b2c6b6f76R1134-R1139)
- Improved shape consistency checks for pipeline-parallel parameters to
ensure all replicas agree on shape.
(`deepspeed/checkpoint/ds_to_universal.py`)

**Restoration Logic:**
- Updated the restoration logic to use the new shard widths metadata,
ensuring correct reconstruction of sub-parameters during model loading.
(`deepspeed/checkpoint/universal_checkpoint.py`)
[[1]](diffhunk://#diff-22d7b9e3b6eac1dc6e989cd8582946321c36f4fc80b527648eeb2d77a8fd3ee2L13-R13)
[[2]](diffhunk://#diff-22d7b9e3b6eac1dc6e989cd8582946321c36f4fc80b527648eeb2d77a8fd3ee2R34-R73)

These changes collectively improve the robustness and flexibility of
DeepSpeed's checkpoint conversion, especially for advanced tensor
parallelism scenarios.

## Testing

* Added coverage for uneven vocabulary, GQA projections, checkpoint
conversion/restore, and PP + TP tied parameters.
* loss curve deepspeedai/DeepSpeedExamples#1008

## Limitations

tp_size > num_kv need to further be optimized

---------

Signed-off-by: iLeGend <824040212@qq.com>
Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Ma,Guokai <guokai.ma@intel.com>
Co-authored-by: Ma, Guokai <guokai.ma@gmail.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