Skip to content

Emit tool-calling special tokens in ORT GenAI config - #524

Merged
justinchuby merged 14 commits into
mainfrom
copilot/add-special-tokens-genai-config
Aug 21, 2026
Merged

Emit tool-calling special tokens in ORT GenAI config#524
justinchuby merged 14 commits into
mainfrom
copilot/add-special-tokens-genai-config

Conversation

Copilot AI commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

ORT GenAI config output now declares Qwen and Phi tool-calling delimiters, including Qwen3 reasoning delimiters, so runtime token parsing can recognize tool and thinking blocks.

  • Model token mappings

    • Qwen2: <tool_call> / </tool_call>
    • Qwen3: tool-call tokens plus <think> / </think>
    • Phi-4 Mini (phi3 config type): <|tool_call|> / <|/tool_call|>
  • Safety

    • Emit IDs only when the configured vocabulary contains them.
    • Prevent special-token mappings from replacing BOS/EOS/PAD configuration.
{
  "model": {
    "bot_token_id": 151657,
    "eot_token_id": 151658,
    "bor_token_id": 151667,
    "eor_token_id": 151668
  }
}
  • Coverage
    • Adds family-specific and vocabulary-boundary regression cases.

@CLAassistant

CLAassistant commented Aug 20, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ justinchuby
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

@justinchuby

Copy link
Copy Markdown
Member

@copilot other qwen 3.5+ models can use the same tags as qwen3

Copilot AI and others added 3 commits August 20, 2026 18:00
Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Copilot AI changed the title [WIP] Add special tokens for tool calling in genai_config Emit tool-calling special tokens in ORT GenAI config Aug 20, 2026
Copilot AI requested a review from justinchuby August 20, 2026 18:20
Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>

Copilot AI commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

@copilot other qwen 3.5+ models can use the same tags as qwen3

Added Qwen 3.5-MoE positive and vocabulary-boundary regression coverage for the existing Qwen3 tag mapping in 9912790.

@justinchuby

Copy link
Copy Markdown
Member

@copilot actually, see if you could read from tokenizer_config.json and avoid model specific logic.

@justinchuby

Copy link
Copy Markdown
Member

@copilot or tokenizer.json I should say. You decide

Copilot AI and others added 4 commits August 20, 2026 18:49
Derive tool and reasoning delimiter IDs from tokenizer_config.json so exports are not tied to specific model families.

Signed-off-by: GitHub <noreply@github.com>

Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Avoid selecting an arbitrary delimiter ID when tokenizer metadata contains conflicting spellings.

Signed-off-by: GitHub <noreply@github.com>

Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Use distinct raw and parsed token ID names when reading tokenizer metadata.

Signed-off-by: GitHub <noreply@github.com>

Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Clarify that special token parsing reads copied tokenizer configuration from the export directory.

Signed-off-by: GitHub <noreply@github.com>

Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
@justinchuby

Copy link
Copy Markdown
Member

@copilot survey all models that we support that has this thinking and tool calling tokens, and make sure we have covered all forms of the contents.

Copilot AI commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

@copilot actually, see if you could read from tokenizer_config.json and avoid model specific logic.

Implemented in 8b23146: tool and reasoning delimiter IDs now come from tokenizer_config.json instead of model-family checks, with vocabulary validation and regression coverage.

@justinchuby

Copy link
Copy Markdown
Member

In a follow up PR declare model capabilities so that we assert tool calling supported models has a tool calling string emitted.

Copilot AI and others added 2 commits August 20, 2026 19:01
Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>

Copilot AI commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

@copilot survey all models that we support that has this thinking and tool calling tokens, and make sure we have covered all forms of the contents.

Survey confirmed ORT GenAI recognizes the Qwen/Qwen3 and Phi delimiter spellings already mapped. 4a4afd6 now covers every supported spelling in both Hugging Face metadata layouts, with vocabulary and cross-file-conflict tests.

@copilot or tokenizer.json I should say. You decide

Implemented generic extraction from both tokenizer_config.json and tokenizer.json in 4a4afd6, including conflicting-ID protection.

@github-actions

github-actions Bot commented Aug 21, 2026

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing 4097572071d155

Model Sub-model Changes Status

No architecture changes detected.


Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed)

@justinchuby
justinchuby marked this pull request as ready for review August 21, 2026 14:59
@justinchuby
justinchuby requested review from a team and a lite review from Copilot August 21, 2026 14:59
@github-actions

github-actions Bot commented Aug 21, 2026

Copy link
Copy Markdown

Performance Comparison

Comparing 4097572071d155

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0%
bert (feature-extraction) num_nodes 60 60 +0.0%
falcon model_size_bytes 364 KB 364 KB +0.0%
falcon num_nodes 66 66 +0.0%
gemma2 model_size_bytes 428 KB 428 KB +0.0%
gemma2 num_nodes 105 105 +0.0%
gpt2 model_size_bytes 388 KB 388 KB +0.0%
gpt2 num_nodes 54 54 +0.0%
llama model_size_bytes 425 KB 425 KB +0.0%
llama num_nodes 60 60 +0.0%
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0%
llama (static-cache) num_nodes 56 56 +0.0%
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0%
mamba (ssm-text-generation) num_nodes 94 94 +0.0%
phi3 model_size_bytes 421 KB 421 KB +0.0%
phi3 num_nodes 58 58 +0.0%
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0%
phi3 (static-cache) num_nodes 54 54 +0.0%
qwen2 model_size_bytes 425 KB 425 KB +0.0%
qwen2 num_nodes 60 60 +0.0%
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0%
qwen2 (static-cache) num_nodes 56 56 +0.0%
qwen3_5_moe (hybrid-text-generation) model_size_bytes 506 KB 506 KB +0.0%
qwen3_5_moe (hybrid-text-generation) num_nodes 264 264 +0.0%
qwen3_5_text (hybrid-text-generation) model_size_bytes 458 KB 458 KB +0.0%
qwen3_5_text (hybrid-text-generation) num_nodes 126 126 +0.0%
qwen3_5_vl (hybrid-qwen-vl) model_size_bytes 977 KB 977 KB +0.0%
qwen3_5_vl (hybrid-qwen-vl) num_nodes 428 428 +0.0%
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0%
t5 (seq2seq) num_nodes 166 166 +0.0%
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0%
whisper (speech-to-text) num_nodes 128 128 +0.0%

No performance regressions.

@justinchuby

Copy link
Copy Markdown
Member

@copilot resolve merge conflicts.

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

Adds support for emitting ORT GenAI “tool calling” and “thinking/reasoning” delimiter token IDs into genai_config.json, sourced from tokenizer metadata and guarded to avoid overriding core BOS/EOS/PAD settings. This extends the ORT GenAI integration so downstream runtime parsing can reliably detect tool/thinking blocks for Qwen2/Qwen3 and Phi (phi3 config type).

Changes:

  • Extend GenaiConfigGenerator with a with_special_tokens() API and emit those fields under model in genai_config.json, disallowing overrides of bos_token_id/eos_token_id/pad_token_id.
  • Add tokenizer-metadata parsing in the ORT GenAI exporter to discover tool/thinking delimiter IDs (only when in-vocab; ignore ambiguous/conflicting sources).
  • Add regression tests covering override protection, vocab-boundary behavior, malformed tokenizer metadata, and ambiguity handling.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/mobius/integrations/ort_genai/genai_config.py Add support for extra model-level special token ID fields and prevent overriding standard token IDs.
src/mobius/integrations/ort_genai/genai_config_test.py Add unit test ensuring special tokens cannot replace BOS/EOS/PAD fields.
src/mobius/integrations/ort_genai/auto_export.py Parse tool/thinking delimiter IDs from tokenizer metadata and inject into emitted genai config.
src/mobius/integrations/ort_genai/auto_export_test.py Add exporter regression tests for delimiter extraction, boundary conditions, malformed input, and ambiguity resolution.

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

Signed-off-by: GitHub <noreply@github.com>

Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>

Copilot AI commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

@copilot resolve merge conflicts.

Resolved the conflict with current main in merge commit 17aed32. The targeted ORT GenAI suite passes (181 tests).

@sayanshaw24

Copy link
Copy Markdown

Looks great, thanks for adding this! Could we add some unit tests that leverage Mobius to ensure the workflow is accurate?

Download tokenizer metadata from known Qwen and Phi checkpoints and verify the generated ORT GenAI config emits the expected tool-call and reasoning token IDs.\n\nCo-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@justinchuby
justinchuby merged commit 656a47e into main Aug 21, 2026
21 of 23 checks passed
@justinchuby
justinchuby deleted the copilot/add-special-tokens-genai-config branch August 21, 2026 20:05
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.

Add special tokens for tool calling in genai_config

5 participants