SFT double-encodes tool-call arguments for chat templates that apply `| tojson` (Qwen2.5, Llama 3.2)
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 50/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- python
- Lĩnh vực
- machine-learning
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 10.9k
- Fork
- 1k
- Merge trung bình
- 2 ngày 5 giờ
- Pull request đã merge (30 ngày)
- 38
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của OpenPipe/ART
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
gather_trajectory_groups / gather_trajectories leave sibling rollouts running after a failureCó thể đã có người làm @salma2vec đã nhận 38 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Distributed group_mean casts group ids to float32, losing precision vs non-distributed pathCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Add from_entity parameter to _experimental_fork_checkpointCó thể đã có người làm @Boulea7 đã nhận 35 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
bug improve content
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
opensafely/documentation#2102 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
difficulty:1 documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
MakazhanAlpamys/Soup#3533 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
onyx-dot-app/onyx#18730 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Claiming namespace `aadml`Đang mởnamespace team:operations
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
EclipseFdn/open-vsx.org#16509 ·
Maintainer thường phản hồi trong vòng 1 ngày