Repository navigation
template: str.format() with positional fields and brace escapes - #3816
Conversation
|
Thanks @atakann. Please validate the field grammar before
|
|
Thanks, fixed in 10f735b: a field is an index only when every character is a decimal digit, so |
|
Thank you @atakann. The field grammar is now checked before parseInt, so {+0}, {-0} and {0_0} are refused as Python does, while {00} renders as index zero. The refusal and parity cases are in the tests and the parity probes. The only thing left is the CHANGELOG line: please leave the branch as it is and we will place the Unreleased entry when we land it. The branch now conflicts with main; we will rebase it ourselves, keeping your commits. Nothing else is needed from you.
|
10f735b to
58e18e9
Compare
|
Thanks @atakann. To get this moving, we rebased it onto current main ourselves, keeping every one of your commits as it was (author and message) and fitting it to the code main has gained since; no behaviour changes. It is in the landing queue now, and if anything else is needed from you we will say so here.
|
…r fields are refused by name
…decimal digits ('{+0}', '{-0}', '{0_0}' are Python keyword names and are refused; '{00}' is index 0), with refusal and parity probes and the changelog line
58e18e9 to
1d5bb69
Compare
|
Thank you @atakann. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
What this changes
The chat template core refused every template that calls
str.format()("str.format() is not supported"). It now runs the positional form:{}fields in order,{N}fields by index, and the{{and}}escapes, with each argument written as Python'sstr()writes it. A keyword field ({name}), an attribute or index ({0.x}), a conversion ({!r}) and a format spec ({:>4}) are still refused, each by name. The errors Python raises (an index past the arguments, mixing automatic and manual numbering, a single{or}) fail here too. Hy4-flash's chat template builds its 22 special tokens with'<|hy_start{}|>'.format(HYTK), so it could not render.atc overlap --json(atc 0.9.6, withATC_READ_ONLY=1), run in this tree on 2026-11-18, base main8cbef9777, this head03acc6b33:complete: false(otherPullRequestsLimit,pullFilesUnavailable,pullRequestsLimit,timeLimit), 0 overlaps listed, so no conflict found, but the list is incomplete. A search of open pull requests and issues forstr.formatandformat()in templates finds none.Checks on this head
python3 tools/pr_check.py --base origin/main: 0 errors, 1 warning, the Unreleased line, since no number was given). This change carries no CHANGELOG line.zig testofzig/src/core/template/tests.zigwith thesysmodule and its dependencies: All 41 tests passed. The same forzig/src/core/template/template.zig: All 41 tests passed.ImmutableSandboxedEnvironmentin transformers' environment: the two rendering rows give<aXb>|1z|ba|{}None|xandTrue|1.5|qq, and the four error rows raise (IndexError,ValueErrorthree times). The three rows the engine refuses on purpose render in Python (1|1|'s'); the test names them as refusals.methods.zig,tests.ziggives 39 passed, 2 failed (the new test and the method-coverage property test, which now listsformatas supported); restored: 41 passed.zig build test-server-cpu --summary all: 8 of 8 steps succeeded, 1573 of 1580 tests passed, 7 skipped.zig fmt --check build.zig zig: exit 0.git diff --check: exit 0.chat_template.jinjarenders five reference prompts (default effort,no_think,max, a system prompt, a second turn) byte for byte againsttokenizer.apply_chat_templateoftencent/Hy4-flash.fmt,zig,zig-b,zig-windows,zig-macos-dev-tools,pytest,release-pathsand bothbenchmark-clientsjobs passed;host-nightly-linuxandhost-nightly-macoswere skipped.zig build test test-goldenon macOS (this Mac has no Metal Toolchain component, so the Metal kernel compiles fail before any test);zig build -Dfixed-cpu test-hoston Linux (my two Linux boxes are serving a model today; I leave it to CI and will run it here on request); everything on a GPU (no GPU code is in this pull request).Receipt
n/a for decode and prompt speed. The method runs only when a chat template calls it, and
git grep -F '.format(' -- '*.jinja' '*.j2'finds no such template on this head, so no rendered prompt in the repository changes. A template that calls it was refused at render before and now renders as jinja2 does for the positional form.Checklist