Skip to content

Make trucation=false by default to align with HF#654

Open
pavel-esir wants to merge 3 commits into
openvinotoolkit:masterfrom
pavel-esir:trucation_false
Open

Make trucation=false by default to align with HF#654
pavel-esir wants to merge 3 commits into
openvinotoolkit:masterfrom
pavel-esir:trucation_false

Conversation

@pavel-esir

Copy link
Copy Markdown
Collaborator

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

@pavel-esir pavel-esir added this to the 2026.2 milestone May 6, 2026
@pavel-esir pavel-esir requested review from apaniukov and Copilot May 6, 2026 10:43
@pavel-esir pavel-esir added the bug Something isn't working label May 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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=False in tests and CLI validation tools.
  • TruncationStep updated to read a boolean state variable and select between real max_length vs “no truncation” max length.
  • Tokenizer model construction updated to register the new Assign op 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())
pavel-esir and others added 2 commits May 6, 2026 13:03
Co-authored-by: Copilot <copilot@github.com>
@pavel-esir pavel-esir removed this from the 2026.2 milestone May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants