[gpt-oss] Add model_identity to system message retrieval for harmony chat template#30247
[gpt-oss] Add model_identity to system message retrieval for harmony chat template#30247lyuwen wants to merge 2 commits intovllm-project:mainfrom
Conversation
Signed-off-by: LFu <lyuwen@users.noreply.github.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
Code Review
This pull request aims to pass the model_identity from chat_template_kwargs to the system message formatter for the harmony chat template. However, the current implementation has a critical bug where it does not handle the case where request.chat_template_kwargs is None, which will lead to an AttributeError and crash the server. I've provided a suggestion to fix this issue.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: LFu <lyuwen@users.noreply.github.com>
|
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels. Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run You ask your reviewers to trigger select CI tests on top of Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging. To run CI, PR reviewers can either: Add If you have any questions, please reach out to us on Slack at https://slack.vllm.ai. 🚀 |
|
@lyuwen could you share some examples in your test plans. what's the rendered messages before and after the change? |
|
For example, if I run this before the patch: from openai import OpenAI
client = OpenAI(base_url="http://127.0.0.1:8000/v1", api_key="EMPTY")
MODEL_NAME = "gpt-oss-120b"
response = client.chat.completions.create(
model="gpt-oss-120b",
messages=[{"role": "user", "content": "What are you?"}],
extra_body={
"chat_template_kwargs": {"model_identity": "You are DeepSeek developed by MoonShot.", "reasoning_effort": "high"},
}
)
print("Reasoning:")
print(response.choices[0].message.reasoning_content)
print("Final:")
print(response.choices[0].message.content)The output would be : But the expected behavior is the model assuming the provided identity and respond with something like the following: Upon investigation, below are the reason this parameter is not taking effect - the vllm/vllm/entrypoints/openai/serving_chat.py Lines 1763 to 1768 in 73a484c And system message just used the default model identity: https://github.com/openai/harmony/blob/ec7606df9e87e3d0a1fec9f50928c1e407f0c438/python/openai_harmony/__init__.py#L181-L184 |
|
The model_identity parameter itself is already in the vLLM code base, it just wasn't used. vllm/vllm/entrypoints/openai/parser/harmony_utils.py Lines 87 to 96 in 7cab92f So the prompt with chat template should look like But without model_identity passed in, it used the default: |
|
/cc @yeqcharlotte PTAL. |
| assert not self.supports_browsing | ||
| assert not self.supports_code_interpreter | ||
| sys_msg = get_system_message( | ||
| model_identity=(request.chat_template_kwargs or {}).get("model_identity"), |
There was a problem hiding this comment.
| model_identity=(request.chat_template_kwargs or {}).get("model_identity"), | |
| model_identity=(request.chat_template_kwargs or {}).get("harmony_model_identity"), |
WDYT? @yeqcharlotte @lyuwen
There was a problem hiding this comment.
"model_identity" seems more straightforward since it aligns with the GPT-OSS's original chat template. Using "harmony_model_identity" would need a bit more explanation in the vllm docs.
Pasted from the chat template:
{#-
--
In addition to the normal inputs of `messages` and `tools`, this template also accepts the
following kwargs:
- "builtin_tools": A list, can contain "browser" and/or "python".
- "model_identity": A string that optionally describes the model identity.
- "reasoning_effort": A string that describes the reasoning effort, defaults to "medium".
#}
Maybe the additional ones suggested in #30873 could use a prefix since it could be harmony specific?
Anyway, either works for me.
There was a problem hiding this comment.
It appears that apart from reasoning_effort, the remaining fields are specific to the Harmony format.
I think it might be beneficial to add a harmony_ prefix to these keys (e.g., harmony_model_identity). My concern is that even users familiar with the Harmony format might easily overlook this feature unless they carefully read the vLLM documentation.
| sys_msg = get_system_message( | ||
| model_identity=(request.chat_template_kwargs or {}).get("model_identity"), | ||
| reasoning_effort=request.reasoning_effort, | ||
| browser_description=None, | ||
| python_description=None, | ||
| with_custom_tools=request.tools is not None, | ||
| ) |
There was a problem hiding this comment.
I realized I had opened a duplicate PR (#30873) addressing the same issue, as I missed this one initially. I'll be closing mine in favor of this one.
However, I'd like to suggest an improvement based on my implementation. Instead of supporting only model_identity, it would be better to read other arguments supported by get_system_message from chat_template_kwargs as well. This provides greater flexibility for future use cases without needing additional code changes.
The test plan remains the same as described in this PR.
| chat_template_kwargs = request.chat_template_kwargs or {} | |
| sys_msg = get_system_message( | |
| model_identity=chat_template_kwargs.get("model_identity"), | |
| reasoning_effort=request.reasoning_effort, | |
| start_date=chat_template_kwargs.get("start_date"), | |
| browser_description=chat_template_kwargs.get("browser_description"), | |
| python_description=chat_template_kwargs.get("python_description"), | |
| container_description=chat_template_kwargs.get("container_description"), | |
| instructions=chat_template_kwargs.get("instructions"), | |
| with_custom_tools=should_include_tools, | |
| ) |
Purpose
When using GPT-OSS,
model_identitypassed in fromchat_template_kwargsis not being used to adjust model's identity. This PR is to pass themodel_identityfrom chat/completion to the system message formatter.Test Plan
Test Result
Essential Elements of an Effective PR Description Checklist
supported_models.mdandexamplesfor a new model.