Skip to content

fix(inkling): align multimodal placeholders with checkpoint template - #1931

Merged
slin1237 merged 1 commit into
mainfrom
hongtaoc/inkling-chat-template
Jul 16, 2026
Merged

fix(inkling): align multimodal placeholders with checkpoint template#1931
slin1237 merged 1 commit into
mainfrom
hongtaoc/inkling-chat-template

Conversation

@chenht2022

@chenht2022 chenht2022 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Description

Problem

The current Inkling multimodal path expands inputs from the structural image/audio markers.

The checkpoint-provided chat template emits each marker followed by one soft placeholder:

  • image: <|unused_200054|>
  • audio: <|unused_200053|>

Expanding the marker leaves the template-emitted soft placeholder in the final prompt as an extra token. The template also uses raise_exception(...) for input validation, which is not currently registered in SMG's MiniJinja environment.

Solution

Expand the checkpoint-provided soft placeholders directly and keep the preceding image/audio marker in the structural range through structural_prefix(1).

Also register the Hugging Face-compatible raise_exception helper so template validation errors preserve their authored messages.

Changes

  • Expand Inkling image features from token 200054.
  • Expand Inkling audio features from token 200053.
  • Keep template-owned image/audio markers and <|audio_end|>.
  • Register raise_exception in the chat-template environment.
  • Update focused Inkling and chat-template tests.

Test Plan

  • cargo test -p llm-multimodal inkling
    • 19 unit tests and 2 golden tests passed.
  • cargo test -p llm-tokenizer test_raise_exception_surfaces_template_validation_message
    • 1 test passed.
  • cargo clippy -p llm-multimodal -p llm-tokenizer --all-targets -- -D warnings
  • cargo +nightly fmt --all -- --check
  • CI-style non-Rust pre-commit run --all-files
  • git diff --check
Checklist
  • cargo +nightly fmt passes
  • cargo clippy --all-targets --all-features -- -D warnings passes
  • (Optional) Documentation updated
  • (Optional) Please join us on Slack #sig-smg to discuss, review, and merge PRs

Summary by CodeRabbit

  • Bug Fixes

    • Updated multimodal prompt handling to use dedicated image and audio placeholder tokens.
    • Corrected image and audio feature placement and token expansion behavior.
  • Error Handling

    • Improved template validation errors by surfacing specific failure messages when invalid settings are encountered.

@github-actions github-actions Bot added tokenizer Tokenizer related changes multimodal Multimodal crate changes labels Jul 16, 2026
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 82e57132-c800-4dfa-a438-b8cd5989c161

📥 Commits

Reviewing files that changed from the base of the PR and between 60e87b0 and 2075db7.

📒 Files selected for processing (2)
  • crates/multimodal/src/registry/inkling.rs
  • crates/tokenizer/src/chat_template.rs

📝 Walkthrough

Walkthrough

Inkling now emits dedicated image and audio placeholder tokens with updated feature ranges. Chat templates can invoke a registered raise_exception helper to surface custom rendering errors.

Changes

Inkling placeholder handling

Layer / File(s) Summary
Dedicated placeholder contracts
crates/multimodal/src/registry/inkling.rs
Image and audio placeholder constants, IDs, and lookup methods now use dedicated unused tokens.
Prompt replacement and tests
crates/multimodal/src/registry/inkling.rs
Image and audio replacements emit repeated placeholder tokens with feature ranges starting at offset 0 and structural_prefix set to 1; tokenizer fixtures and assertions reflect the updated behavior.

Template error reporting

Layer / File(s) Summary
Register and validate template errors
crates/tokenizer/src/chat_template.rs
Adds and registers raise_exception, which returns a custom MinijinjaError, with a test covering the surfaced message.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested labels: tests

Suggested reviewers: key4ng, slin1237

Poem

I’m a rabbit with tokens in line,
New image and audio markers now shine.
Templates may raise a clear call,
With reasons displayed for all.
Hop, hop—the tests all align!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: aligning Inkling multimodal placeholders with the checkpoint template.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hongtaoc/inkling-chat-template

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates the InklingSpec multimodal registry to use unused placeholder tokens for image and audio modalities, adjusting the prompt replacement logic and tests accordingly. It also registers a raise_exception helper function in the chat template's MiniJinja environment to surface model-authored validation errors. Feedback suggests using minijinja::Value instead of String for the exception message parameter to avoid type coercion failures when non-string values are passed.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +837 to +839
fn raise_exception(message: String) -> std::result::Result<String, MinijinjaError> {
Err(MinijinjaError::new(ErrorKind::InvalidOperation, message))
}

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.

medium

Using String as the parameter type for raise_exception forces MiniJinja to attempt type coercion. If a template passes a non-string value (such as a boolean, number, or complex object) to raise_exception, MiniJinja will fail with a type coercion error (e.g., invalid type: ..., expected a string) instead of raising the actual authored validation message.

Using minijinja::Value instead allows the function to accept any type and convert it to a string representation via .to_string(), ensuring the authored validation message is always preserved and surfaced.

Suggested change
fn raise_exception(message: String) -> std::result::Result<String, MinijinjaError> {
Err(MinijinjaError::new(ErrorKind::InvalidOperation, message))
}
fn raise_exception(message: Value) -> std::result::Result<String, MinijinjaError> {
Err(MinijinjaError::new(ErrorKind::InvalidOperation, message.to_string()))
}

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Clean and well-tested change. The placeholder realignment correctly delegates structural markers to the checkpoint template and expands only the soft placeholders, with structural_prefix(1) properly accounting for the leading marker. The raise_exception addition is a standard HF compatibility function. No issues found.

Signed-off-by: chenht2022 <chenht2022@gmail.com>
@chenht2022
chenht2022 force-pushed the hongtaoc/inkling-chat-template branch from c8ce6b8 to 2075db7 Compare July 16, 2026 15:10
@chenht2022
chenht2022 marked this pull request as ready for review July 16, 2026 16:38

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2075db730e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +69 to +70
Modality::Image => Ok(Self::IMAGE_PLACEHOLDER.to_string()),
Modality::Audio => Ok(Self::AUDIO_PLACEHOLDER.to_string()),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep Inkling string-template anchors on content markers

When an Inkling deployment uses a String-format chat template, the rendering path replaces image_url/input_audio parts with the value returned here before the checkpoint template has a chance to add TML markers. Returning the soft placeholders means those prompts contain only <|unused_...|>, while the replacement code still assumes a preceding <|content_image|>/<|content_audio_input|> via with_structural_prefix(1) and does not re-emit it; expansion then folds the previous text/newline token into the structural range and the final prompt is missing the typed marker. The OpenAI-format checkpoint template may be fine, but the supported String-template path regresses unless the content marker remains the rendered anchor or is emitted in the replacement.

Useful? React with 👍 / 👎.

@slin1237
slin1237 merged commit d43aa04 into main Jul 16, 2026
87 of 89 checks passed
@slin1237
slin1237 deleted the hongtaoc/inkling-chat-template branch July 16, 2026 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

multimodal Multimodal crate changes tokenizer Tokenizer related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants