Skip to content

[Blip2] Fix cross attention reshape - #46695

Merged
vasqu merged 1 commit into
huggingface:mainfrom
vasqu:fix-blip-cross-attn
Jun 16, 2026
Merged

vasqu merged 1 commit into
huggingface:mainfrom
vasqu:fix-blip-cross-attn

Conversation

@vasqu

@vasqu vasqu commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

As per title. It's a regression caused by #46401 (discovered it during #46039) where the cross attn final shape is not done properly (the root cause is that there oftentimes is some broadcasting going on between q and kv so the final shape is not "static").

Tbh, I'm not sure why this was even mergable with the merge queue as it is already indicated with fast test using granite speech plus.

@github-actions

Copy link
Copy Markdown
Contributor

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

run-slow: blip_2, instructblip, instructblipvideo

@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 Dashboard: View test results in Grafana

Comment on lines +605 to 607
# NOTE: KV has a different bsz than Q so we take the broadcasted shapes instead of the input shape
attn_output = attn_output.reshape(*attn_output.shape[:2], -1).contiguous()
return attn_output, attn_weights

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.

wait, isn't the bsz supposed to be same as queries? I'm not following how it came out a different bsz

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I thought so as well but I debugged and it apparently wasn't - and tbh I didn't want to go any deeper 😬

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

And it seems to happen only on the granite model so very weird

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.

I didn't want to go any deeper

haha I feel it, as long as the slow CI passes for blips, granitevision, graniteaudio - lets merge then (hopefully I am not missing any models with qformer backbone)

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.

smth saying that the dummy tester inputs weren't prepared correctly to begin with, and we were lucky to not notice it 🙃

@vasqu

vasqu commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator Author

run-slow: blip_2, instructblip, instructblipvideo, granite4_vision, granite_speech, granite_speech_plus

@vasqu

vasqu commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator Author

Just sanity checking again then merging 🫡

@github-actions

Copy link
Copy Markdown
Contributor

Workflow Run ⚙️

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

models: ["models/blip_2", "models/granite4_vision", "models/granite_speech", "models/granite_speech_plus", "models/instructblip", "models/instructblipvideo"]
quantizations: []

@github-actions

Copy link
Copy Markdown
Contributor

CI Results

Workflow Run ⚙️

Commit Info

Context Commit Description
RUN bab2f073 workflow commit (merge commit)
PR 6ee8ff21 branch commit (from PR)
main e4189101 base commit (on main)

✅ No failing test specific to this PR 🎉 👏 !

@vasqu
vasqu added this pull request to the merge queue Jun 16, 2026
@vasqu

vasqu commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator Author

Merging, all green and we need it to unblock tomorrow potentially

Merged via the queue into huggingface:main with commit 65c60cd Jun 16, 2026
47 checks passed
@vasqu
vasqu deleted the fix-blip-cross-attn branch June 16, 2026 19:03
stevhliu pushed a commit to stevhliu/transformers that referenced this pull request Jul 30, 2026
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.

3 participants