Make trucation=false by default to align with HF#654
Open
pavel-esir wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates OpenVINO Tokenizers to match Hugging Face behavior by making truncation disabled by default and introducing a stateful runtime switch in the generated tokenizer graph so consumers (e.g., openvino_genai) can enable/disable truncation dynamically.
Changes:
- Default HF reference comparisons updated to
truncation=Falsein tests and CLI validation tools. TruncationStepupdated to read a boolean state variable and select between realmax_lengthvs “no truncation” max length.- Tokenizer model construction updated to register the new
Assignop as a model sink so the state is preserved.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
tests/tokenizers_test.py |
Aligns HF reference tokenization in tests with the new default (truncation=False). |
python/openvino_tokenizers/tokenizer_pipeline.py |
Adds stateful truncation toggle (ReadValue/Assign + Select) and registers stateful sinks on the model. |
python/openvino_tokenizers/cli_tools/diagnose_tokenizer.py |
Aligns HF reference output in diagnostics with truncation=False. |
python/openvino_tokenizers/cli_tools/check_tokenizer.py |
Aligns HF reference output in checker + GenAI checks with truncation=False. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| stateful_sinks = [] | ||
| for step in self.steps: | ||
| if isinstance(step, TruncationStep): |
| axis: int = -1 | ||
| _stateful_assign: Optional[op.Node] = field(default=None, init=False, repr=False) | ||
|
|
||
| TRUNCATE_ENABLED_VAR_ID = "is_max_length_set" |
| _stateful_assign: Optional[op.Node] = field(default=None, init=False, repr=False) | ||
|
|
||
| TRUNCATE_ENABLED_VAR_ID = "is_max_length_set" | ||
| DISABLE_TRUNCATE_MAX_LENGTH = np.int32(np.iinfo(np.int32).max - 64) |
Comment on lines
+937
to
+945
| truncate_enabled_default = make_constant_node(False, Type.boolean) | ||
| truncate_enabled = opset.read_value(truncate_enabled_default, self.TRUNCATE_ENABLED_VAR_ID) | ||
| self._stateful_assign = opset.assign(truncate_enabled, self.TRUNCATE_ENABLED_VAR_ID) | ||
|
|
||
| max_length_const = make_constant_node(self.max_length, Type.i32) | ||
| no_truncate_const = make_constant_node(self.DISABLE_TRUNCATE_MAX_LENGTH, Type.i32) | ||
| selected_max_length = opset.select(truncate_enabled, max_length_const, no_truncate_const) | ||
|
|
||
| input_nodes.extend(selected_max_length.outputs()) |
Comment on lines
+1632
to
+1633
| if isinstance(step, TruncationStep): | ||
| stateful_sinks.extend(step.get_stateful_sinks()) |
Co-authored-by: Copilot <copilot@github.com>
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.
Description
Previously, truncation was always enabled in OpenVINO Tokenizers. In Hugging Face tokenizers, truncation is not stored as a model attribute; it is controlled by the runtime encode argument, and defaults to false. This change updates the OpenVINO Tokenizers default to match Hugging Face.
The change adds an extra ReadValue and constant so the truncation state is still stored in the graph. openvino_genai can then set this variable at runtime to enable or disable truncation.
Ticket: CVS-185349