Skip to content

fix(attention_visualizer): add default value for image_seq_length#38577

Merged
Rocketknight1 merged 1 commit intohuggingface:mainfrom
IceGiraffe:fix-attention-visualizer-bug
Jun 4, 2025
Merged

fix(attention_visualizer): add default value for image_seq_length#38577
Rocketknight1 merged 1 commit intohuggingface:mainfrom
IceGiraffe:fix-attention-visualizer-bug

Conversation

@IceGiraffe
Copy link
Copy Markdown
Contributor

@IceGiraffe IceGiraffe commented Jun 4, 2025

What does this PR do?

Fixes a small bug in attention_visualizer.py where image_seq_length may be used before assignment.

🐛 Bug Description

Calling visualize_attention_mask() triggers:
UnboundLocalError: cannot access local variable 'image_seq_length' where it is not associated with a value

Fix

Just adds one line code

image_seq_length = None

Fixes #38576

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • (N/A) Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • (N/A) Did you write any new necessary tests?

Who can review?

@ArthurZucker

Copy link
Copy Markdown
Member

@Rocketknight1 Rocketknight1 left a comment

Choose a reason for hiding this comment

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

Yes, this looks like a clean fix to me. Thank you!

@Rocketknight1 Rocketknight1 force-pushed the fix-attention-visualizer-bug branch from 47b732c to 980b4c6 Compare June 4, 2025 12:07
@Rocketknight1 Rocketknight1 enabled auto-merge (squash) June 4, 2025 12:08
@Rocketknight1 Rocketknight1 merged commit 82fa68c into huggingface:main Jun 4, 2025
10 checks passed
@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.

@IceGiraffe IceGiraffe deleted the fix-attention-visualizer-bug branch June 4, 2025 12:44
bvantuan pushed a commit to bvantuan/transformers that referenced this pull request Jun 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants