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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

## Unreleased

- Qwen3.8-27B on Metal serves Q4_K_M and Q8_0 GGUF files using their metadata, full stop set, tokenizer and chat template, exact FP32 affine tables and an explicit DeltaNet head-layout conversion; the text path matches the MLX assets on 834 varied strings. Every projection takes the generic weight-only kernel, so a Q4_K_M file decodes about 13 times slower than the MLX 4-bit checkpoint (3.8 against 48.7 tok/s at one stream on an M5 Ultra). GGUF's FP32-gain residual norm is its own kernel source, so saved prompt states on Metal are recomputed once after upgrading, since their identity covers the kernel sources (#2078, part of #1920).
- CUDA EXL3 grouped experts launch and size their storage at the caller's tile and pair count, so decode no longer launches three quarters of its grid empty, and Qwen3.6-35B-A3B EXL3 sizes its grouped storage for 36,864 pair rows instead of 163,904 (about 3 GB less); outputs are bit-equal (#2843, for #2823).

- CUDA: dots.mocr's text decoder serves text prompts on a GB10 from the publisher's BF16 weights, on a new shared engine for dense GQA decoders (`zig/src/cuda_dense/`); `--vision`, prompt caching and fp8 caches are refused by name, and served CUDA checkpoints are unchanged (#2673, part of #1927). Thanks to @laudney.
Expand Down
76 changes: 68 additions & 8 deletions docs/recipes/qwen3.8-27b.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ window into its history as it reads it, so the commit and publication kernels go
four simdgroups (each lane's squares still summed in order); 1.19 ms a token where 1.75 (`QWEN27_STEPCHECK` checks
the state, history and logits bytes against the general path).

## GGUF host adapter
## GGUF on Metal

`families/qwen27/gguf.zig` prepares the dense family's GGUF metadata and tensor identities on the host (#1920).
It accepts the observed qwen35 architecture, refuses the unproven qwen3 alias, uses core's typed views
Expand All @@ -113,21 +113,51 @@ original bytes. GGUF matrices reverse dimension labels only; the convolution is
The host fixture checks every repacked value against independent source decoding for all ten core formats.
Core's documented signed-zero cancellation exception still applies; this does not extend its exactness claim.

Destination names are identities for future native loading, not ready-to-serve tensors. The `ssm_a` entry has an
explicit negative-exponential-decay role: its bytes are not relabelled as a usable logarithmic `A_log`. GDN head
ordering still needs checkpoint qualification. No coefficient is narrowed or group merged.
The native GGUF loader copies repeat-major DeltaNet value heads to the engine's key-major head order.
It moves QKV's value rows, Z/A/B rows, output columns, convolution taps, decay and time bias together;
Q/K rows and attention Q/gate rows retain their order. Packed codes and FP32 coefficient bits stay intact.
The `ssm_a` role is negative exponential decay: the loader explicitly computes `log(-ssm_a)` for the existing
DeltaNet kernel's logarithmic input. It refuses nonfinite or nonnegative decay values.

The final, input, post-attention, gated-linear, Q and K norm tensors carry the explicit `rms_gain` role.
Sixteen values per class from both GGUF variants match the supplied MLX BF16 gains after rounding to BF16.
Both checkpoints therefore store effective multiplicative gains here: the adapter neither adds nor subtracts one.
It preserves the GGUF F32 values, including the bits beyond the MLX BF16 representation. The paired sample fixture
checks all 96 values and the borrowed byte identities; this comparison does not qualify the remaining weights.
Existing Metal paths still need FP32 metadata and group-16 qualification, tokenizer/chat-template integration,
prepared-cache integration and real-model token/performance gates. GGUF model arguments receive a coming-later
refusal; the adapter does not enable end-to-end GGUF inference.
Serve a Q4_K_M or Q8_0 file directly, or a directory containing exactly one GGUF file and no `config.json`:

```sh
zig build test-qwen27-gguf-host test-gguf-host -j1 --summary all
tensorfold-native serve model.gguf --no-drafts
tensorfold-native serve gguf-directory --no-drafts
```

Other source quantizations and missing tokenizer keys are refused by name. Text comes from the GGUF vocabulary,
merges, token kinds, BOS/EOS settings and chat template; no tokenizer sidecar is read. The supported `qwen35`
pre-tokenizer selects NFC and the family's byte-level BPE splitting rule. Native checkpoint directories retain
their existing loader and operators. GGUF currently refuses `--drafter`, `--vision`, `--slide`, tensor parallelism,
`--speed-up` and disk prompt learning.

FP32 coefficient tables feed the existing shared weight-only projection. Six-bit codes are widened losslessly
to eight-bit codes in groups of 16; four- and eight-bit groups of 32 stay intact. Existing kernels handle embedding,
activation narrowing, norms and fused output copies. No shader source or entry point changes.

`tf-qwen27-gguf-check MODEL.gguf` checks the first layer's eight matrix classes against core's independent block
decoder, including every decoded weight bit and every fixed-input binary64 projection row after layout conversion.
On a Mac, `tf-qwen27-gguf-reference MODEL.gguf CASES.json` decodes original source weights independently and runs
binary64 CPU arithmetic with the family's BF16 activation rounding points. Its three cases contain `id`,
`prompt_ids` from `/tokenize` and `device_tokens` from greedy serving with `return_token_ids`; it compares eight
tokens per case. The CPU reference retains source head order and does not use native repacks or layout helpers.
Its decoded F32 cache is capped at 112 GiB, so run it separately from the server on a machine with sufficient RAM.
On M3 Ultra, the observed Q4_K_M file matches all 24 CPU reference tokens across three fixed prompts
(21, 25 and 24 rendered tokens), each served greedily for 32 tokens with thinking and drafts off and EOS ignored.
Observed startup/physical process footprint at context 1,024, one stream and prompt cache off: Q4_K_M 61.99 s /
27.63 GiB; Q8_0 79.33 s / 35.78 GiB. File-cache state was uncontrolled and the files had been read before.
The comparison uses the same decoded GGUF weights; equality with a separately quantized MLX checkpoint is not claimed.
Additional chips, drafted operation and feature combinations require their own checkpoint receipts.

```sh
zig build test-qwen27-gguf-host test-gguf-host test-gguf-text-host test-qwen27-gguf-bindings-host -j1
zig build tf-qwen27-gguf-check tf-qwen27-gguf-reference test-qwen27-gguf-reference-host -j1
```

## MLX
Expand Down Expand Up @@ -444,3 +474,33 @@ Endpoint, rewind and shared states have priority within the same byte and slot c
is published in `tensorfold:prompt_cache_states` and `tensorfold:prompt_cache_bytes`; restored tokens also count
in `tensorfold:prompt_tokens_cached_total`. Synthetic host checks cover the two-request pattern and exact
output. Real-model parity and TTFT for this state still need the Metal gate.

### GGUF text parity and current projection speed

Q4_K_M and Q8_0 GGUFs both use the generic weight-only projection for their affine linear products. Q4_K tensors use four-bit
codes with groups of 32; Q6_K codes widen losslessly to eight bits with groups of 16; Q8_0 uses eight-bit codes
with groups of 32. All retain their F32 scales and biases. These formats do not take the MLX projection kernels.
On the M3 Ultra with 256 GiB, Q4_K_M decoded at about 2.8 tok/s on the three short greedy 32-token requests in
the GGUF receipt. That is the current generic path's observed speed, not a speed improvement or a Q8_0 decode
measurement. Q8_0 uses the same generic path; its generation speed remains unmeasured.
On an M5 Ultra, Q4_K_M decoded at 3.8 tok/s at one stream and 3.9 to 4.0 tok/s across four, against 48.7
and 182 tok/s for the MLX 4-bit checkpoint on the same machine: about 13 times slower at one stream, with no gain
from more streams. The generic kernel repeats its weight work for each row, which fits that; it is not profiled.

The full Qwen stop set keeps the declared EOS and the end-of-text control, in that order. Both model config and
server text expose the same set. An ordinary end-of-text spelling refuses rather than becoming a stop. Adding
an EOS in tokenization appends only the primary EOS. The six FIM/repository/file added tokens remain ordinary
for skip-special decoding, and GGUF unused slots are absent from the tokenizer vocabulary.

`zig build gguf-tokenizer-compare-host` builds a CPU-only check over the actual GGUF and MLX text providers:

```sh
tf-gguf-tokenizer-compare model.gguf mlx-checkpoint
```

The tool maps the GGUF read-only and reads its metadata, without repacking weights or opening a device. Its default corpus is
the 834 varied strings used by the earlier tokenizer check. An optional third argument supplies another JSON
case array. It checks every vocabulary slot, added-token flags, both stop sets, full and masked encodings,
decoding with both skip-special settings, and one real rendered chat prompt's bytes and token IDs. Its receipt
reports each comparison class separately. Both providers use the native tokenizer and template engines with
independently loaded assets. Model inference and other GPUs keep their own qualification checks.
25 changes: 25 additions & 0 deletions zig/build/gguf_host.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
const std = @import("std");

pub fn steps(b: *std.Build, all: *std.Build.Step) void {
const admission = b.addRunArtifact(b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("zig/src/core/weight_only.zig"), .target = b.graph.host, .optimize = .debug }) }));
b.step("test-weight-only-admission-host", "Generic/CUDA group refusals and the isolated Metal group16 admission").dependOn(&admission.step);
all.dependOn(&admission.step);
const host = b.step("test-gguf-host", "Checked GGUF containers and typed metadata without a GPU");
for ([_]std.builtin.OptimizeMode{ .debug, .fast }) |mode| {
const m = b.createModule(.{ .root_source_file = b.path("zig/src/core/gguf.zig"), .target = b.graph.host, .optimize = mode, .link_libc = true });
Expand All @@ -13,6 +16,23 @@ pub fn steps(b: *std.Build, all: *std.Build.Step) void {
}
}
all.dependOn(host);
const proof_core = b.createModule(.{ .root_source_file = b.path("zig/qwen27_gguf_core.zig"), .target = b.graph.host, .optimize = .ReleaseFast });
const proof_family = b.createModule(.{ .root_source_file = b.path("zig/src/families/qwen27/gguf_projection.zig"), .target = b.graph.host, .optimize = .ReleaseFast, .imports = &.{.{ .name = "core", .module = proof_core }} });
const proof_root = b.createModule(.{ .root_source_file = b.path("zig/tools/qwen27_gguf_check.zig"), .target = b.graph.host, .optimize = .ReleaseFast, .link_libc = true, .imports = &.{ .{ .name = "core", .module = proof_core }, .{ .name = "preparation", .module = proof_family } } });
const proof = b.addExecutable(.{ .name = "tf-qwen27-gguf-check", .root_module = proof_root });
b.step("tf-qwen27-gguf-check", "Check decoded first-layer GGUF projections against binary64 without a GPU").dependOn(&b.addInstallArtifact(proof, .{}).step);
if (b.graph.host.result.os.tag == .macos) {
const reference = b.createModule(.{ .root_source_file = b.path("zig/src/families/qwen27/gguf_cpu_reference.zig"), .target = b.graph.host, .optimize = .ReleaseFast, .imports = &.{.{ .name = "core", .module = proof_core }} });
const reference_root = b.createModule(.{ .root_source_file = b.path("zig/tools/qwen27_gguf_reference.zig"), .target = b.graph.host, .optimize = .ReleaseFast, .link_libc = true, .imports = &.{.{ .name = "reference", .module = reference }} });
reference_root.linkFramework("Accelerate", .{});
reference.linkFramework("Accelerate", .{});
const ref_test = b.addTest(.{ .root_module = reference });
const reference_checks = b.addRunArtifact(ref_test);
b.step("test-qwen27-gguf-reference-host", "Binary64 CPU projection and activation checks without a GPU").dependOn(&reference_checks.step);
all.dependOn(&reference_checks.step);
const ref_exe = b.addExecutable(.{ .name = "tf-qwen27-gguf-reference", .root_module = reference_root });
b.step("tf-qwen27-gguf-reference", "Binary64 CPU reference over decoded GGUF weights and fixed prompt ids").dependOn(&b.addInstallArtifact(ref_exe, .{}).step);
}
const family = b.step("test-qwen27-gguf-host", "Qwen27 GGUF metadata, names and exact affine preparation without a GPU");
for ([_]std.builtin.OptimizeMode{ .debug, .fast }) |mode| {
const core = b.createModule(.{ .root_source_file = b.path("zig/qwen27_gguf_core.zig"), .target = b.graph.host, .optimize = mode });
Expand All @@ -21,6 +41,11 @@ pub fn steps(b: *std.Build, all: *std.Build.Step) void {
family.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = root, .filters = &.{"Qwen27 GGUF:"} })).step);
}
all.dependOn(family);
const text_lanes = b.createModule(.{ .root_source_file = b.path("zig/src/core/lanes/lanes.zig"), .target = b.graph.host, .optimize = .fast, .link_libc = true });
const compare_root = @import("server.zig").plain(b, "zig/gguf_tokenizer_compare.zig", b.graph.host, .fast, text_lanes);
compare_root.addImport("core", compare_root);
const compare = b.addExecutable(.{ .name = "tf-gguf-tokenizer-compare", .root_module = compare_root });
b.step("gguf-tokenizer-compare-host", "Compare actual GGUF and MLX vocabulary, encoding, decoding, stops and rendered chat without a GPU").dependOn(&b.addInstallArtifact(compare, .{}).step);
const linux = b.createModule(.{ .root_source_file = b.path("zig/src/core/gguf.zig"), .target = b.resolveTargetQuery(.{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .gnu }), .optimize = .Debug, .link_libc = true });
b.step("test-gguf-linux-compile", "Compile GGUF host checks for Linux aarch64").dependOn(&b.addTest(.{ .root_module = linux }).step);
}
2 changes: 1 addition & 1 deletion zig/build/qwen27.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub const Shared = struct {
};

/// The 27B's Metal sources, embedded by name (zig/kernels/metal/qwen27).
const parts = [_][]const u8{ "xsum", "norm_xs", "norm_input", "mlp_xs", "mlp_ane", "glue", "copy", "moe", "moe_rows", "attention_mpp", "attention_io", "attention_prompt", "attention_prompt_sg", "prompt_glue", "prompt_state" };
const parts = [_][]const u8{ "xsum", "norm_xs", "norm_input", "mlp_xs", "mlp_ane", "glue", "gguf_norm", "copy", "moe", "moe_rows", "attention_mpp", "attention_io", "attention_prompt", "attention_prompt_sg", "prompt_glue", "prompt_state" };

/// The shared modules, imported into `engine` (whose `core` is itself) for the server and the release binary.
pub fn engineModules(b: *std.Build, target: std.Build.ResolvedTarget, metal: *std.Build.Module, sources: *std.Build.Module, engine: *std.Build.Module) Shared {
Expand Down
1 change: 1 addition & 0 deletions zig/build/qwen27_host.zig
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pub fn compileHost(b: *std.Build, metal: *std.Build.Module, engine: *std.Build.M
inline for (.{ "config_test.zig", "weights_test.zig", "checkpoint.zig", "projection.zig", "affine.zig", "geometry_test.zig" }) |file| tryNames(b, &dense_names, @embedFile("../src/families/qwen27/" ++ file));
tryNames(b, &dense_names, @embedFile("../src/families/qwen3_5/config.zig"));
b.step("test-qwen-dense-geometry-host", "Dense config and full-size packed headers without shaders or a GPU").dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = engine, .filters = dense_names.items })).step);
b.step("test-qwen27-gguf-bindings-host", "GGUF F32 attention gains and native defaults without a GPU").dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = engine, .filters = &.{"GGUF attention:"} })).step);
const api = b.createModule(.{ .root_source_file = b.path("zig/src/core/engine_api.zig"), .target = b.graph.host, .link_libc = true, .imports = &.{.{ .name = "lanes", .module = lanes }} });
const host = b.createModule(.{ .root_source_file = b.path("zig/src/native/qwen27_served.zig"), .target = b.graph.host, .link_libc = true, .imports = &.{ .{ .name = "metal", .module = metal }, .{ .name = "tensorfold", .module = engine }, .{ .name = "engine_api", .module = api } } });
b.step("test-qwen27-reply-cache-host", "Served reply keeps retain a reusable history within the cache caps").dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = host, .filters = &.{"qwen27 reply cache:"} })).step);
Expand Down
2 changes: 2 additions & 0 deletions zig/build/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ pub fn toolHostTests(b: *std.Build, parser: *std.Build.Module, server: *std.Buil
b.step("test-nemotron-window-host", "Nemotron advertised capacity and unchanged chat admission without devices").dependOn(&windows.step);
b.step("test-thinking-request-host", "Client refusals and internal note and lesson requests without devices").dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = server, .filters = &.{"thinking request:"} })).step);
b.step("test-thinking-benchmark-host", "Benchmark thinking capability and request bodies without devices").dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = server, .filters = &.{"thinking benchmark:"} })).step);
const gguf_text = b.addRunArtifact(b.addTest(.{ .root_module = server, .filters = &.{ "GGUF text:", "GGUF path" } }));
b.step("test-gguf-text-host", "GGUF tokenizer/template data and local source selection without a GPU").dependOn(&gguf_text.step);
const deepseek = b.addRunArtifact(b.addTest(.{ .root_module = server, .filters = &.{"DeepSeek chat:"} }));
deepseek.has_side_effects = true;
all.dependOn(&deepseek.step);
Expand Down
Loading
Loading