Skip to content

Fix undefined 'input' variable#45895

Merged
Cyrilvallez merged 1 commit into
huggingface:mainfrom
fullyz:fix-undefined-input-variable
May 13, 2026
Merged

Fix undefined 'input' variable#45895
Cyrilvallez merged 1 commit into
huggingface:mainfrom
fullyz:fix-undefined-input-variable

Conversation

@fullyz

@fullyz fullyz commented May 11, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes self.embed_positions(input, ...) which references undefined variable input instead of input_ids in decoder forward methods.

This was introduced during cache refactoring (#35314, #44330) where the input = input_ids local alias was removed but the input reference was not updated.

-        positions = self.embed_positions(input, past_key_values_length, position_ids=position_ids)
+        positions = self.embed_positions(input_ids, past_key_values_length, position_ids=position_ids)

Currently this works because position_ids is always provided, making the first argument to embed_positions unused.

  • I confirm that this is not a pure code agent PR.

Before submitting

  • This PR fixes a typo or improves the docs
  • Did you read the contributor guideline?
  • Was this discussed/approved via a Github issue or the forum?
  • Did you make sure to update the documentation with your changes? (N/A)
  • Did you write any new necessary tests?

Who can review?

@ArthurZucker @Cyrilvallez

@github-actions

Copy link
Copy Markdown
Contributor

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

run-slow: bart, bigbird_pegasus, mbart, plbart, pp_formulanet

@fullyz
fullyz force-pushed the fix-undefined-input-variable branch from 5bcdb5e to c28203a Compare May 11, 2026 13:58
@fullyz fullyz changed the title Fix undefined 'input' variable and add input_ids None guard Fix undefined 'input' variable May 11, 2026

# embed positions
positions = self.embed_positions(input, past_key_values_length, position_ids=position_ids)
positions = self.embed_positions(input_ids, past_key_values_length, position_ids=position_ids)

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.

we don't need to pass inputs/past-length since we already pre-computed position ids a few lines above

@Cyrilvallez Cyrilvallez left a comment

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.

Woww, indeed a bad typo! Thanks for fixing!

@Cyrilvallez
Cyrilvallez merged commit e51a963 into huggingface:main May 13, 2026
24 checks passed
jp1924 pushed a commit to jp1924/transformers that referenced this pull request May 18, 2026
khushali9 pushed a commit to khushali9/transformers that referenced this pull request Jun 8, 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