Fix num_logits_to_keep default in decoder_forward and add get_available_devices()#1669
Closed
Suh0161 wants to merge 2 commits into
Closed
Fix num_logits_to_keep default in decoder_forward and add get_available_devices()#1669Suh0161 wants to merge 2 commits into
Suh0161 wants to merge 2 commits into
Conversation
…ing to tokenizer - TokenClassificationPipeline now populates start/end character offsets on every raw token result by scanning forward through the original text. Grouped results (aggregation_strategy='simple') carry the span of the first-to-last token in the group. - PreTrainedTokenizer._call now accepts return_offsets_mapping: true, which adds an offset_mapping field ([start, end) per token) to the encoding. Works for single strings and batched input; handles padding with [0,0] and strips the field before tensor conversion so it is never tensorized. - Adds computeOffsets() helper with case-insensitive fallback for uncased tokenizers (e.g. bert-base-uncased). Closes huggingface#425, closes huggingface#633.
- Fix decoder_forward() defaulting num_logits_to_keep to 0n instead of 1n. The comment correctly stated the value should be 1 to avoid computing logits for the entire prompt sequence, but the code contradicted it. For models like Gemma 4 with long contexts and large vocabularies this caused ~20 GB of unnecessary memory allocation during generation. Closes huggingface#1666. - Add get_available_devices() to the public API. The underlying supportedDevices list already existed in the ONNX backend but was not accessible to users. Returns a copy of the device list sorted by priority/performance for the current environment (Node.js, browser, Electron). Closes huggingface#1643.
Author
|
Closing in favor of #1670, which contains this work in the same commit stack. |
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, closes #1643.
Fix:
num_logits_to_keepdefaults to0ninstead of1n(#1666)decoder_forward()had a comment correctly explaining thatnum_logits_to_keep=1reduces memory during generation, but the code set0n— causing the ONNX model to compute logits for the entire prompt instead of just the last token. For Gemma 4 with a 20k token prompt and 262k vocabulary this wastes ~20 GB of memory and can cause OOM crashes.Fix: Change
[0n]→[1n]to match both the comment and the behavior ofdecoder_prepare_inputs_for_generation().Feature:
get_available_devices()(#1643)The
supportedDeviceslist already existed inside the ONNX backend but was never exposed to users. This adds a publicget_available_devices()function: