Skip to content

Support per-layer MTP configuration - #48264

Merged
Cyrilvallez merged 7 commits into
huggingface:mainfrom
eladsegal:per-layer-config-mtp
Sep 2, 2026
Merged

Cyrilvallez merged 7 commits into
huggingface:mainfrom
eladsegal:per-layer-config-mtp

Conversation

@eladsegal

@eladsegal eladsegal commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

CPU CI GPU run-slow

What does this PR do?

Adds independent per-layer configuration for MTP layers.

Previously, get_mtp_config() retained the main model's per_layer_config. This could apply the main-model overrides to MTP layers unintentionally.

With this PR, MTP layers discard the main model's per-layer overrides by default and can define their own through mtp_per_layer_config. MTP masks are created from the corresponding layer config, preserving per-layer settings such as sliding_window.

This also fixes MTP attention-mask selection for Inkling. Previously, mask creation looked for layer_type on the generic MtpLayer wrapper, which does not define it, and therefore always fell back to full attention. As a result, Inkling did not use the correct masks for its hybrid and hybrid_sliding MTP layers. Mask creation now selects the pattern from layer_types in the MTP config.

Who can review?

@ArthurZucker
@Cyrilvallez

@Cyrilvallez Cyrilvallez left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM! Thanks a lot! Thankfully MTP is restricted to batch_size == 1, so the conv_mask is never actually used for Inkling!

Comment on lines -447 to +449
mtp_layer_type = getattr(self.layers[layer_idx], "layer_type", None)
mtp_layer_types = getattr(self.config, "layer_types", None)
mtp_layer_type = mtp_layer_types[layer_idx] if mtp_layer_types is not None else None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice catch!

@Cyrilvallez
Cyrilvallez merged commit 57ddd70 into huggingface:main Sep 2, 2026
111 checks passed
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 33517125555:2
Result: success | Jobs: 16 | Tests: 185,109 | Failures: 0 | Duration: 16h 12m

sbucaille pushed a commit to sbucaille/transformers that referenced this pull request Sep 16, 2026
* Support per-layer configuration in MTP masks

* Add tests

* mtp mask creation bug fix

* slighty easier

---------

Co-authored-by: Elad Segal <[email protected]>
Co-authored-by: Cyril Vallez <[email protected]>
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