Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1be6dc0
Windows: a platform layer and host builds that pass
BobClawblaw Oct 12, 2026
e5bb3bc
Windows: CUDA kernels, the native server and the GPU suites on sm_89
BobClawblaw Oct 12, 2026
1f87b27
Windows: pull into the hub cache, HOME, and the whole test step
BobClawblaw Oct 12, 2026
996a50f
Windows: build notes, strip before install, formatting
BobClawblaw Oct 12, 2026
aac93d2
Default port 8888
BobClawblaw Oct 12, 2026
81f5576
qwen3_5: serve Qwen3.5-2B on CUDA
BobClawblaw Oct 13, 2026
3ace97e
qwen3_5: serve Qwen3.8-27B on CUDA, one arena for a model's device me…
BobClawblaw Oct 14, 2026
6b85f22
qwen3_5: replay each decode shape as a CUDA graph
BobClawblaw Oct 14, 2026
b19e0d7
qwen3_5: DFlash2 drafts for Qwen3.8-27B on CUDA
BobClawblaw Oct 14, 2026
288ba03
qwen3_5: tree drafts on CUDA, the kept path replayed from a log
BobClawblaw Oct 14, 2026
61fc2bf
docs: the Qwen hybrids on CUDA in the Windows page and the README
BobClawblaw Oct 14, 2026
6aaf241
qwen3_5, platform: comments on one line
BobClawblaw Oct 14, 2026
8107ee2
Windows: checkpoint reads skip the page cache
BobClawblaw Oct 14, 2026
693533e
Windows: the signal handler type allows address 1, for aarch64
BobClawblaw Oct 14, 2026
f53ae20
docs: Windows as a target in the README and the Windows page
BobClawblaw Oct 14, 2026
e875ee2
CI: the host unit tests on Windows
BobClawblaw Oct 14, 2026
38ecce5
qwen3_5: the drafter reads TF_TIMING through the platform layer
BobClawblaw Oct 14, 2026
1817823
qwen3_5: the drafter takes a prompt longer than its tap ring
BobClawblaw Oct 14, 2026
b811a3b
qwen3_5 cuda: prompt chunks past 32 rows see the right keys, and tree…
BobClawblaw Oct 14, 2026
0a0856b
Windows: the server goldens and the Cortheon fuzz step on Windows hosts
BobClawblaw Oct 14, 2026
ccd06b9
cuda: cuBLASLt opens by its Windows DLL name
BobClawblaw Oct 14, 2026
045abbd
Windows: writes on an O_APPEND descriptor land at the end whole
BobClawblaw Oct 14, 2026
bdfeb84
golden check: a request-log mismatch names the first differing line
BobClawblaw Oct 14, 2026
153d6b4
golden check: the request log compares with LF endings on either side
BobClawblaw Oct 14, 2026
8570e06
qwen3_5: attention chunks follow each row's own keys, not the forward…
BobClawblaw Oct 15, 2026
5e1c3fe
qwen3_5: the DFlash2 config's divisors must be positive, and staging …
BobClawblaw Oct 15, 2026
d653cd5
perf(qwen3_5 cuda): deliver the first token before drafting
jrb-ai Oct 16, 2026
1471afe
docs: pin the Spark driver and CUDA toolkit on the first-token receipt
jrb-ai Oct 17, 2026
52639bd
docs: publish the first-token harness and per-request rows
jrb-ai Oct 17, 2026
72462cc
docs: add the startup clock anchors and unbound replay plans
jrb-ai Oct 17, 2026
5248a33
docs: clarify first-token replay clocks and startup receipt
jrb-ai Oct 18, 2026
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
Prev Previous commit
Next Next commit
qwen3_5, platform: comments on one line
The lean rule (tools/zig/lean_check.py) counts a comment that runs on
to a second line; the Windows port's new files had a hundred such runs.
Each is one line of at most 120 columns now, and the checker reports
the same 539 problems as main.
  • Loading branch information
BobClawblaw committed Oct 14, 2026
commit 6aaf241affa27864e08898a4648bc4e32a491015
3 changes: 1 addition & 2 deletions zig/build/sys.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! `sys` (zig/src/platform/sys.zig) for every module the build compiles: one walk of the step graph after it is
//! declared, so no module's declaration needs to name it.
//! `sys` (zig/src/platform/sys.zig) for every module the build compiles, by one walk of the step graph once declared.

const std = @import("std");

Expand Down
45 changes: 11 additions & 34 deletions zig/kernels/cuda/qwen35.cu
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
// Qwen3.5's hybrid text models on CUDA (the 2B and Qwen3.8-27B): the Metal engine's kernels (zig/kernels/metal/qwen3_5)
// with the same bf16 rounding points, their widths from the model's Geo. Rows of one forward belong to segments (one
// stream's window each); a segment's state lives in its stream's blocks.
// Qwen3.5's hybrids (2B, 27B) on CUDA: the Metal kernels' arithmetic and rounding; a segment is one stream's window.

#include "qwen35.cuh"

using namespace tf_q35;

// The per-forward counts a captured forward reads from the device, so one graph serves every shape: P[0] attention
// chunks, P[1] their width, P[2] rows, P[3] windows, P[4] whether the rows are recorded for keep (a verify window:
// its state stays as it was until the kept path is applied). A null P means the launch's grid is exact.
// A window's rows may form a tree: rowpar names each forward row's parent forward row (-1: the window's first row,
// after the stream's cache), rowanc each row's ancestors and itself as bits over its window's rows.
// P (device counts, one graph for every shape): chunks, width, rows, windows, recorded; rowpar/rowanc give the tree.
__device__ __forceinline__ bool past_rows(const int* P, int m) { return P != nullptr && m >= P[2]; }
__device__ __forceinline__ bool past_windows(const int* P, int s) { return P != nullptr && s >= P[3]; }
__device__ __forceinline__ bool recorded(const int* P) { return P != nullptr && P[4] != 0; }
Expand All @@ -30,8 +24,7 @@ extern "C" __global__ void __launch_bounds__(256) tf_q35_embed(const int* __rest
}
}

// h = bf16(h + r) (r may be null), x = bf16(w * (h * inv)), D wide (a multiple of 256, at most 8192). One 256-thread
// block a row; each thread's elements in index order, warps summed in order.
// h = bf16(h + r) (r may be null), x = bf16(w * (h * inv)); D a multiple of 256 up to 8192; a 256-thread block a row.
extern "C" __global__ void __launch_bounds__(256) tf_q35_norm(__nv_bfloat16* __restrict__ H, const __nv_bfloat16* __restrict__ R,
const __nv_bfloat16* __restrict__ W, __nv_bfloat16* __restrict__ X, float eps, int D,
const int* __restrict__ P) {
Expand Down Expand Up @@ -82,9 +75,7 @@ extern "C" __global__ void tf_q35_sums(const __nv_bfloat16* __restrict__ X, floa
}
}

// The causal convolution, silu, q/k normalization and the decay and write strength of each row's linear heads.
// Grid (1, 2 * nk + nv, rows), a warp a (row, head): heads [0, nk) are q, [nk, 2nk) k, then nv of v. A row's taps
// are its parents (then the stream's tail), so a tree's rows each see their own branch.
// Conv, silu, q/k norms, the linear heads' decay and write: a warp a (row, head) over q, k, v; taps from the parents.
extern "C" __global__ void __launch_bounds__(32) tf_q35_gdn_pre(Geo geo, const __nv_bfloat16* __restrict__ QKV, const Seg* __restrict__ segs,
const int* __restrict__ rowseg, const int* __restrict__ rowpar, int layer,
const __nv_bfloat16* __restrict__ CW,
Expand Down Expand Up @@ -144,9 +135,7 @@ extern "C" __global__ void __launch_bounds__(32) tf_q35_gdn_pre(Geo geo, const _
}
}

// Each segment's convolution tail: a recorded window logs the tail after each of its rows (the last TAPS - 1 tokens of
// the row's branch) for keep, and leaves the stream's own; a prompt chunk or one-row window updates the stream's in
// place. A thread a (segment, channel).
// A segment's conv tail: a recorded window logs each row's for keep and leaves the stream's; others update it in place.
extern "C" __global__ void tf_q35_conv_commit(Geo geo, const __nv_bfloat16* __restrict__ QKV, const Seg* __restrict__ segs,
const int* __restrict__ rowpar, int layer, const int* __restrict__ P) {
const int C = geo.conv();
Expand All @@ -171,12 +160,7 @@ extern "C" __global__ void tf_q35_conv_commit(Geo geo, const __nv_bfloat16* __re
}
}

// The gated delta rule over each segment's rows, each row's state its parent's updated: a chain carries the state in
// registers, a branch rebuilds its parent's from the stream's recurrence and the logged updates of the ancestors.
// A recorded window logs each row's (decay, write, key) and leaves the recurrence as it was (keep applies the kept
// path, qwen35_keep.cu); a prompt chunk or one-row window updates it in place. Value head hv reads key head
// hv / (nv / nk). Grid (1, DK / 4, nv * segments), block (32, 4): a warp a (value head, value row), its 32 lanes
// over the key width.
// Gated delta rule, each row's state its parent's: a chain keeps it in registers, a branch rebuilds it from the log.
extern "C" __global__ void __launch_bounds__(128) tf_q35_gdn_chain(Geo geo, const __nv_bfloat16* __restrict__ q, const __nv_bfloat16* __restrict__ k,
const __nv_bfloat16* __restrict__ v, const float* __restrict__ g,
const __nv_bfloat16* __restrict__ beta, const Seg* __restrict__ segs,
Expand All @@ -201,8 +185,7 @@ extern "C" __global__ void __launch_bounds__(128) tf_q35_gdn_chain(Geo geo, cons
const int row = sg.row0 + r;
const int parent = rowpar[row];
if (parent != prev) {
// a branch: its parent's state from the stream's and the ancestors' updates, oldest first (their keys
// and decays from this forward's rows, their writes from the log, which this thread wrote itself)
// a branch: its parent's state from the stream's and the ancestors' logged updates, oldest first
int anc[MAXW];
int n = 0;
for (int a = parent; a >= 0; a = rowpar[a]) anc[n++] = a;
Expand Down Expand Up @@ -286,8 +269,7 @@ extern "C" __global__ void __launch_bounds__(32) tf_q35_gdn_post(Geo geo, const
}
}

// Per-head RMSNorm of attention rows: X's head h of row m at m * stride + h * hstride, out packed (rows, heads, HD).
// Grid (rows * heads), 64 threads of 4 values.
// Per-head RMSNorm of attention rows, out packed (rows, heads, HD); grid (rows * heads), 64 threads of 4 values.
extern "C" __global__ void __launch_bounds__(64) tf_q35_head_norm(const __nv_bfloat16* __restrict__ X, const __nv_bfloat16* __restrict__ W,
__nv_bfloat16* __restrict__ OUT, int heads, int stride, int hstride, float eps,
const int* __restrict__ P) {
Expand Down Expand Up @@ -325,8 +307,7 @@ __device__ __forceinline__ __nv_bfloat16 rotate(const __nv_bfloat16* x, int d, i
return __float2bfloat16_rn(d < 32 ? a * cs - b * sn : b * cs + a * sn);
}

// Queries in place at their positions (the cache length plus the row's depth in its window); keys rotated and values
// copied into their segment's cache at the row's own slot (the cache length plus its row). Grid (rows), HD threads.
// Queries rotated in place, keys rotated and values copied into the row's cache slot; grid (rows), HD threads.
extern "C" __global__ void __launch_bounds__(256) tf_q35_rope(Geo geo, __nv_bfloat16* __restrict__ Qn, const __nv_bfloat16* __restrict__ Kn,
const __nv_bfloat16* __restrict__ Vr, const Seg* __restrict__ segs,
const int* __restrict__ rowseg, const unsigned* __restrict__ rowanc, int layer,
Expand All @@ -351,10 +332,7 @@ extern "C" __global__ void __launch_bounds__(256) tf_q35_rope(Geo geo, __nv_bflo
}
}

// Causal attention over a segment's cache, P[1] keys a block over P[0] chunks (read from the device, so a captured
// forward replays as caches grow): grid (chunks at most, kvh, rows), block qh / kvh warps, a warp a query head of
// the kv head's group. A row sees the cache before its window and its window's ancestors and itself (rowanc).
// Partials (max, sum, out) at slot (row, qh, chunk); empty chunks leave sum 0.
// Causal attention over the cache in P[0] chunks of P[1] keys, a warp a query head; partials by (row, head, chunk).
extern "C" __global__ void tf_q35_attn_partial(Geo geo, const __nv_bfloat16* __restrict__ Q, const Seg* __restrict__ segs,
const int* __restrict__ rowseg, const unsigned* __restrict__ rowanc, int layer,
const int* __restrict__ P, float scale,
Expand Down Expand Up @@ -454,8 +432,7 @@ extern "C" __global__ void tf_q35_attn_gate(Geo geo, const __nv_bfloat16* __rest
OUT[i] = __float2bfloat16_rn(bf(Y[i]) * s);
}

// A tapped layer's residual stream, bf16(h + r) as the next norm rounds it, into each row's segment's tap ring at
// the row's position: plane `tap` of the row's taps. Grid (rows), 256 threads.
// A tapped layer's residual bf16(h + r) into the segment's tap ring at the row's position; a 256-thread block a row.
extern "C" __global__ void __launch_bounds__(256) tf_q35_tap(const __nv_bfloat16* __restrict__ H, const __nv_bfloat16* __restrict__ R,
const Seg* __restrict__ segs, const int* __restrict__ rowseg, int tap, int D,
const int* __restrict__ P) {
Expand Down
9 changes: 3 additions & 6 deletions zig/kernels/cuda/qwen35.cuh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// What qwen35.cu and qwen35_keep.cu share: the model's widths (Geo), a stream's window in a forward (Seg), the per-row
// record a verify window leaves in its stream's log, and the walk from a row back through its parents.
// Shared by qwen35.cu and qwen35_keep.cu: the widths (Geo), a stream's window (Seg), a row's log record, parent walks.

#pragma once
#include <cuda_bf16.h>
Expand All @@ -19,8 +18,7 @@ struct Geo {
__device__ int conv() const { return (2 * nk + nv) * DK; } // q, k and v channels the convolution sees
__device__ size_t rec() const { return (size_t)nv * DK * DK; } // floats of one layer's recurrence
__device__ size_t conv_rows() const { return (size_t)(TAPS - 1) * conv(); }
// one row's record of one linear layer: decay and write strength a value head, its write a value (head, dv), its
// key a key head, and the convolution tail after it
// a row's record of a linear layer: decay, strength and write a value head, key a key head, the tail after it
__device__ size_t log_bytes() const { return (size_t)nv * 4 + (size_t)nv * DK * 4 + (size_t)nk * DK * 2 + conv_rows() * 2; }
};

Expand Down Expand Up @@ -58,8 +56,7 @@ struct Path {
int rows[MAXW];
};

// The row `steps` tokens before forward row `w` through its parents (rowpar: each forward row's parent forward row, -1
// for a window's first row): a forward row, or -1 - t for the stream's convolution tail row t (TAPS - 2 the newest).
// The row `steps` tokens before forward row `w` through rowpar: a forward row, or -1 - t for the stream's tail row t.
__device__ __forceinline__ int back(const int* __restrict__ rowpar, int w, int steps) {
int a = w;
for (int s = 1; s <= steps; s++) {
Expand Down
15 changes: 4 additions & 11 deletions zig/kernels/cuda/qwen35_draft.cu
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// The DFlash2 drafter's glue on CUDA (zig/src/families/qwen3_5/cuda_draft.zig): a block of rows attends over the
// target's tapped context, with two-tap dynamic convolutions around attention and MLP. Rounding points follow the
// Metal drafter's draft_ops.metal; the projections run through the target engine's affine-4 kernels.
// DFlash2 drafter glue on CUDA (cuda_draft.zig): a block of rows over the target's taps, draft_ops.metal's rounding.

#include <cuda_bf16.h>
#include <stdint.h>
Expand Down Expand Up @@ -46,9 +44,7 @@ extern "C" __global__ void tf_q35d_gather_rows(const __nv_bfloat16* __restrict__
for (int i = threadIdx.x; i < width; i += blockDim.x) dst[i] = src[i];
}

// y[t, c] = sum over lags l of (BASE[branch, l, c] + DYN[t, (branch * 2 + l) * groups + c / group]) * x[t - l, c],
// each product and sum rounded to bf16 in turn; x[-1] is zero (the block's first row has no past); RES, if given,
// is added last. D wide rows, `group` channels a dynamic coefficient. Grid (rows), 256 threads.
// y[t, c] = sum over lags l of (BASE[l, c] + DYN[t, l, c / group]) * x[t - l, c] in bf16 steps; x[-1] = 0; RES last.
extern "C" __global__ void tf_q35d_dyn_conv(const __nv_bfloat16* __restrict__ X, const __nv_bfloat16* __restrict__ DYN,
const __nv_bfloat16* __restrict__ BASE, const __nv_bfloat16* __restrict__ RES,
__nv_bfloat16* __restrict__ OUT, int D, int group, int branch) {
Expand All @@ -69,8 +65,7 @@ extern "C" __global__ void tf_q35d_dyn_conv(const __nv_bfloat16* __restrict__ X,
}
}

// Per-head RMSNorm over HD then rotate-half RoPE over all HD at position pos0 + row: X's head h of row m at
// m * stride + h * HD, OUT packed (rows, heads, HD). Grid (rows * heads), 32 threads of 4 values.
// Per-head RMSNorm then rotate-half RoPE at position pos0 + row; OUT packed (rows, heads, HD), grid (rows * heads).
extern "C" __global__ void __launch_bounds__(32) tf_q35d_norm_rope(const __nv_bfloat16* __restrict__ X, const __nv_bfloat16* __restrict__ W,
__nv_bfloat16* __restrict__ OUT, int heads, int stride, long long pos0,
float eps, float theta) {
Expand Down Expand Up @@ -115,9 +110,7 @@ extern "C" __global__ void tf_q35d_ring_put(const __nv_bfloat16* __restrict__ K,
}
}

// The block's attention: query row m, head h sees the context ring's positions [max(begin, p - window + 1), pos0)
// where p = pos0 + m, and every block row (the drafter is not causal within its block). GQA over kv_heads; scale
// 1 / sqrt(HD). Grid (rows, heads), a warp each; online softmax in fp32, bf16 out (rows, heads * HD).
// Block attention: a row sees ring positions [max(begin, p - window + 1), pos0) and every block row; a warp a row.
extern "C" __global__ void __launch_bounds__(32) tf_q35d_attn(const __nv_bfloat16* __restrict__ Q, const __nv_bfloat16* __restrict__ KB,
const __nv_bfloat16* __restrict__ VB, const __nv_bfloat16* __restrict__ RK,
const __nv_bfloat16* __restrict__ RV, int rows, int heads, int kv_heads, int W,
Expand Down
11 changes: 3 additions & 8 deletions zig/kernels/cuda/qwen35_keep.cu
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
// Keeping a verified window's path on CUDA (zig/src/families/qwen3_5/cuda_cache.zig): the stream's recurrences take
// the path's logged updates in order, its convolution tails the path's last row's, and a tree's kept keys move down
// to the slots after the cache. The rows of a window were recorded by qwen35.cu's kernels (Seg.log).
// Keeping a verified window's path (cuda_cache.zig): the recurrences take its logged updates and its keys move down.

#include "qwen35.cuh"

using namespace tf_q35;

// Each linear layer's recurrence through the path's rows' (decay, key, write), as the forward's chain would have
// left it. Grid (1, DK / 4, nv * nl), block (32, 4): a warp a (layer, value head, value row), its lanes over the key.
// Each linear layer's recurrence through the path's (decay, key, write), as the forward's chain would have left it.
extern "C" __global__ void __launch_bounds__(128) tf_q35k_apply(Geo geo, Seg sg, Path path) {
const int NK = geo.nk, NV = geo.nv;
const int layer = blockIdx.z / NV, hv = blockIdx.z % NV;
Expand Down Expand Up @@ -43,9 +40,7 @@ extern "C" __global__ void tf_q35k_conv(Geo geo, Seg sg, int last) {
CS[i] = log_row(geo, sg, layer, last).conv[i];
}

// The path's rows' keys and values (slot cache length + row) down to the slots cache length + 0, 1, ... in path
// order: row j of the path is at least j, so a move never lands on a slot a later move still reads. One block a
// (attention layer, kv head): grid (attention layers, kvh), HD threads, a barrier between moves.
// The path's keys and values move down to the slots after the cache; row j lands at or below j, never on one unread.
extern "C" __global__ void __launch_bounds__(256) tf_q35k_compact(Geo geo, Seg sg, Path path) {
const int KVH = geo.kvh;
const int layer = blockIdx.x, h = blockIdx.y;
Expand Down
3 changes: 1 addition & 2 deletions zig/src/cli/pull_file.zig
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ pub fn linkIntoSnapshot(a: Allocator, io: std.Io, snapshot_dir: []const u8, path
std.Io.Dir.cwd().deleteFile(io, link_path) catch {};
const target = try std.fs.path.join(a, &.{ "..", "..", "blobs", blob_name });
std.Io.Dir.cwd().symLink(io, target, link_path, .{}) catch |err| {
// Windows grants symlinks only with Developer Mode or elevation (and refuses some): a hard link to the blob,
// which costs no space (huggingface_hub copies instead); learning refuses linked shards either way
// Windows grants symlinks only with Developer Mode or elevation: a hard link to the blob costs no space
if (@import("builtin").os.tag != .windows) {
std.log.err("cannot link {s} to its blob: {t}", .{ link_path, err });
return error.SymLinkFailed;
Expand Down
6 changes: 2 additions & 4 deletions zig/src/core/lanes/drafter.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ pub const Facts = struct {
lane_costs: []const Cost = &.{}, // the same for the lane planner (Model.lane_costs)
};

/// Target rows [start, start + features.rows) and the token after each; rows at or past `start` replace what was held.
/// `rows`, when given, picks the features' rows to absorb (a tree's kept path), in order; null: all of them.
/// Target rows [start, start + features.rows) and the token after each; `rows`, when given, picks which to absorb.
pub const Absorb = struct { stream: *Stream, features: Features, start: u64, follow: []const u32, rows: ?[]const u32 = null };

/// Draft `depth` tokens after `pending`, the first at `position`; asked only once row `position - 2` was absorbed.
/// With `lanes`, a tree instead: lane i's token is the rank-r choice after its parent (depth unused).
/// `depth` drafts after `pending` at `position`; with `lanes` a tree, lane i the rank-r choice after its parent.
pub const Hold = struct { stream: *Stream, pending: u32, position: u64, depth: u32, lanes: ?*const Shape = null };

pub const Drafter = struct {
Expand Down
3 changes: 1 addition & 2 deletions zig/src/families/qwen3_5/cuda.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! The Qwen3.5 hybrids on CUDA (the 2B, Qwen3.8-27B): the engine and its native family entry (the Metal 2B engine is
//! qwen3_5.zig).
//! The Qwen3.5 hybrids on CUDA (2B, Qwen3.8-27B): the engine and its native family entry; Metal's 2B is qwen3_5.zig.
pub const config = @import("config.zig");
pub const geometry = @import("cuda_geometry.zig");
pub const engine = @import("cuda_engine.zig");
Expand Down
Loading