Repository navigation
Drop content=None from messages in apply_chat_template - #45422
qgallouedec wants to merge 10 commits into
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Rocketknight1
left a comment
There was a problem hiding this comment.
Sorry for losing track of this one! I think it's a good fix, and a good path to standardization, but Deepseek-R1 is a very major model, even if it's a little out of date now that V4 exists, and this change would be very breaking for it. I think we should patch its template on the Hub first, then merge this!
|
View the CircleCI Test Summary for this PR: https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=45422&sha=dc4c5d |
CI recapDashboard: View test results in Grafana |
… and tokenizer boundary fixes Preserve the upstream Qwen parser/streaming-engine and tokenizer corrections as attributed source patches. Keep parser state, configuration and token handling together so the integration can validate the complete compatible source set. Provenance Upstream PRs and authors: - vllm-project/vllm#56113 — Svliverse-1 - vllm-project/vllm#56661 — JordiPosthumus - huggingface/transformers#45422 — qgallouedec - huggingface/transformers#47855 — ameerhmz - huggingface/transformers#47990 — Ilya-a-sergeyev-ger - huggingface/transformers#48708 — albertvillanova
… and tokenizer boundary fixes Preserve the upstream Qwen parser/streaming-engine and tokenizer corrections as attributed source patches. Keep parser state, configuration and token handling together so the integration can validate the complete compatible source set. Provenance Upstream PRs and authors: - vllm-project/vllm#56113 — Svliverse-1 - vllm-project/vllm#56661 — JordiPosthumus - huggingface/transformers#45422 — qgallouedec - huggingface/transformers#47855 — ameerhmz - huggingface/transformers#47990 — Ilya-a-sergeyev-ger - huggingface/transformers#48708 — albertvillanova
In
apply_chat_template, drop thecontentkey from messages when its value isNonebefore passing to the Jinja template.Why this is a bug fix, not a breaking change
content=Nonemeans "there is no content", it is semantically identical to the key being absent. No caller setscontent=Noneexpecting the literal string"None"to appear in the output, or the output to be different than if the key were absent.Yet today, several templates crash or misbehave:
"None": GLM-5.1, GLM4MOE, MiniMax-M2.5, MiniMax-M2.7After this change, out of the 20 tool-calling models tested:
"None"→ correct output)content=Nonebut crashes on absent key, which IMO is itself a template bug to fix on the Hub repo).Why not just leave it to template authors?
Because
content=Noneis a real-world input (it's what the OpenAI API returns for tool-call-only messages)msg_dict = {'content': None, 'refusal': None, 'role': 'assistant', 'annotations': [], 'audio': None, 'function_call': None, 'tool_calls': [{'id': 'call_Im08OArU1YY2mKi7ntPxdm22', 'function': {'arguments': '{"city":"Paris"}', 'name': 'get_weather'}, 'type': 'function'}]}and expecting every template author to handle it correctly is a losing game — 8 out of 20 already don't. One normalization line in
apply_chat_templatefixes all of them at once and prevents future templates from hitting the same issue.Part of the broader discussion in #45419.