SFT double-encodes tool-call arguments for chat templates that apply `| tojson` (Qwen2.5, Llama 3.2)
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 50/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- python
- Ambito
- machine-learning
Direzione di ricerca
Start with normalize_tool_call_arguments_for_chat_template in src/art_inference/chat_template.py, and check how it detects templates that iterate arguments (| items, is mapping). Run the reproduction script in the issue against a template that uses tool_call.arguments | tojson to confirm the double-encoded string. Done means that case renders a dict, while templates with an is string guard keep the exact string, and the tests in tests/unit/test_preprocessing_tokenize.py pass.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
When SFT data contains OpenAI-format tool calls, the arguments field is a JSON string (the shape shown in the SFT docs). normalize_tool_call_arguments_for_chat_template only turns it into a dict when the template iterates the arguments (| items, .items(), is mapping). Templates such as Qwen2.5-Instruct and Llama 3.2 Instruct render tool_call.arguments | tojson instead, so they get the string and tojson quotes it a second time:
"arguments": "{\"location\": \"Hobart\"}"
At inference time vLLM passes the arguments to the template as a dict, so the template renders "arguments": {"location": "Hobart"}. The SFT target then differs from what the same model sees and is supposed to produce.
The function and the unit tests are in src/art_inference/chat_template.py and tests/unit/test_preprocessing_tokenize.py.
normalize_tool_call_arguments_for_chat_template is also used for RL trajectory rendering and tinker server prompts, where templates with an is string guard must keep the exact sampled argument string, so any change to the detection has to leave those cases alone.
Reproduction
Requirements: jinja2==3.1.6. Set SRC to a checkout of the repo. The template below is the tool-call part of Qwen2.5-Instruct's chat template.
import importlib.util, os, sys
import jinja2
src = os.environ.get("SRC", "./src")
p = os.path.join(src, "src/art_inference/chat_template.py")
spec = importlib.util.spec_from_file_location("ct", p)
ct = importlib.util.module_from_spec(spec); spec.loader.exec_module(ct)
TEMPLATE = """{%- for message in messages %}{%- if message.role == "assistant" and message.tool_calls %}{%- for tool_call in message.tool_calls %}{%- if tool_call.function is defined %}{%- set tool_call = tool_call.function %}{%- endif %}
<tool_call>
{"name": "{{ tool_call.name }}", "arguments": {{ tool_call.arguments | tojson }}}
</tool_call>{%- endfor %}{%- endif %}{%- endfor %}"""
msgs = [{"role": "assistant", "content": None, "tool_calls": [
{"id": "call_1", "type": "function",
"function": {"name": "get_weather", "arguments": "{\"location\": \"Hobart\"}"}}]}]
env = jinja2.Environment()
env.policies["json.dumps_kwargs"] = {"sort_keys": False, "ensure_ascii": False}
def render(m): return env.from_string(TEMPLATE).render(messages=m)
norm = ct.normalize_tool_call_arguments_for_chat_template(msgs, TEMPLATE)
actual = render(norm)
expected = render([{"role": "assistant", "tool_calls": [{"function": {"name": "get_weather", "arguments": {"location": "Hobart"}}}]}])
print("expected:", repr(expected)); print("observed:", repr(actual))
if actual != expected:
print("REPRODUCED"); sys.exit(1)
Expected
expected: '\n<tool_call>\n{"name": "get_weather", "arguments": {"location": "Hobart"}}\n</tool_call>'
observed: '\n<tool_call>\n{"name": "get_weather", "arguments": {"location": "Hobart"}}\n</tool_call>'
Actual
expected: '\n<tool_call>\n{"name": "get_weather", "arguments": {"location": "Hobart"}}\n</tool_call>'
observed: '\n<tool_call>\n{"name": "get_weather", "arguments": "{\\"location\\": \\"Hobart\\"}"}\n</tool_call>'
A second check, using the real Qwen2.5 tokenizer and tokenize_sft_batch, showed the trained (label != -100) text containing "arguments": "{\"location\": \"Hobart\"}".
I did not run an actual fine-tune.
Version
OpenPipe/ART at 87a8d7c9717f (main when checked on 2026-10-28, v0.5.23; Python 3.13). Still reproduces there; first seen at 51f3fbc9e2b1 (v0.5.21).
Related
#634 and #800 taught normalize_tool_call_arguments_for_chat_template to detect templates that iterate arguments (|items, Gemma's is mapping). This issue covers the remaining shape: templates that render tool_call.arguments | tojson still receive the JSON string, so it is encoded twice.
- Lingua principale
- Python
- Stelle
- 10.9k
- Fork
- 1k
- Merge medio
- 2g 5h
- PR unite (30g)
- 38
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di OpenPipe/ART
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
gather_trajectory_groups / gather_trajectories leave sibling rollouts running after a failureForse già presa @salma2vec l’ha presa 38 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Distributed group_mean casts group ids to float32, losing precision vs non-distributed pathForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Add from_entity parameter to _experimental_fork_checkpointForse già presa @Boulea7 l’ha presa 35 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di OpenPipe/ART
Issue simili
-
bug improve content
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
opensafely/documentation#2102 ·
I maintainer di solito rispondono entro 1 giorno
-
difficulty:1 documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
MakazhanAlpamys/Soup#3533 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
onyx-dot-app/onyx#18730 ·
I maintainer di solito rispondono entro 1 giorno
-
Claiming namespace `aadml`Apertanamespace team:operations
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 65/100
EclipseFdn/open-vsx.org#16509 ·
I maintainer di solito rispondono entro 1 giorno