Repository navigation
Support tool calling for the Laguna chat templates - #8511
albertvillanova wants to merge 3 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. Pages changed in this PR: |
qgallouedec
left a comment
There was a problem hiding this comment.
Thanks! I'd prefer adding a tiny Laguna model in this PR, so Laguna can join all the parametrizations (SFT, GRPO with tools, the training template suite, ...) like the other families. Right now it's only covered by the parsing tests, which feels like partial support. transformers has LagunaForCausalLM, and a 2-layer model built from Laguna-XS.2's config (per-layer lists cut to 2) runs a forward with the real tokenizer at 3.2M parameters.
# Conflicts: # docs/source/chat_templates.md # trl/chat_template_utils.py # trl/chat_templates/README.md
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 96efd18. Configure here.
| messages, tokenize=True, return_dict=True, enable_thinking=enable_thinking | ||
| ) | ||
| response = text.input_ids[len(prefix.input_ids) :] | ||
| assert parse_response(tokenizer, response, prefix=prefix.input_ids, tools=[multiply]) == assistant |
There was a problem hiding this comment.
Newline breaks Laguna content round-trip
Medium Severity
The shared Laguna round-trip test expects content to equal Let me check. for every template, but laguna.jinja and laguna_v2.jinja emit a newline after the text when tool_calls follow. laguna_template closes content at <tool_call> (no leading whitespace) rather than at </assistant>, so that newline stays in content and the assertion fails for those two templates. Parsed GRPO messages would carry the same trailing newline.
Additional Locations (2)
Reviewed by Cursor Bugbot for commit 96efd18. Configure here.
There was a problem hiding this comment.
Not an issue: the content field uses the text content parser, which strips the text by default (strip=True, transformers ≥ 5.13). The trailing newline that laguna.jinja and laguna_v2.jinja emit before <tool_call> doesn't reach content. test_add_response_schema_laguna passes for all four templates, with and without thinking.


This PR makes
GRPOTrainerwith tools work on the Laguna checkpoints (poolside/Laguna-XS.2,poolside/Laguna-M.1,poolside/Laguna-XS-2.1andpoolside/Laguna-S-2.1), whose chat templates TRL did not recognize, soadd_response_schemarejected them.Part of #7943.
Motivation
Laguna checkpoints have about 2.3M downloads, and none ships a response template, so
GRPOTrainerwith tools fails at init. The four checkpoints ship four distinct chat templates. They write tool calls in the same format as GLM-4-MoE, with or without newlines around the arguments, wrap turns in<assistant>/</assistant>, and pre-fill the generation prompt with<think>or</think>. All four already have{% generation %}markers and are prefix-preserving, so they need no training template.Changes
laguna.jinja,laguna_v2.jinja,laguna_v3.jinjaandlaguna_v4.jinja, document them, and add their repos to the drift check.laguna_template, which reuses the GLM-4-MoE tool-call parsing, and set it inadd_response_schemafor the four templates.Note
Low Risk
Adds template assets, parsing rules, and tests without changing existing families’ behavior.
Overview
Adds Laguna (Poolside XS.2, M.1, XS-2.1, S-2.1) to TRL’s recognized chat-template families so
GRPOTrainerwith tools can initialize on these checkpoints instead of failing inadd_response_schema.Four reference Jinja templates are vendored (
laguna.jinjathroughlaguna_v4.jinja), documented, and registered in the Hub drift check. A dedicatedlaguna_templateresponse parser (GLM-4-MoE-style XML tool calls, thinking anchors) is wired inadd_response_schemafor all four variants. Tests cover response parsing with and without thinking; docs list Laguna among supported families.Reviewed by Cursor Bugbot for commit 96efd18. Bugbot is set up for automated code reviews on this repo. Configure here.