Skip to content

[opt] Fix in attention after transformers upgrade#2276

Merged
regisss merged 1 commit intohuggingface:mainfrom
ugolowic:opt-attn-fix
Sep 22, 2025
Merged

[opt] Fix in attention after transformers upgrade#2276
regisss merged 1 commit intohuggingface:mainfrom
ugolowic:opt-attn-fix

Conversation

@ugolowic
Copy link
Collaborator

@ugolowic ugolowic commented Sep 22, 2025

This commit fixes two issues that appeared in opt attention after transformers upgrade.

  • incorrect shape of attn_weights caused mismatch in subsequent torch.bmm operation
  • applying scaling to attn_weights significantly worsened accuracy

This change should also be applied to v1.20-release

Example:

PT_HPU_LAZY_MODE=1  python3  run_generation.py --batch_size 1 --bf16 --model_name_or_path facebook/opt-125m --use_hpu_graphs --n_iterations 1 --use_kv_cache --max_new_tokens 100

This commit fixes two issues that appeared in opt attention after transformers upgrade.
* incorrect shape of attn_weights caused mismatch in subsequent torch.bmm operation
* applying scaling to attn_weights significantly worsened accuracy

Signed-off-by: Urszula <urszula.golowicz@intel.com>
@ugolowic ugolowic requested a review from regisss September 22, 2025 08:00
@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.

@astachowiczhabana
Copy link
Collaborator

"Next Synapse Release Validation" is failing on one test with unrelated reason. It looks clean.

@astachowiczhabana
Copy link
Collaborator

LGTM, @regisss can we merge this?

Copy link
Collaborator

@regisss regisss left a comment

Choose a reason for hiding this comment

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

LGTM

@regisss regisss merged commit 4ac187f into huggingface:main Sep 22, 2025
3 of 5 checks passed
astachowiczhabana pushed a commit that referenced this pull request Sep 23, 2025
Signed-off-by: Urszula <urszula.golowicz@intel.com>
astachowiczhabana added a commit that referenced this pull request Sep 23, 2025
gplutop7 pushed a commit to HabanaAI/optimum-habana-fork that referenced this pull request Oct 15, 2025
…uggingface#714)

Signed-off-by: Urszula <urszula.golowicz@intel.com>
Co-authored-by: Urszula Golowicz <urszula.golowicz@intel.com>
gplutop7 pushed a commit to HabanaAI/optimum-habana-fork that referenced this pull request Nov 6, 2025
…uggingface#714)

Signed-off-by: Urszula <urszula.golowicz@intel.com>
Co-authored-by: Urszula Golowicz <urszula.golowicz@intel.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