-
Notifications
You must be signed in to change notification settings - Fork 260
[Fix] Fix chat templating in Mini-SWE-Agent and Terminal-Bench examples #404
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 |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| from skyrl_train.inference_engines.utils import get_sampling_params_for_backend | ||
| from skyrl_train.generators.utils import ( | ||
| get_rollout_metrics, | ||
| encode_messages_subset, | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -128,6 +129,9 @@ def __init__( | |
| self.model_name = model_name | ||
| self.litellm_model_name = "openai/" + self.model_name | ||
|
|
||
| if self.generator_cfg.chat_template.name_or_path is not None: | ||
| raise NotImplementedError("MiniSWEAgentGenerator doesn't support custom chat template") | ||
|
|
||
| async def minisweagent_agent_loop( | ||
| self, | ||
| prompt: ConversationType, | ||
|
|
@@ -182,7 +186,7 @@ async def minisweagent_agent_loop( | |
|
|
||
| for message in response_messages: | ||
| # Apply chat template and tokenize each message | ||
| msg_encoding = self.tokenizer.apply_chat_template([message], add_generation_prompt=False, tokenize=True) | ||
| msg_encoding = encode_messages_subset([message], self.tokenizer) | ||
|
|
||
| # Extend response_ids with the tokens | ||
| response_ids.extend(msg_encoding) | ||
|
Collaborator
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. Can we add an assertion of
And same for terminal bench? At least a warning perhaps
Member
Author
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. Hmm such an assertion or warning can be misleading or incorrect because applying the chat template message by message can be pretty different from full conversation. For models like Qwen 3 - the thinking tokens for previous messages in the history are discarded by default. Now, if we call But then with the RHS - the think tokens for previous messages are removed. Now, I don't think either is the correct behaviour we want for on policy trainig, but in any case we shouldn't have this assertion.
Member
Author
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. As such, for Qwen3 8B, I re-ran the mini swe agent example and it is okay - actually the previous expression was also correct, because for qwen 3 8B there is no default system prompt added; print(self.tokenizer.apply_chat_template([{"role": "assistant", "content": "What is 1+1?"}], tokenize=False))
# '<|im_start|>assistant\nWhat is 1+1?<|im_end|>\n'
Member
Author
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. I believe the tests should be sufficient
Collaborator
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.
Good point... so the current behavior becomes, during inference we discard thinking tokens, and for training, we keep all thinking tokens. Made an issue for this: #410 |
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.