Skip to content

Fix: Added check the type of tokenizer.json's model_merges - #987

Open
NEWTON MALLICK (N-E-W-T-O-N) wants to merge 12 commits into
microsoft:mainfrom
N-E-W-T-O-N:merges
Open

NEWTON MALLICK (N-E-W-T-O-N) wants to merge 12 commits into
microsoft:mainfrom
N-E-W-T-O-N:merges

Conversation

@N-E-W-T-O-N

@N-E-W-T-O-N NEWTON MALLICK (N-E-W-T-O-N) commented Aug 9, 2025 •

Copy link
Copy Markdown

Modern Tokenizer store merge's value as list of lists of strings. But models like GPT-2 or gemma-2 store as a list of strings
Ex Mistral

Added a check for this fix

@N-E-W-T-O-N
NEWTON MALLICK (N-E-W-T-O-N) requested a review from a team as a code owner August 9, 2025 18:33
@N-E-W-T-O-N

Copy link
Copy Markdown
Author

Mistral

merges": [
      [
        "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n",
        "\n"
      ],
      [
        "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
        "▁"
      ],
      [

@N-E-W-T-O-N

Copy link
Copy Markdown
Author

Gpt-2

"merges":["Ġ t","Ġ a","h " ...

@N-E-W-T-O-N

NEWTON MALLICK (N-E-W-T-O-N) commented Aug 11, 2025 •

Copy link
Copy Markdown
Author

@sayanshaw24

Copy link
Copy Markdown
Collaborator

Modern Tokenizer store merge's value as list of lists of strings. But models like GPT-2 or gemma-2 store as a list of strings Ex Mistral

Added a check for this fix

awesome, thanks for this! could you add a unit test here as well to ensure expected functionality: https://github.com/microsoft/onnxruntime-extensions/tree/main/test?

@sayanshaw24

Copy link
Copy Markdown
Collaborator

/azp run onnxruntime-extensions.CI

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@N-E-W-T-O-N

Copy link
Copy Markdown
Author

Using phi-4 as an example

@N-E-W-T-O-N

NEWTON MALLICK (N-E-W-T-O-N) commented Aug 13, 2025 •

Copy link
Copy Markdown
Author

The following Functions is only called when use_fast=True used in passed to tokenizer

@sayanshaw24 Sayan Shaw (sayanshaw24) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

please use test/data/phi-4-base or test/data/phi-4-mini-reasoning, we'd like to minimize tokenizer files checked into the repo; (also, FYI onnxruntime-extensions only needs the tokenizer.json and tokenizer_config.json files to load tokenizers).

Comment thread test/data/phi-4-mini-reasoning/tokenizer_config.json Outdated
@azure-pipelines

Copy link
Copy Markdown
Commenter does not have sufficient privileges for PR 987 in repo microsoft/onnxruntime-extensions

@N-E-W-T-O-N

NEWTON MALLICK (N-E-W-T-O-N) commented Aug 19, 2025 •

Copy link
Copy Markdown
Author

Hi Sayan Shaw (@sayanshaw24)
Revert back the change as requested and updated the branch .
Please merge my pr

@sayanshaw24

Copy link
Copy Markdown
Collaborator

/azp run onnxruntime-extensions.CI

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Merge the latest code .Please rerun the pipeline

@snnn

Copy link
Copy Markdown

/azp where

@azure-pipelines

Copy link
Copy Markdown
Azure DevOps orgs getting events for this repository:

@N-E-W-T-O-N NEWTON MALLICK (N-E-W-T-O-N) left a comment •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hi Sayan Shaw (@sayanshaw24) pr please merge my PR

Copilot AI lite review requested due to automatic review settings September 25, 2026 06:56

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.

Copilot review overview

🟡 Changes recommended

A critical merge-format bug remains, and string-merge coverage is missing.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity · 1 Low severity

Open (2)
What changed in this PR

Updates Hugging Face tokenizer conversion to support alternate merge formats and adds Phi-4 tokenizer coverage.

Changes:

  • Handles nested-list and string merge representations.
  • Adds a local Phi-4 tokenizer regression test.
File Summary
test/​test_autotokenizer.py Adds Phi-4 coverage, but does not test string merges. Nit: Add representative string-merge cases.
onnxruntime_extensions/​_hf_cvt.py Handles tokenizer merge formats. Critical: The generator condition is always truthy and can corrupt string merges.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread onnxruntime_extensions/_hf_cvt.py Outdated
Comment thread test/test_autotokenizer.py
The list-of-lists check tested a generator object, which is always truthy,
so flat string merges (e.g. phi-4-base, GPT-2) were split into single
characters. Move the logic into HFTokenizerConverter.normalize_merges and
add a phi-4-base test with text that needs BPE merges.
@N-E-W-T-O-N

Copy link
Copy Markdown
Author

Sayan Shaw (@sayanshaw24) could you please re-review? Your earlier comments are addressed: the tests only use the existing test/data/phi-4-base and test/data/phi-4-mini-reasoning fixtures, and tokenizer_config.json is unchanged. Commit 37f33f6 also fixes the merges format check that Copilot flagged and adds a phi-4-base test for string merges. test_autotokenizer.py passes locally (11 tests). Could you also trigger CI? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants