Skip to content

dnn: fuse attention when a Q/K/V projection has no bias - #6

Draft
sanjayk9 wants to merge 2 commits into
5.xfrom
dnn-attention-fusion-missing-bias
Draft

sanjayk9 wants to merge 2 commits into
5.xfrom
dnn-attention-fusion-missing-bias

Conversation

@sanjayk9

Copy link
Copy Markdown
Owner

The fused Attention layer needs the full QKV bias. Fill a missing projection bias with zeros in all three attention fusion paths, and leave the block unfused if a bias has the wrong length. The CLIP path dropped all three biases when one was missing, and the generic path read K/V bias blobs that may not exist. Fixes the trOCR encoder.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

The fused Attention layer needs the full QKV bias. Fill a missing
projection bias with zeros in all three attention fusion paths, and leave
the block unfused if a bias has the wrong length. The CLIP path dropped
all three biases when one was missing, and the generic path read K/V
bias blobs that may not exist. All three paths now emit a 1-D bias.
Fixes the trOCR encoder.
@sanjayk9
sanjayk9 force-pushed the dnn-attention-fusion-missing-bias branch from 1020377 to e61c641 Compare October 13, 2026 19:32
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.

1 participant