Skip to content

Fix config.per_layer_config[layer_type] lookup speed - #47539

Merged
hmellor merged 1 commit into
huggingface:mainfrom
hmellor:fix-hetererogeneous-lookups
Jul 27, 2026
Merged

hmellor merged 1 commit into
huggingface:mainfrom
hmellor:fix-hetererogeneous-lookups

Conversation

@hmellor

@hmellor hmellor commented Jul 25, 2026

Copy link
Copy Markdown
Member

CI

This was causing very slow init when trying to use Gemma 4 in vLLM with the new heterogeneous configs.

scenario (µs/lookup) before (L=4 → L=62) after (L=4 → L=62) speedup
str, majority layer type 90 → 1523 5.6 → 7.2 16–210×
str, minority layer type 33 → 350 7.2 → 8.2 5–43×
str, homogeneous config 78 → 1313 1.4 → 1.5 54–893×
str, rope init (both types) 123 → 1870 13.1 → 15.4 9–122×
int index (control, untouched) 5.6 → 5.8 5.6 → 5.7

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes heterogeneous configuration access by making config.per_layer_config[layer_type] significantly faster, addressing slow initialization when using heterogeneous layer_types (e.g., Gemma 4 in vLLM).

Changes:

  • Reworked _PerLayerConfigView.__getitem__ for str keys to avoid constructing per-layer configs just to check homogeneity.
  • Added unit tests covering layer-type indexing behavior (homogeneous, heterogeneous, missing/unknown layer types).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/transformers/integrations/heterogeneity/configuration_utils.py Refactors layer-type lookup to compare per-layer overrides directly and return the resolved config.
tests/heterogeneity/test_configuration_utils.py Adds coverage for indexing per_layer_config by layer_type, including error cases.

Comment thread src/transformers/integrations/heterogeneity/configuration_utils.py
@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.

@github-actions

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 30150366074:1
Result: success | Jobs: 16 | Tests: 174,849 | Failures: 0 | Duration: 15h 55m

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

ty

@hmellor
hmellor added this pull request to the merge queue Jul 27, 2026
Merged via the queue into huggingface:main with commit 142f01f Jul 27, 2026
112 checks passed
@hmellor
hmellor deleted the fix-hetererogeneous-lookups branch July 27, 2026 09:24
stevhliu pushed a commit to stevhliu/transformers that referenced this pull request Jul 30, 2026
…7539)

Fix `config.per_layer_config[layer_type` lookup speeds

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Sainava pushed a commit to Sainava/Sai-transformers that referenced this pull request Aug 3, 2026
…7539)

Fix `config.per_layer_config[layer_type` lookup speeds

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.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.

4 participants