Repository navigation
Conversation
Assisted decoding (`assistant_model=...` or `prompt_lookup_num_tokens=...`) with `output_attentions=True` raised `IndexError: tuple index out of range` for any attention implementation that does not return attentions, including `sdpa`, the default for most models. The guard already intended to cover this case -- its comment reads "some (V)LLMs have hard requirement on SDPA and thus never return attn" -- but it only handled an `attentions` tuple populated with `None`s. `sdpa` returns an empty tuple instead, so indexing it raised before the `is not None` check could run. Every other decoding strategy only warns and returns empty attentions. The existing assisted-decoding tests force `_attn_implementation = "eager"` so that attentions are available, which is why the no-attentions path was never exercised.
Contributor
|
Thank you for your contribution 🤗! CI Security Gate — waiting for maintainer approvalCI is approved automatically only for authors who already have a contribution merged in this repository. A maintainer will review this PR and approve CI to run on it. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this fixes
generate()raisesIndexError: tuple index out of rangewhen assisted decoding (assistant_model=...orprompt_lookup_num_tokens=...) is combined withoutput_attentions=True, for any model whose attentionimplementation does not return attentions — including
sdpa, the default for most models.Every other decoding strategy only emits the usual
sdpa` attention does not support `output_attentions=Truewarning and returns empty attentions, so this isspecific to assisted decoding.
Reproducer (fails on
main, CPU only, no checkpoint download)Cause
The guard at
generation/utils.py:4220already intends to cover this case — its comment reads"some (V)LLMs have hard requirement on SDPA and thus never return attn" — but it only handles an
attentionstuple populated withNones.sdpainstead returns an empty tuple, so[0]raisesbefore the
is not Nonecheck can run.Fix
Check that the tuple is non-empty before indexing it:
With the fix, attention collection is skipped (as the guard intended) and generation completes normally.
Why CI did not catch it
test_prompt_lookup_decoding_matches_greedy_searchandtest_assisted_decoding_matches_greedy_searchboth setconfig._attn_implementation = "eager"so thatoutput_attentionsis supported, so the no-attentions path wasnever exercised in assisted decoding.
Test
Adds
test_prompt_lookup_decoding_output_attentions_without_attentionstotests/generation/test_utils.py, built from a tiny in-processllamaconfig (no checkpoint download, runs in~1s). It fails on
mainwith theIndexErrorabove and passes with the fix.