Fix decoder prefix preprocessing in alternatives mode - #2087
Draft
akira-in-tech wants to merge 1 commit into
Draft
Fix decoder prefix preprocessing in alternatives mode#2087akira-in-tech wants to merge 1 commit into
akira-in-tech wants to merge 1 commit into
Conversation
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.
Summary
Fix decoder prefix prefill when
return_alternativesforwards multiple tokens at decoding step 0.For models that both start from a zero decoder embedding and scale embeddings (including Marian conversions), the previous sequence path zeroed the entire prefetched prefix and skipped scaling for every token. This made the alternatives distribution differ from normal step-by-step decoding.
The decoder now uses the existing sequence preprocessing behavior for multi-token input at step 0: only the first embedding is zeroed, while later prefix embeddings are scaled normally. Position encoding and decoder state still use the original decoding step.
Fixes #2014.
Tests
start_from_zero_embedding=Trueand embedding scaling enabled.-0.6844518vs expected-0.6613321) and passes after the fix.python -m pytest python/tests/test_translator.py::test_return_alternatives_with_scaled_prefix -q: 1 passed.Conv1DGroupNoBiasQuantizedon the macOS Accelerate backend, outside the decoder code path changed here.black --check,isort --check-only,flake8, andgit diff --checkpass for the changed files (using the repository's existing flake8 ignores).AI disclosure
AI assistance was used to search for duplicate work, reason about the reported root cause, and help draft the patch and regression test. I reviewed the decoder flow, built and ran the before/after reproducer, checked the final diff, and remain responsible for the correctness and design of this change.