Skip to content

fix(cluster): the leader's draw refuses non-finite logits - #658

Merged
ashhart merged 1 commit into
ashhart:mainfrom
chaog992:cluster-draw-nonfinite
Oct 12, 2026
Merged

ashhart merged 1 commit into
ashhart:mainfrom
chaog992:cluster-draw-nonfinite

Conversation

@chaog992

Copy link
Copy Markdown
Contributor

What this changes

Leader.draw in zig/src/cluster/backend.zig hands a sampled row's logits straight to lanes.sampling.choose. Its sort comparator, byValueThenId, stops being a strict weak order once a value is NaN, and std.mem.sort can then compute an out-of-range index inside its block sort. Without this change, the new test panics there in Debug and ReleaseSafe. Other rows with a NaN or an infinity, greedy or sampled, still draw a token, sometimes the id of a NaN logit.

draw now refuses such a row with error.NonfiniteLogits before either path. serial_host.choose and qwen27's argmax already refuse these rows with the same error, and qwen3_5's draw with NonfiniteQwenLogits. Finite rows draw as before.

Nothing shipped reaches this yet: only the toy cluster in the tests builds a Leader, and the cluster commands stop before any round. It matters once a Metal or CUDA backend implements cluster.backend.Shard.

Receipt

  • Environment: base d5126573, fix a6823950, Zig 0.17.0, Linux x86_64 under WSL2. No GPU or model is needed.
  • Test: backend_test.zig gets one test, run for NaN, +inf and -inf, greedy and with the file's hot sampling. Each case expects error.NonfiniteLogits from two kinds of row: a 2048-logit row with every other logit bad (the sort's failing path needs 1024 or more), and rows with one bad logit at either end. A row of finite extremes (±floatMax, a subnormal, -0.0) draws as before.
  • Cluster tests: CI's zig build test never builds the cluster module, and test-cluster is macOS-only, so I ran the tests directly:
    zig test -lc --dep lanes --dep fabric -Mroot=zig/src/cluster/cluster.zig -Mlanes=zig/src/core/lanes/lanes.zig -Mfabric=zig/src/fabric/fabric.zig
    
    • With this change: 74 passed, 6 skipped and 2 failed. The base gives 73, 6 and 2.
    • The counts are the same with -O ReleaseSafe or -O ReleaseFast before -Mroot.
    • The two failures happen on main too: the fixture names its nodes studio1 to studio4, and the assertions look for node-d.
    • The skipped tests need TF_K3_DIR, TF_CLUSTER_PROBES or TF_CLUSTER_REPORT.
  • Failing receipt: the trace below is the new test on the unfixed backend.zig, in Debug. ReleaseSafe gives the same panic with inlined frames. ReleaseFast, the build default, segfaults.
    backend_test.test.a draw refuses a row holding a NaN or an infinity, greedy or sampled; finite extremes draw as before...thread … panic: integer overflow
    lib/std/sort/block.zig:520:73: … in block__func_1004 (std.zig)
    lib/std/mem.zig:671:19: … in sort__func_983 (std.zig)
    zig/src/core/lanes/sampling.zig:90:17: … in choose (lanes.zig)
    zig/src/cluster/backend.zig:146:54: … in draw (cluster.zig)
    
  • Other gates:
    • python3 tools/zig/lean_check.py reports 1169 files and 534 problems on the base, and the same list with this change.
    • zig fmt --check build.zig zig passes.
    • zig build test passes 39/39 steps and 449/449 tests.
    • The cluster tests compile for aarch64-macos (-mcpu apple_m1 --test-no-exec). This is a compile check only.
  • Not run: zig build test-cluster, since I have no Mac, and any served model.

choose's sort has no consistent order once a logit is NaN; greedy rows and infinities are refused too, as in serial_host's choose and qwen27's argmax.
@ashhart
ashhart merged commit ef1de9c into ashhart:main Oct 12, 2026
2 checks passed
@ashhart

ashhart commented Oct 12, 2026

Copy link
Copy Markdown
Owner

Thank you, @chaog992. A clear find, and the test pins it down exactly. Your commit a68239508 landed in 1.0.8 under your name, so GitHub shows this PR as merged.

We ran the parts you couldn't, on a Mac:

  • With the check taken out, your test panics with an integer overflow in std.sort's block sort, called from draw, as in your trace. With it, the test passes.
  • zig build test-cluster gives 74 passed, 7 skipped and 2 failed with your change, against 73, 7 and 2 before. The two failures are the fixture's node names you pointed out, and they fail on main too.

Your direct zig test line on Linux gives 74 passed, 6 skipped and 2 failed, against 73, 6 and 2 before, the same counts you reported.

We added a CHANGELOG line saying no served model reaches the cluster's draw yet, so nobody reads it as a live crash fix. When a Metal or CUDA shard lands, this check will already be there.

BobClawblaw pushed a commit to BobClawblaw/TensorFold that referenced this pull request Oct 12, 2026
BobClawblaw pushed a commit to BobClawblaw/TensorFold that referenced this pull request Oct 12, 2026
core/serial_host.zig served one request at a time through a driver of callbacks. Its last engine was the 27B's
single-stream host, qwen27_host.zig, which no server had opened since 1.0.6 and ashhart#659 removed with the drafter's
batch path, so only its own tests used it. It goes with them: serial_host_test.zig, serial_batch_test.zig and
cache_mode_host_test.zig, 1,113 lines in all and 20 tests, every one in the binary rooted at engine_api.zig. No
build step, tool or doc named it, and its choose()/Logits sampling helper had no caller either. cache_modes keeps
its callers: Engine.submit validates spans and the 27B's host keeps reply states.

Three mentions follow it: the rewind test's comment names the 27B's host, the 27B's slot prefill comment drops its
pointer to the serial host's rule, and ashhart#658's CHANGELOG line compares with Qwen's draws alone.
@chaog992
chaog992 deleted the cluster-draw-nonfinite branch October 12, 2026 14:34
@ashhart ashhart mentioned this pull request Oct 14, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
ashhart#658 landed above as 2e6a3f511 (the author's commit, rebased onto this candidate). This keeps the PR's own head commit in the history, with no change to the tree.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
core/serial_host.zig served one request at a time through a driver of callbacks. Its last engine was the 27B's
single-stream host, qwen27_host.zig, which no server had opened since 1.0.6 and ashhart#659 removed with the drafter's
batch path, so only its own tests used it. It goes with them: serial_host_test.zig, serial_batch_test.zig and
cache_mode_host_test.zig, 1,113 lines in all and 20 tests, every one in the binary rooted at engine_api.zig. No
build step, tool or doc named it, and its choose()/Logits sampling helper had no caller either. cache_modes keeps
its callers: Engine.submit validates spans and the 27B's host keeps reply states.

Three mentions follow it: the rewind test's comment names the 27B's host, the 27B's slot prefill comment drops its
pointer to the serial host's rule, and ashhart#658's CHANGELOG line compares with Qwen's draws alone.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants