Repository navigation
template: add the float filter - #3577
Merged
Merged
Conversation
4 tasks done
1 task done
Jinja's float(value, default=0.0) for numbers, booleans and numeric text. Anything else gives the default, an undefined value raises, and an argument Jinja does not have is an error, as in Jinja. Inkling 2's chat template reads its thinking effort through it.
ashhart
force-pushed
the
template-float-filter-3476
branch
from
November 17, 2026 02:56
72a2707 to
3aa9a39
Compare
Owner
|
Thank you @Nipale-ai. 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. |
1 task done
Owner
|
Thanks @Nipale-ai! This is in TensorFold 1.2.10, out now: https://github.com/ashhart/TensorFold/releases/tag/v1.2.10
|
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
The chat template compiler refused every template that uses Jinja's
floatfilter ("template uses unsupported filter or test 'float'"). It now accepts it as Jinja defines it,float(value, default=0.0): numbers, booleans and ASCII numeric text convert, anything else givesdefault, an undefined value raises as it does in Jinja, and an argument Jinja does not have is an error. Text is read as ASCII only: a non-ASCII digit or a Unicode space givesdefault, where Python reads it. Inkling 2 Small's chat template reads its thinking effort through| float.atc overlap --json(atc 0.9.6, withATC_READ_ONLY=1), run in this tree on 2026-11-16 at 13:21 CET, base maine86a0bed1(main had moved on frome2375f36a, the base of this head;git merge-treeof this head withe86a0bed1and with the later9e00f2cb5merges cleanly), this head72a2707ed:complete: false(otherPullRequestsLimit,pullFilesUnavailable,pullRequestsLimit,timeLimit), no overlap with any other pull request listed, hence no conflict found, but the list is incomplete (the limits above). The same result on three runs. It also lists the other worktrees of this clone: 3 of the 8 listed conflict with this head. These are earlier drafts of this same change (the firstfloatbranch, the first host-package branch and the clone's Inkling 2 draft branch; matched by their file counts and checked withgit merge-treeagainst this head), not other pull requests. They collide with this head inCHANGELOG.md,zig/src/core/template/filters.zigandzig/src/core/template/tests.zig(and intools/zig/template_parity.pyfor two of them).Checks on this head
python3 tools/zig/lean_check.py, on the base and on this head: 221 and 221 problems, 0 new (CI's procedure with a base worktree andtools/zig/lean_new.py).zig test --dep sys -Mroot=zig/src/core/template/tests.zig -Msys=zig/src/platform/sys.zig -lc: All 40 tests passed.zig test --dep sys -Mroot=zig/src/core/template/template.zig -Msys=zig/src/platform/sys.zig -lc(includesprovenance_test.zig, whose filter count is now 31): All 40 tests passed.floatrow oftests.zig(6 rows) rendered withjinja2.Environment().from_string(...).render()gives the expected string in the file, or raises where the file expects an error (0 differ). The error probes raiseTypeErrorforfloat(2, 3)andfloat(boolean=true)andUndefinedErrorforundefined_name|float.'+ U+0663 +'|floatand a text of U+00A0 and7to0.0|0.0here, and3.0|7.0in jinja2 3.1.6.tests.zig, each turned red and back:filters.zigof main (nofloat): 38 passed, 2 failed; thebooleanparameter accepted: 39 passed, 1 failed; the undefined-value check removed: 39 passed, 1 failed.zig fmt --check build.zig zig: exit 0.git diff --check origin/main..HEAD: exit 0.python3 tools/pr_check.py --base origin/main: 0 errors, 1 warning (--pr NUMBERwas not given, so the Unreleased line is not checked). This change carries no CHANGELOG line; given a pull request number,pr_checkreports that as a warning, as it did for qwen3_5 cuda: the dense family has a rank plan, host only; it moves no tokens #3383 (tools/pr_check.pylines 90 and 91).python3 tools/zig/cuda_common_check.py && python3 tools/zig/cuda_fragment_check.pyandcuda_common_check_test.py: 51 copies, 0 violations; 2 fragments, 0 misses; 9 tests OK.python3 -m unittest discover -s tools/zig -p host_tests_test.py: 13 tests OK.-p build_options_test.py: 5 tests OK.-p flashnext_batch_serve_test.py: 8 tests OK.zig build -Dfixed-cpu test-host --test-timeout 20mwith a fresh local build cache directory, first run: 2099 of 2105 steps succeeded (1 failed), 19846 of 19978 tests passed, 131 skipped, 1 failed. The failed test isbringup_test("two ranks settle on the real clock and agree on one plan and view; a goodbye ends the other's watch by name";zig/src/cluster/bringup_test.zig:97,expectEqual(x.view, y.view): expected 5693255286640881692, found 3698603761711287178). This pull request changes no file underzig/src/clusterorzig/src/platform, and the sametest-hostrun on main e2375f3 succeeded (below). After the failure, in this order: a repeat in the first directory: 2105 of 2105 steps succeeded (test steps whose inputs had not changed came from the cache and the others ran again, among them the one that had failed, which passed with 37 tests and 1 skipped; 1940 of 1981 tests counted, 41 skipped). A second repeat there: 2105 of 2105 steps succeeded. Then two attempts that are not counted: one failed with "No space left on device" errors in its cache directory, and one was started with umask 0002 by my mistake and failed incli_config_test, which refuses a config file that other users can write (with umask 0002 the same test fails on main e2375f3 too, with umask 022 it passes on both). Then atest-hostrun in another fresh local cache directory: 2105 of 2105 steps succeeded, 19846 of 19978 tests passed, 132 skipped. The test program of the failed step (test-cluster-membership-host) alone passed 25 of 25 runs one at a time. Run 64 at a time, 300 runs each, it failed 21 times on main e2375f3 (14 at line 97, the same line, and 7 at line 133 of the same file) and 17 times on this head (14 and 3). So the test also fails on main when the box is loaded; it uses the real clock. I did not look further into its code.zig build test-cuda-host: 410 of 410 steps succeeded, 6885 of 6918 tests passed, 33 skipped.test-kernel-contract: 34 of 34 steps, 205 tests passed.test-golden: 5 of 5 steps.fuzz-cortheon: 3 of 3 steps. Plainzig build: 33 of 33 steps.zig build -Dfixed-cpu test --test-timeout 10m: 694 of 694 steps, 407 of 420 tests passed, 13 skipped.test-qwen-serving-host,test-server-securityandtest-pull-securityrun inside thetest-hostaggregate and were not run on their own as separate commands.test-gradient-servingis excluded fromtest-hoston main (red on main, CI never reaches 246 of the 393 named test steps, and nine of them fail on main #2031) and was not run. On main e2375f3 the same runs (a fresh local cache directory, the same commands):test-host2105 of 2105 steps succeeded, 19847 of 19978 tests passed, 131 skipped;test-cuda-host410 of 410 steps succeeded, 6885 of 6918 tests passed, 33 skipped;test-kernel-contract34 of 34 steps, 205 tests;test-golden5 of 5 steps;fuzz-cortheon3 of 3 steps; plainzig build33 of 33 steps;zig build -Dfixed-cpu test694 of 694 steps, 407 of 420 tests passed, 13 skipped.python -m pytest -q -p no:cacheproviderfrom the root (run on the Inkling head, which contains this change): stops at collection with an ImportError, on main e2375f3 as well (zig/tests/qwen3_metal/test_reference.pyimportsFfromreferenceand getstools/lfm3/reference.py). With--ignore=zig/tests/qwen3_metal: 555 passed, 56 skipped; main e2375f3 with the same option: 555 passed, 56 skipped.xcrun metal --version: Apple metal version 32023.922), on this head (72a2707); everyzig buildbelow with--summary alland with one shared local build cache directory (--cache-dir).zig fmt --check build.zig zig: exit 0.zig build test test-golden -Dcpu=apple_m1: exit 0, 874 of 874 steps succeeded, 14376 of 14494 tests passed, 118 skipped; thetest-goldenstep succeeded.zig build dev-tools -Doptimize=Debug: 268 of 268 steps succeeded.zig build -Dfixed-cpu dev-tools: 268 of 268 steps succeeded.zig build -Dfixed-cpu check-release-paths: 68 of 68 steps succeeded.zig build native -Dcpu=apple_m1 -Dversion=1.0.0: 66 of 66 steps succeeded.zig testoftests.zigand oftemplate.zig(the two commands above plus-mcpu=apple_m1): All 40 tests passed each.tools/zig/nfkd_tables.py --check: exit 0;test_nfkd_tables.pywith Python 3.14: 5 tests OK. In thedev-tools,check-release-pathsandnativeruns, steps whose inputs had not changed show as cached in their logs and were not run again.test-hostrun and the later fresh one started from empty local cache directories (a new one each); the global cache is shared by all runs.git range-diff 08f1de594..6760fa996 e2375f36a..72a2707ed(the earlier head against this one) marks the one commit changed (!); the only difference is that its change toCHANGELOG.mdis gone, and the four other files have the same blobs (4 of 4). Thezig testruns, the jinja2 probes, the scratch probe and the planted controls above ran on this head.fmt,zig,zig-b,zig-windows,zig-macos-dev-tools,pytest,release-pathsand bothbenchmark-clientsjobs passed;host-nightly-linuxandhost-nightly-macoswere skipped.test-gradient-serving, which main excludes fromtest-host(CI never reaches 246 of the 393 named test steps, and nine of them fail on main #2031); thecheck-release-pathsbuild step on the Linux box, which main also excludes fromtest-host(the tool itself runs insidetest-release-directory-host, which succeeded intest-host; the build step ran on the Mac and succeeded there, 68 of 68 steps); a model or checkpoint check on Metal (none was run; this pull request changes no Metal code); the Windows job.Receipt
n/a for decode and prompt speed. The filter runs only when a chat template calls it, and
git grep -E '\|[[:space:]]*float\b'over*.jinja,*.j2,*.json,*.txtand*.mdfinds no such template on this head, so no rendered prompt in the repository changes. A template that uses it was refused at load before and now renders as jinja2 3.1.6 does (the probes above).test-goldenover the frozen server corpus passed: 5 of 5 steps (it records known differences separately).Checklist