Skip to content

Key the tied-embedding TP rule on the model's input embedding attribute - #48779

Closed
Siddhant231xyz wants to merge 3 commits into
huggingface:mainfrom
Siddhant231xyz:tp-tied-embed-layer
Closed

Siddhant231xyz wants to merge 3 commits into
huggingface:mainfrom
Siddhant231xyz:tp-tied-embed-layer

Conversation

@Siddhant231xyz

@Siddhant231xyz Siddhant231xyz commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

CPU CI GPU run-slow

What does this PR do?

PreTrainedConfig.__init__ injects {"embed_tokens": "embedding_rowwise"} into base_model_tp_plan whenever tie_word_embeddings is set. For models whose embedding attribute has another name (GPT-2 style wte, GPT-NeoX embed_in) that entry matches nothing, which blocks adding TP plans to those models (see the TODO above that block in configuration_utils.py).

This moves the rule into ParallelInterface.init_parallel_plans, keyed on the model's _input_embed_layer (default "embed_tokens", so existing models are unchanged). The config stays declarative.

Part of #34789. Follow-up PRs adding TP plans for GPT-Neo and GPT-J depend on this.

Verification

  • tests/tensor_parallel + tests/test_tensor_parallel_mixin.py: 16 passed.
  • test_tp_plan_matches_params for llama and qwen3_moe pass.
  • Tied-embedding Llama on a 2-rank CPU/gloo mesh (DistributedConfig(tp_size=2)) still shards 15/20 params, embedding included, with logits identical to the single-process run.

The only CI failure is OlmoModelTest::test_generate_with_static_cache in tests_generate shard 4, which is unrelated to this change and flaky: it also fails intermittently on unmodified main locally (1 of 3 runs).

AI disclosure

I used an AI coding assistant (Claude Code) to draft this change and the verification script. I have read and understand every changed line, ran the tests listed above locally, and take responsibility for the code.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline and the Pull Request checks?
  • Was this discussed/approved via a Github issue or the forum? Maintainer invited PRs on Add Tensor Parallel support for ALL models #34789 ("just open a PR and link it to this issue").
  • Did you make sure to update the documentation with your changes according to the guidelines? No doc change needed; behaviour for existing models is unchanged.
  • Did you write any new necessary tests? Covered by the existing tensor-parallel test suites listed above.

Who can review?

@ArthurZucker @Cyrilvallez

PreTrainedConfig injected a hard-coded {'embed_tokens': 'embedding_rowwise'} into base_model_tp_plan whenever tie_word_embeddings is set, which produces an invalid plan entry for models whose embedding attribute has another name (GPT-2 style 'wte', GPT-NeoX 'embed_in', ...), as noted in the TODO.

Move the rule into ParallelInterface mixin plan initialization, keyed on the model's _input_embed_layer (default 'embed_tokens'), so the config stays declarative and models with differently named embeddings get vocab-parallel tied embeddings too.

No behaviour change for existing models: tests/tensor_parallel + test_tensor_parallel_mixin pass (16), tp_plan tests for llama/qwen3_moe pass, and a tied-embedding Llama on a 2-rank CPU mesh still shards 15/20 params with identical logits.

Related: huggingface#34789
@Cyrilvallez

Copy link
Copy Markdown
Member

cc @3outeille indeed probably cleaner

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@3outeille

Copy link
Copy Markdown
Member

lgtm

@github-actions

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 35214896308:2
Result: success | Jobs: 16 | Tests: 190,481 | Failures: 0 | Duration: 13h 50m

@ArthurZucker

Copy link
Copy Markdown
Collaborator

Thanks! #49570 just reworked this: the tied-embedding injection was removed from configuration_utils.py and the input-embedding rowwise rule now lives in distributed/mixin.py (around line 96), still keyed on the embed_tokens attribute name. Closing this one for now; feel free to open a fresh PR against main if it's still needed. Thanks!

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.

5 participants