Repository navigation
[BUGFIX] gpt-oss chat template: emit blank lines after developer message - #19090
DimitriChrysafis wants to merge 2 commits into
Conversation
|
Thank you for the PR! After checking this against OpenAI's reference Harmony renderer (
Comparing developer blocks against
All 4 mismatches are instructions without tools. With the PR, the last token before |
…#19241) Adds a regression test that pins the gpt-oss developer block rendered by `get_chat_template(tokenizer, "gpt-oss")` (and the `gptoss` alias) to the output of OpenAI's reference Harmony renderer, `openai-harmony`, which vLLM uses for gpt-oss. The official Hugging Face `chat_template.jinja` appends `\n\n` after the developer instructions even when no tools are given (side effect of openai/gpt-oss-120b discussion #85). Harmony does not. Unsloth main already matches Harmony, but porting the HF template again (as in unslothai#19090) would silently change the last token before `<|end|>` from `.` to `.\n\n` for every gpt-oss fine-tune with a system prompt, so training would no longer match what vLLM and Ollama serve. Test cases (system and developer role, both template aliases): | Case | Expected developer block | |---|---| | Instructions, no tools | `# Instructions\n\nBe helpful.<\|end\|>` | | Instructions and tools | `# Instructions\n\nBe helpful.\n\n# Tools ...<\|end\|>` | | Tools, no instructions | `# Tools ...<\|end\|>` | The expected strings were rendered with `openai-harmony` 0.0.8. A second test re-renders them with the live library when it is installed (skipped otherwise), so the literals cannot drift from Harmony. Verification: - main: 13 passed (10 template cases plus the 3 live Harmony checks) - main with the unslothai#19090 template change applied: 4 failed, 9 passed (exactly the instructions-without-tools cells fail) Test only, no library code changes.
In our gpt-oss template, the
\n\nafter the developer message is only emitted when tools are present. Upstream moved it insideif developer_message(openai/gpt-oss-20b commitcbf31f6266), the day after the revision we ported, and we never picked that up. A developer message without tools runs straight into the next block.This moves that one line. The output now matches the current official
chat_template.jinjain every scenario I tried. Our more forgiving handling ofcontent=Nonetool calls (#17176) stays as it is.Tests:
tests/python/test_gptoss_developer_block.py. 4 cases fail on main, and all 8 pass with the fix.