Skip to content

🚨 [v5] Prune prune_heads#41417

Merged
gante merged 4 commits intohuggingface:mainfrom
gante:rm_prune_heads
Oct 8, 2025
Merged

🚨 [v5] Prune prune_heads#41417
gante merged 4 commits intohuggingface:mainfrom
gante:rm_prune_heads

Conversation

@gante
Copy link
Contributor

@gante gante commented Oct 7, 2025

What does this PR do?

Spiritual successor to #41076 -- removes prune_heads and related code/tests/docs.

prune_heads was a feature that we stopped including in models a while ago. For instance, the test_head_pruning_save_load_from_config_init test passes in 28 model classes, but is skipped in 444.

@HuggingFaceDocBuilderDev

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.

Comment on lines -126 to -130
prune_heads (`dict[int, list[int]]`, *optional*, defaults to `{}`):
Pruned heads of the model. The keys are the selected layer indices and the associated values, the list of
heads to prune in said layer.

For instance `{1: [0, 2], 2: [2, 3]}` will prune heads 0 and 2 on layer 1 and heads 2 and 3 on layer 2.
Copy link
Collaborator

Choose a reason for hiding this comment

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

this won't break the loading if a saved config has this attribute?

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok, we have kwargs so it won't break.

But this makes the things not transparent somehow, i.e. the saved config have it but not used at all during loading.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can load arbitrary serialized kwargs, so it shouldn't :)

Copy link
Collaborator

@ydshieh ydshieh left a comment

Choose a reason for hiding this comment

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

🔥

@github-actions
Copy link
Contributor

github-actions bot commented Oct 8, 2025

[For maintainers] Suggested jobs to run (before merge)

run-slow: albert, align, altclip, audio_spectrogram_transformer, beit, bert, bert_generation, blip, blip_2, bridgetower, bros, camembert, canine, chinese_clip, clap, clvp

Copy link
Member

@Cyrilvallez Cyrilvallez left a comment

Choose a reason for hiding this comment

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

Very very nice! Good riddance! 🧹🤗

@gante gante merged commit 7e47555 into huggingface:main Oct 8, 2025
25 checks passed
@gante gante deleted the rm_prune_heads branch October 8, 2025 09:25
@vasqu vasqu mentioned this pull request Oct 9, 2025
AhnJoonSung pushed a commit to AhnJoonSung/transformers that referenced this pull request Oct 12, 2025
* remove _prune_heads

* remove prune_heads

* finalize the purge

* remove another patterns
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