Ensure num_logits_to_keep is always set to 1 for generate calls#1681
Merged
Conversation
|
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. |
6 tasks
IdkwhatImD0ing
added a commit
to emilyLi2020/WAVE
that referenced
this pull request
May 14, 2026
@huggingface/transformers@4.2.0's decoder_forward() unconditionally overwrites num_logits_to_keep to 0n for Gemma 4 sessions, so every decode step computes logits over the full prompt sequence (262144 vocab × every prompt token) instead of just the last token. For 200-500-token framing prompts this is a 200-500x extra MatMul on lm_head per token, explaining browser tok/s near 6 on a card that should be much faster. Fix is upstream in PR huggingface/transformers.js#1681 (merged 2026-05-08) but not yet in any published release (latest is 4.2.0 from 2026-04-23). We vendor a one-line backport via pnpm patch until 4.2.1+ ships. Patch covers all four bundle paths referenced from package.json#exports: dist/transformers.node.cjs (Node CJS - SSR) dist/transformers.node.mjs (Node ESM) dist/transformers.web.js (Browser) dist/transformers.js (legacy) To remove after the bump: drop client/patches/, drop the patchedDependencies entry in pnpm-workspace.yaml, bump @huggingface/transformers in client/package.json, regenerate lockfile. Full write-up: docs/transformers-js-gemma4-perf.md Reported: huggingface/transformers.js#1666
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.
Closes #1666