Skip to content

[PEFT] Fix prefix tuning#41696

Merged
vasqu merged 4 commits intohuggingface:mainfrom
vasqu:fix-prefix-tuning
Nov 13, 2025
Merged

[PEFT] Fix prefix tuning#41696
vasqu merged 4 commits intohuggingface:mainfrom
vasqu:fix-prefix-tuning

Conversation

@vasqu
Copy link
Copy Markdown
Contributor

@vasqu vasqu commented Oct 17, 2025

Prefix tuning is a bit more of a special case where we have different q and kv lengths despite having the encoder attention. We now rely on the mask for kv length now (if provided). The assumption was holding before because causal masks always have q == kv length. Fixes #38301 (comment)

cc @BenjaminBossan

@vasqu
Copy link
Copy Markdown
Contributor Author

vasqu commented Oct 17, 2025

run-slow: bert,bart

@github-actions
Copy link
Copy Markdown
Contributor

This comment contains run-slow, running the specified jobs:

models: ['models/bart', 'models/bert']
quantizations: [] ...

@vasqu
Copy link
Copy Markdown
Contributor Author

vasqu commented Oct 17, 2025

run-slow: bert,bart

@vasqu vasqu requested a review from Cyrilvallez October 17, 2025 15:32
@github-actions
Copy link
Copy Markdown
Contributor

This comment contains run-slow, running the specified jobs:

models: ['models/bart', 'models/bert']
quantizations: [] ...

Copy link
Copy Markdown
Member

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

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

Thanks a lot for taking quick care of this regression.

I also tested this PR with the original PEFT unit tests that were failing and they pass now!

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

@vasqu vasqu requested a review from ArthurZucker October 20, 2025 14:18
@BenjaminBossan
Copy link
Copy Markdown
Member

Ping @ArthurZucker could we please get this in before the next release?

Comment thread src/transformers/masking_utils.py
Cyrilvallez
Cyrilvallez previously approved these changes Nov 11, 2025
Copy link
Copy Markdown
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.

All right, let's go for it even if it's quite a weird pattern, as both should always be the same in general 🥲

@Cyrilvallez Cyrilvallez dismissed their stale review November 11, 2025 17:29

Removed after more offline discussion

BenjaminBossan added a commit to BenjaminBossan/peft that referenced this pull request Nov 12, 2025
In transformers, the bidirecional mask creation (as e.g. used by Bert)
does not take into account possible virtual tokens inserted by prefix
tuning. This results in an attention mask of the wrong shape.

This PR monkey patches the _preprocess_mask_arguments function from
transformers to take the virtual tokens into account. This is far from
ideal but there are currently no plans to fix this on the transformers
side (see huggingface/transformers#41696).
Copy link
Copy Markdown
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.

Alright, after all the discussions it's a bit too hard to fix in peft directly, so let's go for it!

@vasqu vasqu merged commit 6408d3b into huggingface:main Nov 13, 2025
23 checks passed
@vasqu vasqu deleted the fix-prefix-tuning branch November 13, 2025 10:59
SangbumChoi pushed a commit to SangbumChoi/transformers that referenced this pull request Jan 23, 2026
* fix

* simplify

* add my 2 cents
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