Skip to content

fix: pass cache to Hugging Face forwards that declare it - #2063

Open
emerardd wants to merge 1 commit into
TransformerLensOrg:devfrom
emerardd:fix/hf-forward-cache-keyword
Open

emerardd wants to merge 1 commit into
TransformerLensOrg:devfrom
emerardd:fix/hf-forward-cache-keyword

Conversation

@emerardd

Copy link
Copy Markdown
Contributor

Description

Transformers 5.24 renamed the top-level model forward keyword from past_key_values to cache. #2047 handles the rename inside attention and recurrent layers, but manual cache injection and the ordinary cached generation path still send the deprecated keyword into the HF model. Transformers 5.24.1 accepts it with a FutureWarning.

Keep the bridge's public past_key_values argument and translate it at the Transformers driver boundary when the wrapped model declares cache in place of past_key_values. Older or uninspectable forwards keep the legacy keyword. The driver checks the signature once per underlying model.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Validation

  • Before the fix, GPT-2 and Llama failed four manual-cache and cached-generation cases when the relevant FutureWarning was treated as an error.
  • The focused suite covers cache population, cached/uncached/HF generation parity, Falcon, MPT, driver model replacement, and forward kwargs.
  • The focused suite passed under Transformers 5.13.0 and 5.24.1 with the deprecated cache-keyword warning treated as an error.
  • Changed-file formatting, mypy, and git diff --check passed. The full unit suite was not run.

Checklist

  • My changes generate no new warnings
  • I have added tests that prove my fix is effective
  • New and existing unit tests pass locally with my changes (full unit suite not run)
  • I have not rewritten tests relating to key interfaces which would affect backward compatibility

This branch has not been deployed

No deployments
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