Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ jobs:
name: tensorfold-linux-appimage
path: app/release/linux/*.AppImage
if-no-files-found: error
# ~230 MB a run: kept 3 days, not GitHub's 90 (2,069 copies, 475 GB of Actions storage by 12 Nov)
retention-days: 3

mobile:
runs-on: ubuntu-24.04
Expand Down
26 changes: 21 additions & 5 deletions .github/workflows/no-gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
"$RUNNER_TEMP/pytest/bin/python" -m pytest -q -p no:cacheprovider
zig:
runs-on: ubuntu-latest
timeout-minutes: 45
timeout-minutes: 60
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
Expand Down Expand Up @@ -125,10 +125,26 @@ jobs:
exit 0
fi
python3 -m unittest discover -s tools/zig -p zig_cache_restat_test.py -v
# zig build test is the host unit tests. No GPU. The Python suite is not this check.
# A unit test that hangs fails by name after 10 minutes instead of holding the runner until the job's limit.
- name: zig build test
run: zig build -Dfixed-cpu test --test-timeout 10m
- name: Host test graph regressions
shell: bash
env:
BASE_REF: ${{ github.base_ref }}
PUSH_BASE: ${{ github.event.before }}
run: |
if [ -n "$BASE_REF" ]; then
base=$(git merge-base HEAD "origin/$BASE_REF" 2> /dev/null || true)
else
base=$(git rev-parse --verify "$PUSH_BASE^{commit}" 2> /dev/null || true)
fi
if [ -n "$base" ] && git diff --quiet "$base" HEAD -- \
build.zig zig/build/host_tests.zig tools/zig/host_tests_test.py; then
echo "Host test graph inputs are unchanged."
exit 0
fi
python3 -m unittest discover -s tools/zig -p host_tests_test.py -v
# Keep per-test timeouts while allowing the DeepSeek AOT enumeration to finish on hosted runners.
- name: zig build test-host
run: zig build -Dfixed-cpu test-host --test-timeout 20m
# The kernel contract's limits gate: every registered launch against M1-M5 and sm_80/86/89/120/121, controls red.
- name: zig build test-kernel-contract
run: zig build -Dfixed-cpu test-kernel-contract
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

## Unreleased

- CI: the app workflow keeps its Linux AppImage artifact for 3 days instead of GitHub's default 90 (#2966).

- CI: the Linux no-GPU job runs `zig build test-host`, which collects the named host tests and compile checks apart from nine reviewed exclusions (the optional xgrammar steps, the release-path check, the two large-state timing commands, which stay available for explicit runs, and four fixture and source-pin checks held back under #2031); the build graph refuses empty checks, stale exclusions and aliases that bring excluded work back (#2095, part of #2031). Thanks to @garvrao80.

- Tests: the TCP bootstrap's three-rank gather test and the multi-rank RoCE vote test join every rank they started before returning, so a failed spawn or check no longer leaves threads writing to a finished test's frame (#2963). Thanks to @Defilan.

- GLM-5.3-Flash on CUDA: a tensor-parallel abort reaches the ranks' communicator from the engine's start, once, and a start-up failure after an abort no longer destroys the communicator again; serving and replies are unchanged (#2918, part of #2560). Thanks to @laudney.

- Metal: MiniMax-M3, Spark2.5 and Llama take their NaN-aware bf16 argmax from one shared source; the compiled code is unchanged (#2949, part of #2251). Thanks to @jschmied.

- Metal: the image towers of GLM, Step-5, Gemma 4 and Qwen share one source for bf16 rounding, threadgroup sum and max, row softmax and LayerNorm statistics; the compiled code is unchanged (#2948, part of #2251). Thanks to @jschmied.

- Tests: the dashboard page's test runs on every OS, so Linux CI covers it, and no longer expects a paged prefix cache tile the page never had; `zig build test` passes on Macs again (#2946).
Expand Down
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ zig build test-cuda-host

This subset does not replace the complete `test` suite.

Native Linux no-GPU CI runs `zig build -Dfixed-cpu test-host --test-timeout 20m`.
It includes `test` and every configured `test-*` and `check-*` step, including compile-only checks.
New named checks join automatically, even when a build module registers them last.
The reviewed exclusions in `zig/build/host_tests.zig` cover the optional xgrammar tests,
the separately scheduled `check-release-paths` gate, manual large-state timing commands, and temporary failures tracked in #2031.
An empty named check, a stale exclusion, or an alias that brings excluded work back into the aggregate fails it.
When a fix lands, remove its temporary exclusion and the matching fixture entry in `tools/zig/host_tests_test.py`.
This aggregate is only registered for native Linux; other hosts keep their existing `test` and device steps.

HIP is an explicit build opt-in. Add `-Dhip=true` to enable its host tests and named HIP targets:

```sh
Expand Down
1 change: 1 addition & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pub fn build(b: *std.Build) void {
@import("zig/build/dsv41_draft.zig").steps(b);
@import("zig/build/dsv41_assets.zig").steps(b);
const target = b.standardTargetOptions(.{});
defer @import("zig/build/host_tests.zig").wire(b, target);
@import("zig/build/copy_source.zig").steps(b);
@import("zig/build/checkpoint_io_host.zig").steps(b, target);
if (target.result.os.tag == .macos) @import("zig/build/masked_values.zig").steps(b, target, .ReleaseSafe);
Expand Down
101 changes: 101 additions & 0 deletions tools/zig/host_tests_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
"""Real Zig build graphs must include new host checks and keep reviewed external requirements outside CI."""
import os
from pathlib import Path
import shutil
import subprocess
import sys
import tempfile
import unittest

ROOT = Path(__file__).resolve().parents[2]
POLICY = ROOT / "zig/build/host_tests.zig"
EXCLUDED = (
"test-grammar-budget",
"test-grammar-tools",
"check-release-paths",
"test-startup-states-timing",
"test-imprint-ops-timing",
"test-metal-residency-owners-host",
"test-qwen35-draft-frame-host",
"test-qwen35-frame-invalidation-host",
"test-gradient-serving",
)


@unittest.skipUnless(sys.platform.startswith("linux"), "test-host is a native Linux CI aggregate")
class HostTestGraphTests(unittest.TestCase):
def setUp(self):
self.zig = os.environ.get("ZIG") or shutil.which("zig")
if not self.zig:
self.skipTest("no Zig compiler found (set ZIG, or put zig on PATH)")
temporary = tempfile.TemporaryDirectory(prefix="tensorfold-host-graph-")
self.addCleanup(temporary.cleanup)
self.root = Path(temporary.name)
shutil.copyfile(POLICY, self.root / "host_tests.zig")

def build(self, extra="", omit=None, args=None):
excluded = "\n".join(
f' b.step("{name}", "external requirement").dependOn(&b.addFail("external gate ran").step);'
for name in EXCLUDED if name != omit
)
source = '''const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
defer @import("host_tests.zig").wire(b, target);
''' + excluded + "\n" + extra + "\n}\n"
(self.root / "build.zig").write_text(source)
return subprocess.run([self.zig, "build", *(args or ["test-host", "--summary", "all"])],
cwd=self.root, capture_output=True, text=True, timeout=120)

def assert_failed_with(self, result, message):
self.assertNotEqual(result.returncode, 0, result.stdout + result.stderr)
self.assertIn(message, result.stdout + result.stderr)

def test_new_named_host_test_is_included_after_the_collector_is_declared(self):
result = self.build(' b.step("test-new-host", "new host test").dependOn(&b.addFail("new host test reached").step);')
self.assert_failed_with(result, "new host test reached")

def test_existing_unnamed_unit_tests_are_preserved(self):
result = self.build(' b.step("test", "existing units").dependOn(&b.addFail("existing units reached").step);')
self.assert_failed_with(result, "existing units reached")

def test_new_compile_only_check_is_included(self):
(self.root / "broken.zig").write_text('comptime { @compileError("new compile check reached"); }\n')
result = self.build(''' const check = b.addObject(.{ .name = "compile-only", .root_module = b.createModule(.{
.root_source_file = b.path("broken.zig"), .target = target,
}) });
b.step("check-new-host", "compile only").dependOn(&check.step);''')
self.assert_failed_with(result, "new compile check reached")

def test_reviewed_external_requirements_are_not_executed(self):
result = self.build()
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
self.assertNotIn("external gate ran", result.stdout + result.stderr)

def test_alias_to_an_excluded_check_is_rejected(self):
result = self.build(''' b.step("test-alias", "alias").dependOn(&b.top_level_steps.get("test-grammar-budget").?.step);''')
self.assert_failed_with(result, "test-host reaches excluded test-grammar-budget")
self.assertNotIn("external gate ran", result.stdout + result.stderr)

def test_direct_alias_to_an_excluded_action_is_rejected(self):
result = self.build(''' const external = b.top_level_steps.get("test-grammar-tools").?;
b.step("test-action-alias", "alias").dependOn(external.step.dependencies.items[0]);''')
self.assert_failed_with(result, "test-host reaches excluded test-grammar-tools")
self.assertNotIn("external gate ran", result.stdout + result.stderr)

def test_empty_named_check_is_rejected(self):
result = self.build(' _ = b.step("test-empty", "accidentally disconnected");')
self.assert_failed_with(result, "named check test-empty has no build steps")

def test_removed_external_step_requires_review_of_its_exclusion(self):
result = self.build(omit="test-grammar-tools")
self.assert_failed_with(result, "stale exclusion test-grammar-tools")

def test_cross_target_does_not_acquire_a_native_host_aggregate(self):
result = self.build(args=["--help", "-Dtarget=x86_64-windows-gnu"])
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
self.assertNotIn("test-host", result.stdout)


if __name__ == "__main__":
unittest.main()
73 changes: 73 additions & 0 deletions zig/build/host_tests.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//! Native Linux CI collects named host tests and compile checks after every build module has registered its steps.
const std = @import("std");
const Step = std.Build.Step;
const Set = std.AutoHashMapUnmanaged(*Step, void);

const Exclusion = struct { name: []const u8, reason: []const u8 };
const exclusions = [_]Exclusion{
.{ .name = "test-grammar-budget", .reason = "Requires the optional xgrammar checkout and -Dxgrammar=DIR" },
.{ .name = "test-grammar-tools", .reason = "Requires the optional xgrammar checkout and -Dxgrammar=DIR" },
.{ .name = "check-release-paths", .reason = "The release-paths CI job checks the separately built release server" },
.{ .name = "test-startup-states-timing", .reason = "Manual disk startup timing seeds up to 100,000 states" },
.{ .name = "test-imprint-ops-timing", .reason = "Manual Imprint timing seeds up to 100,000 learned states" },
.{ .name = "test-metal-residency-owners-host", .reason = "red on main, #2031 (Qwen27 recording fixture leaves Runner.kv unset)" },
.{ .name = "test-qwen35-draft-frame-host", .reason = "red on main, #2031 (recording fixture leaves seg_fn uninitialized)" },
.{ .name = "test-qwen35-frame-invalidation-host", .reason = "red on main, #2031 (same recording fixture as test-qwen35-draft-frame-host)" },
.{ .name = "test-gradient-serving", .reason = "red on main, #2031 (Flash Next hyper-connection source pin drifted)" },
};

pub fn wire(b: *std.Build, target: std.Build.ResolvedTarget) void {
const host = b.graph.host.result;
if (host.os.tag != .linux or target.result.os.tag != host.os.tag or
target.result.cpu.arch != host.cpu.arch or target.result.abi != host.abi) return;

const all = b.step("test-host", "Native Linux host tests and compile checks with reviewed exclusions");
var rejected: std.ArrayList(*Step) = .empty;
for (b.top_level_steps.values()) |top| {
const name = top.step.name;
if (&top.step == all or !isCheck(name) or exclusion(name) != null) continue;
if (top.step.dependencies.items.len == 0)
reject(b, &rejected, b.fmt("test-host: named check {s} has no build steps", .{name}));
all.dependOn(&top.step);
}

var included: Set = .empty;
collect(b.allocator, all, &included);
for (exclusions) |entry| {
const top = b.top_level_steps.get(entry.name) orelse {
reject(b, &rejected, b.fmt("test-host: stale exclusion {s}: {s}", .{ entry.name, entry.reason }));
continue;
};
var visited: Set = .empty;
if (includedBoundary(b.allocator, &top.step, &included, &visited))
reject(b, &rejected, b.fmt("test-host reaches excluded {s}: {s}", .{ entry.name, entry.reason }));
}
if (rejected.items.len != 0) all.dependencies = rejected;
}

fn reject(b: *std.Build, rejected: *std.ArrayList(*Step), message: []const u8) void {
rejected.append(b.allocator, &b.addFail(message).step) catch @panic("OOM");
}

fn isCheck(name: []const u8) bool {
return std.mem.eql(u8, name, "test") or std.mem.startsWith(u8, name, "test-") or
std.mem.startsWith(u8, name, "check-");
}

fn exclusion(name: []const u8) ?Exclusion {
for (exclusions) |entry| if (std.mem.eql(u8, name, entry.name)) return entry;
return null;
}

fn collect(a: std.mem.Allocator, root: *Step, seen: *Set) void {
if ((seen.getOrPut(a, root) catch @panic("OOM")).found_existing) return;
for (root.dependencies.items) |dep| collect(a, dep, seen);
}

fn includedBoundary(a: std.mem.Allocator, root: *Step, included: *const Set, seen: *Set) bool {
if ((seen.getOrPut(a, root) catch @panic("OOM")).found_existing) return false;
if (included.contains(root)) return true;
if (root.tag != .top_level) return false;
for (root.dependencies.items) |dep| if (includedBoundary(a, dep, included, seen)) return true;
return false;
}
41 changes: 41 additions & 0 deletions zig/kernels/metal/core/bf16_argmax.metal
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// The greedy draw for decode glue: a bf16 logits row's argmax, NaN first, ties to the lower id (MLX argmax).
#include <metal_stdlib>
using namespace metal;

// The better of two (value, id) candidates: NaN first (lower id among NaNs), then the larger value, then the lower id.
inline bool tf_bf16_argmax_better(float a, uint ia, float b, uint ib) {
if (isnan(a)) return !isnan(b) || ia < ib;
if (isnan(b)) return false;
return a > b || (a == b && ia < ib);
}

// Kernel NAME: logits [vocab] bf16 to its argmax in ids[0], one threadgroup of 1024.
#define TF_BF16_ARGMAX(NAME) \
[[kernel]] void NAME(const device bfloat* logits [[buffer(0)]], device uint* ids [[buffer(1)]], \
constant uint& vocab [[buffer(2)]], uint t [[thread_position_in_threadgroup]], \
uint lane [[thread_index_in_simdgroup]], uint sg [[simdgroup_index_in_threadgroup]]) { \
threadgroup float vals[32]; \
threadgroup uint idxs[32]; \
float best = -INFINITY; \
uint at = 0xffffffffu; \
for (uint i = t; i < vocab; i += 1024) { \
const float v = float(logits[i]); \
if (tf_bf16_argmax_better(v, i, best, at)) { best = v; at = i; } \
} \
for (ushort d = 16; d > 0; d >>= 1) { \
const float ov = simd_shuffle_xor(best, d); \
const uint oi = simd_shuffle_xor(at, d); \
if (tf_bf16_argmax_better(ov, oi, best, at)) { best = ov; at = oi; } \
} \
if (lane == 0) { vals[sg] = best; idxs[sg] = at; } \
threadgroup_barrier(mem_flags::mem_threadgroup); \
if (sg != 0) return; \
best = vals[lane]; \
at = idxs[lane]; \
for (ushort d = 16; d > 0; d >>= 1) { \
const float ov = simd_shuffle_xor(best, d); \
const uint oi = simd_shuffle_xor(at, d); \
if (tf_bf16_argmax_better(ov, oi, best, at)) { best = ov; at = oi; } \
} \
if (lane == 0) ids[0] = at; \
}
37 changes: 2 additions & 35 deletions zig/kernels/metal/llama/glue.metal
Original file line number Diff line number Diff line change
Expand Up @@ -230,41 +230,8 @@ struct ll_vec_args { uint rows, pos, heads, groups, blocks, chunk, first; float
for (uint j = 0; j < PER; ++j) O[(row * a.heads + head) * DH + PER * sg + j] = bfloat(acc[j]);
}

inline bool ll_better(float a, uint ia, float b, uint ib) {
if (isnan(a)) return !isnan(b) || ia < ib;
if (isnan(b)) return false;
return a > b || (a == b && ia < ib);
}

// The greedy draw (nemotron_glue's tf_argmax_bf16): a bf16 logits row's argmax, ties to the lower id, into ids[0].
[[kernel]] void ll_argmax(const device bfloat* logits [[buffer(0)]], device uint* ids [[buffer(1)]],
constant uint& vocab [[buffer(2)]], uint t [[thread_position_in_threadgroup]],
uint lane [[thread_index_in_simdgroup]], uint sg [[simdgroup_index_in_threadgroup]]) {
threadgroup float vals[32];
threadgroup uint idxs[32];
float best = -INFINITY;
uint at = 0xffffffffu;
for (uint i = t; i < vocab; i += 1024) {
const float v = float(logits[i]);
if (ll_better(v, i, best, at)) { best = v; at = i; }
}
for (ushort d = 16; d > 0; d >>= 1) {
const float ov = simd_shuffle_xor(best, d);
const uint oi = simd_shuffle_xor(at, d);
if (ll_better(ov, oi, best, at)) { best = ov; at = oi; }
}
if (lane == 0) { vals[sg] = best; idxs[sg] = at; }
threadgroup_barrier(mem_flags::mem_threadgroup);
if (sg != 0) return;
best = vals[lane];
at = idxs[lane];
for (ushort d = 16; d > 0; d >>= 1) {
const float ov = simd_shuffle_xor(best, d);
const uint oi = simd_shuffle_xor(at, d);
if (ll_better(ov, oi, best, at)) { best = ov; at = oi; }
}
if (lane == 0) ids[0] = at;
}
// The greedy draw: a bf16 logits row's argmax into ids[0] (core/bf16_argmax.metal).
TF_BF16_ARGMAX(ll_argmax)

// The bf16 linear rows ll_matvec_1 to ll_matvec_32 (core/bf16_matvec.metal).
TF_BF16_MATVECS(ll)
Expand Down
Loading
Loading