Skip to content

[AutoTP] Add support for vocab-parallel LM head and related configurations - #8309

Open
jinyouzhi wants to merge 6 commits into
deepspeedai:masterfrom
jinyouzhi:vocab_parallel_ce
Open

[AutoTP] Add support for vocab-parallel LM head and related configurations#8309
jinyouzhi wants to merge 6 commits into
deepspeedai:masterfrom
jinyouzhi:vocab_parallel_ce

Conversation

@jinyouzhi

@jinyouzhi jinyouzhi commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Motivation

Changes

This pull request adds support for vocabulary-parallel language modeling (LM) heads in DeepSpeed's tensor parallelism (TP) system. It introduces a new VocabParallelLinear layer that keeps logits sharded across TP ranks for untied LM heads and installs a compatible distributed loss automatically. The changes ensure correct partitioning, validation, and integration with the rest of the DeepSpeed engine and configuration system.

Key changes include:

Vocabulary-parallel LM head support

  • Introduced a vocab_parallel_lm_head configuration option in TPTrainingConfig and passed it through the relevant APIs to enable this feature. [1] [2] [3] [4] [5]
  • Added logic in auto_tp.py to detect and correctly replace untied LM heads with the new VocabParallelLinear layer, along with validation to ensure the vocab head is not tied to the embedding. [1] [2] [3] [4]

New layer and loss integration

  • Implemented the VocabParallelLinear layer in layers.py, which ensures logits remain sharded and provides partitioning metadata. [1] [2]
  • Updated the DeepSpeed engine to automatically install a distributed causal LM loss compatible with vocab-parallel heads, and to handle model metadata/validation accordingly. [1] [2]

Miscellaneous

  • Made minor logic corrections and refactoring to ensure correct replacement heuristics and fallback configuration. [1] [2]
  • Exposed new loss functions and configuration utilities in the deepspeed.sequence module's public API.

These changes collectively enable efficient, distributed training of models with untied, sharded vocabulary projection heads and ensure compatibility with DeepSpeed's tensor parallelism ecosystem.

Limitations

  • TP x SP mesh are unsupported.

@delock

delock commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Hi @jinyouzhi when this PR is ready for review just ping me, thanks!

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
jinyouzhi and others added 2 commits September 8, 2026 11:11
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
@jinyouzhi
jinyouzhi marked this pull request as ready for review September 8, 2026 11:51
Require an explicit sequence-parallel group when the legacy wrapper gathers losses, and document the distinct backward conventions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>

@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: 8f03c27ea0

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


setattr(model, UNIVERSAL_CHECKPOINT_INFO, collect_autotp_universal_checkpoint_info(model))
setattr(model, "ds_autotp_parsed", True)
finalize_autotp(attach_uc_metadata=True)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Replace the head in the heuristic fallback

When neither a partition config nor a convertible HuggingFace TP plan exists, this branch only invokes replace_transformer_layer for parsed transformer-block classes; its training-mode set_lm_head path returns without touching the root output head. Consequently, finalize_autotp finds no VocabParallelLinear, so the documented autotp_size plus vocab_parallel_lm_head configuration silently leaves the full head replicated and never installs the distributed loss. Explicitly replace the model's output head before finalizing this fallback; an end-to-end training-path test would expose the no-op configuration.

AGENTS.md reference: AGENTS.md:L35-L36

Useful? React with 👍 / 👎.

@jinyouzhi jinyouzhi Sep 8, 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.

Fixed in  a3b440523 . The heuristic AutoTP path now creates a dedicated  AutoTP  instance for the output head and explicitly replaces the single supported  lm_head / embed_out  before finalization. It also fails clearly when no supported head or multiple candidate heads are found, instead of silently leaving the full head replicated. I added a 2-rank end-to-end regression using a real Llama model through  deepspeed.initialize , forward, distributed causal-LM loss, and backward.

Comment on lines +540 to +542
for _, module in self.module.named_modules():
if isinstance(module, nn.Embedding) and getattr(module, "weight", None) is lm_head.weight:
raise ValueError("A no-gather vocab-parallel LM head requires untied embedding and output weights")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Validate tied weights before slicing embeddings

For the usual module order where a tied embedding precedes lm_head, an HF/custom plan can replace the embedding first; _slice_embedding creates a new Parameter, so this later identity scan no longer sees that the original head and embedding were tied. The configuration is then incorrectly accepted and silently breaks weight sharing instead of raising the documented error. Capture and validate candidate ties before traversal mutates either module; integration coverage using an actual tied model and embedding plan is also required.

AGENTS.md reference: AGENTS.md:L35-L36

Useful? React with 👍 / 👎.

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.

Fixed in  a3b440523 .  AutoTP  now records the identities of vocab-head modules tied to embeddings when it is constructed, before traversal can replace an embedding parameter.  _validate_untied_vocab_head()  checks this original tie information as well as the current parameter identity. A regression test covers an  embedding_rowwise  plan followed by a  colwise  tied  lm_head  and verifies that the configuration is rejected before weight sharing can be broken.

Comment thread deepspeed/runtime/tensor_parallel/config.py
jinyouzhi and others added 2 commits September 8, 2026 12:03
Replace the output head in heuristic AutoTP and preserve original tied-weight evidence before embedding traversal mutates parameters.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
Resolve and validate the heuristic output head before transformer partitioning, cache the candidate for replacement, and skip tied-weight scans when the feature is disabled.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
@jinyouzhi

Copy link
Copy Markdown
Contributor Author

Hi @jinyouzhi when this PR is ready for review just ping me, thanks!

Hi, this PR is ready for review now. Thank you for your patience! @delock

During development, I identified and fixed some issues related to SP in a separate PR: #8457.

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