-
Notifications
You must be signed in to change notification settings - Fork 142
fix(inkling): align multimodal placeholders with checkpoint template #1931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -832,6 +832,12 @@ fn sort_json_keys(value: &JsonValue) -> JsonValue { | |||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /// Hugging Face chat-template helper for surfacing model-authored validation | ||||||||||||||
| /// errors instead of a generic "unknown function" render failure. | ||||||||||||||
| fn raise_exception(message: String) -> std::result::Result<String, MinijinjaError> { | ||||||||||||||
| Err(MinijinjaError::new(ErrorKind::InvalidOperation, message)) | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+837
to
+839
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using Using
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| /// Build a pre-configured `Environment<'static>` with the given template string, | ||||||||||||||
| /// Python-compat method callback, and custom `tojson` filter already registered. | ||||||||||||||
| /// The template is stored under the name `"chat"` using owned storage so the | ||||||||||||||
|
|
@@ -856,6 +862,7 @@ fn build_environment(template: String) -> Result<Environment<'static>> { | |||||||||||||
| // This overrides minijinja's built-in tojson to support additional kwargs | ||||||||||||||
| // like ensure_ascii, separators, and sort_keys that HuggingFace templates use | ||||||||||||||
| env.add_filter("tojson", tojson_filter); | ||||||||||||||
| env.add_function("raise_exception", raise_exception); | ||||||||||||||
|
|
||||||||||||||
| Ok(env) | ||||||||||||||
| } | ||||||||||||||
|
|
@@ -1169,6 +1176,21 @@ mod tests { | |||||||||||||
| assert!(result.is_err()); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| #[test] | ||||||||||||||
| fn test_raise_exception_surfaces_template_validation_message() { | ||||||||||||||
| let state = ChatTemplateState::new(Some( | ||||||||||||||
| "{{ raise_exception('reasoning_effort is invalid') }}".to_string(), | ||||||||||||||
| )) | ||||||||||||||
| .unwrap(); | ||||||||||||||
|
|
||||||||||||||
| let error = state | ||||||||||||||
| .apply(&[], ChatTemplateParams::default()) | ||||||||||||||
| .unwrap_err() | ||||||||||||||
| .to_string(); | ||||||||||||||
|
|
||||||||||||||
| assert!(error.contains("reasoning_effort is invalid"), "{error}"); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| #[test] | ||||||||||||||
| fn test_special_tokens_injected_into_context() { | ||||||||||||||
| let template = "{{ bos_token }}{% for message in messages %}{{ message.content }}{% endfor %}{{ eos_token }}"; | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an Inkling deployment uses a String-format chat template, the rendering path replaces
image_url/input_audioparts 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|>viawith_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 👍 / 👎.