Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
940175e
inkling2: grouped expert and vision kernels under the contract
ajensenwaud Nov 20, 2026
8384d24
inkling2: size the vision projector from the config
ajensenwaud Nov 21, 2026
1fb0838
inkling2: refuse expert bit widths the grouped kernels cannot decode
ajensenwaud Nov 21, 2026
f96cefd
inkling2: test the expert and image refusals
ajensenwaud Nov 21, 2026
fa15c93
inkling2: orient RGBA pictures with core picture's pixel map
ajensenwaud Nov 21, 2026
8d494fb
inkling2: wrap the two long kernel table lines
ajensenwaud Nov 21, 2026
ee38269
inkling2: say why the vision rotary and scaled add stay in the family
ajensenwaud Nov 21, 2026
1828a20
vit: give the pointwise kernel a gamma mode
ajensenwaud Nov 21, 2026
8943188
exl3: add Inkling 2's softcapped SwiGLU as a gate/up epilogue
ajensenwaud Nov 21, 2026
2f8f6af
exl3: define the wide grouped kernel before the others
ajensenwaud Nov 21, 2026
9f4cffa
exl3: take any codebook, 32-member items and softcaps in runWith
ajensenwaud Nov 21, 2026
475c929
inkling2: run the experts on the core grouped kernel
ajensenwaud Nov 21, 2026
8703a35
inkling2: use the core softcapped epilogue for the experts
ajensenwaud Nov 21, 2026
8784095
core: one image-rows module for the four vision families
ajensenwaud Nov 21, 2026
f04c4e0
qwen27: export core's image rows from the roots Qwen 2.7 builds against
ajensenwaud Nov 22, 2026
e164889
inkling2: run vision attention on the core ViT kernel
ajensenwaud Nov 23, 2026
e32b7d6
exl3: give the grouped expert kernel 32-member tiles
ajensenwaud Nov 21, 2026
1e42cc6
exl3: round the capped expert epilogue as written
ajensenwaud Nov 24, 2026
c576735
inkling2: main's capped epilogue and layer scale equal the core kerne…
ashhart Nov 24, 2026
da1a0ac
inkling2: load standard exllamav3 packs with two-rank cuts
ajensenwaud Nov 23, 2026
2947678
inkling2 cuda: serve Mini from a stock EXL3 pack
Maxrio9 Nov 24, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

## Unreleased

- Inkling 2 Mini on CUDA: serve text from a stock exllamav3 EXL3 pack with its packed attention projections and routed experts (#4966). Thanks to @ajensenwaud for the EXL3 reader and grouped kernels it builds on.

- Inkling 2 on CUDA: a standard exllamav3 EXL3 pack loads with each projection and expert cut to one of two ranks, and other codebooks, versions and formats are refused by name (#4841, refs #3476). Thanks to @ajensenwaud.

- Hy4-flash: a host weight map for its ModelOpt NVFP4 build (groups of 16, no KV quantization), with the build's recipe and quality notes; serving it comes in later slices (#4110). Thanks @atakann.

- OCR: `POST /ocr` takes docTR's request contract (step 5 of #2440), with each page's response naming its file (#2574). Thanks @laudney.
Expand Down
7 changes: 7 additions & 0 deletions THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -617,3 +617,10 @@ build [atakans/Hy4-flash-NVFP4](https://huggingface.co/atakans/Hy4-flash-NVFP4)
([tencent/Hy4-flash](https://huggingface.co/tencent/Hy4-flash) at revision `d88c9dfd96ba4f2e6b92adba0b8e8f1c8696f959`)
under the Tencent Hy License 1.0 (see [the license text](LICENSES/Tencent-Hy-1.0.txt)); no weights are included.
`tools/hy4_flash/nvfp4.py` and `tools/hy4_flash/engram_fp8.py` rebuild that checkpoint (`docs/receipts/hy4-flash-nvfp4/`).

## Inkling 2 EXL3 packs

`zig/src/families/inkling2/exl3.zig` and `zig/src/families/inkling2/pack_weights.zig` read packs in the EXL3 format of
[turboderp-org/exllamav3](https://github.com/turboderp-org/exllamav3) 1.x (MIT): the trellis layout, the `mul1` codebook
and the per-tensor records. Packs carry the tensor names of an `inkling2` architecture added to exllamav3 for this
model. The loader and its two-rank cuts are TensorFold's own.
8 changes: 5 additions & 3 deletions zig/build/cuda_kernels.zig
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,16 @@ pub const kernels = [_]Kernel{
.{ .name = "idol_decoder", .flags = glue }, // ours: Idol's decoders' stem, to_kv, head norms and attention
.{ .name = "inkling2_attn", .src = "inkling2/attention", .flags = &.{"-O3"} }, // ours: Inkling 2's relative-bias attention
.{ .name = "inkling2_pattn", .src = "inkling2/prompt_attention", .flags = &.{"-O3"} }, // ours: Inkling 2's global-layer prompt attention
.{ .name = "inkling2_ops", .src = "inkling2/ops", .flags = glue }, // ours: Inkling 2's residual mix, convs, router, SwiGLU
.{ .name = "inkling2_ops", .src = "inkling2/ops", .flags = glue }, // ours: Inkling 2's residual mix, convs, router
.{ .name = "inkling2_rows", .src = "inkling2/rows", .flags = glue }, // ours: Inkling 2's router row dots on prompt rows
// ours: Inkling 2's vision tower glue
.{ .name = "inkling2_vision", .src = "inkling2/vision", .flags = glue },
.{ .name = "ricursive", .flags = glue }, // ours: Ripple's glue (embed, add-norms, output gate, FFN activation), glue.metal step for step
.{ .name = "ricursive_prep", .flags = glue }, // ours: Ripple's attention prep (q/k head norms, RoPE, K and V into rings or pages)
.{ .name = "inkling2_experts", .src = "inkling2/experts", .flags = &.{ "-O3", "--expt-relaxed-constexpr" } }, // ours: Inkling 2's grouped experts
// Mini's tensor-path expert epilogue and ascending combine: the modelopt contract's baseline
.{ .name = "inkling2_experts", .src = "inkling2/experts", .flags = &.{ "-O3", "--expt-relaxed-constexpr" } },
.{ .name = "inkling2_modelopt", .src = "inkling2/modelopt", .flags = &.{ "-O3", "--expt-relaxed-constexpr" } }, // Mini packed experts on BF16 activations
.{ .name = "inkling2_loop_math", .src = "inkling2/loop_math", .flags = &.{"-O3"} }, // Mini residuals, cross-pass messages, gates and split QKV
.{ .name = "inkling2_vision", .src = "inkling2/vision", .flags = glue }, // ours: Inkling 2's vision tower glue and attention
.{ .name = "glm_quant", .flags = torch_ops }, // ours: GLM's draft-only weight quantizers, torch at load in the Python family
.{ .name = "exl3_linear", .flags = &.{ "-O3", "--expt-relaxed-constexpr" } }, // exl3/linear.cu's device code, tensorfold_exl3_linear_v5
.{ .name = "exl3_experts", .flags = &.{ "-O3", "--expt-relaxed-constexpr" } }, // exl3/experts.cu's device code, tensorfold_exl3_experts
Expand Down
13 changes: 11 additions & 2 deletions zig/build/inkling2.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,17 @@ pub fn module(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.bui

/// The family in tf-cuda-test's `runner`, where the kernel contract reaches its launchers.
pub fn targets(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, strip: bool, cuda: *std.Build.Module, core: *std.Build.Module, lanes: *std.Build.Module, runner: *std.Build.Module) void {
_ = strip;
runner.addImport("inkling2", module(b, target, optimize, cuda, core, lanes));
const family = module(b, target, optimize, cuda, core, lanes);
runner.addImport("inkling2", family);
const exe = b.addExecutable(.{ .name = "tf-inkling2-mini-exl3-test", .root_module = b.createModule(.{
.root_source_file = b.path("zig/tests/cuda/inkling2_mini_exl3_main.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.strip = strip,
.imports = &.{ .{ .name = "cuda", .module = cuda }, .{ .name = "core", .module = core }, .{ .name = "inkling2", .module = family } },
}) });
b.step("tf-inkling2-mini-exl3-test", "Build the Mini EXL3 grouped contract and teacher-forced check tool").dependOn(&b.addInstallArtifact(exe, .{}).step);
}

/// The family's host regressions (config, chat wiring, reply split, admission, the attention plan) in `all`.
Expand Down
64 changes: 54 additions & 10 deletions zig/kernels/cuda/exl3_experts.cu
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ constexpr int GROUPED_LOAD = tf_exl3::AHEAD;
constexpr int GROUPED_LOAD = tf_exl3::PLAIN;
#endif

// Defined before the others: nvcc 13.3 then leaves tf_exl3_grouped_2's sm_12x SASS as it was.
extern "C" __global__ void tf_exl3_grouped_wide_2(tf_exl3::GroupedArgs a) { // mul1, 64 columns by 32 members
tf_exl3::grouped_body<2, 4, 4, GROUPED_LOAD, 2>(a, blockIdx.x, blockIdx.y, blockIdx.z);
}

extern "C" __global__ void tf_exl3_grouped_0(tf_exl3::GroupedArgs a) { // 3inst, any width
tf_exl3::grouped_body<0, 8, 4, GROUPED_LOAD>(a, blockIdx.x, blockIdx.y, blockIdx.z);
}
Expand Down Expand Up @@ -145,13 +150,9 @@ struct GateUpArgs {
int act_mode;
};

extern "C" __global__ void tf_exl3_gateup_epilogue(const GateUpArgs a) {
const int p = blockIdx.x, blk = blockIdx.y;
const int e = a.pick[p];
if (e < 0 || e >= a.experts) return;
const int lane = threadIdx.x;
const int n = blk * 128 + 4 * lane;
float gv[4], uv[4];
// The gate and up splits of pair p summed in order and rotated back (before the scales).
__device__ __forceinline__ void gateup_sums(const GateUpArgs& a, int p, int n, int lane, float (&gv)[4],
float (&uv)[4]) {
#pragma unroll
for (int j = 0; j < 4; ++j) {
float sg = 0.f, su = 0.f;
Expand All @@ -164,6 +165,24 @@ extern "C" __global__ void tf_exl3_gateup_epilogue(const GateUpArgs a) {
}
fwht128(gv, lane);
fwht128(uv, lane);
}

// The activations rotated into the down projection's inputs.
__device__ __forceinline__ void gateup_store(const GateUpArgs& a, int p, int n, int lane, float (&v)[4]) {
fwht128(v, lane);
half* o = a.xd + (size_t)p * a.n + n;
#pragma unroll
for (int j = 0; j < 4; ++j) o[j] = __float2half_rn(v[j] * HAD_SCALE);
}

extern "C" __global__ void tf_exl3_gateup_epilogue(const GateUpArgs a) {
const int p = blockIdx.x, blk = blockIdx.y;
const int e = a.pick[p];
if (e < 0 || e >= a.experts) return;
const int lane = threadIdx.x;
const int n = blk * 128 + 4 * lane;
float gv[4], uv[4];
gateup_sums(a, p, n, lane, gv, uv);
float v[4];
#pragma unroll
for (int j = 0; j < 4; ++j) {
Expand All @@ -181,10 +200,35 @@ extern "C" __global__ void tf_exl3_gateup_epilogue(const GateUpArgs a) {
}
v[j] = act * __half2float(a.suh_d[(size_t)e * a.n + n + j]);
}
fwht128(v, lane);
half* o = a.xd + (size_t)p * a.n + n;
gateup_store(a, p, n, lane, v);
}

// act_mode 3, Inkling 2's softcapped SwiGLU: gate_cap tanh(g / gate_cap) sigmoid(g) up_cap tanh(u / up_cap), fp32.
struct CappedArgs {
GateUpArgs g;
float gate_cap, up_cap;
};

extern "C" __global__ void tf_exl3_gateup_capped(const CappedArgs c) {
const GateUpArgs& a = c.g;
const int p = blockIdx.x, blk = blockIdx.y;
const int e = a.pick[p];
if (e < 0 || e >= a.experts) return;
const int lane = threadIdx.x;
const int n = blk * 128 + 4 * lane;
float gv[4], uv[4];
gateup_sums(a, p, n, lane, gv, uv);
float v[4];
#pragma unroll
for (int j = 0; j < 4; ++j) o[j] = __float2half_rn(v[j] * HAD_SCALE);
for (int j = 0; j < 4; ++j) {
const float g = gv[j] * HAD_SCALE * __half2float(a.svh_g[(size_t)e * a.n + n + j]);
const float u = uv[j] * HAD_SCALE * __half2float(a.svh_u[(size_t)e * a.n + n + j]);
// Each product and the sum round on their own: core's flags would otherwise fuse them into FMAs.
const float gs = __fmul_rn(__fmul_rn(c.gate_cap, tanhf(g / c.gate_cap)), 1.f / __fadd_rn(1.f, expf(-g)));
const float act = __fmul_rn(__fmul_rn(gs, c.up_cap), tanhf(u / c.up_cap));
v[j] = __fmul_rn(act, __half2float(a.suh_d[(size_t)e * a.n + n + j]));
}
gateup_store(a, p, n, lane, v);
}

// Program (member row, 128-block of the width): down epilogue and combine in one launch, the same bits as the two.
Expand Down
104 changes: 67 additions & 37 deletions zig/kernels/cuda/exl3_grouped.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,19 @@ struct GroupedArgs {
// How a warp reads its k tiles: main's loop, or a tile ahead (sm_120 up); SKIP and STALE are the contract's faults.
enum Load : int { PLAIN = 0, AHEAD = 1, SKIP = 2, STALE = 3 };

// One warp's k tiles [kt0, kt0 + nkt) of an expert matrix into acc: per-lane loads and the shared decode (same bits).
template <int CB, int K2, int NT, int LOAD>
__device__ __forceinline__ void warp_tiles(const uint32_t* T, int ntiles, int kt0, int nkt, int nt0, const half* x0,
const half* x1, bool ok0, bool ok1, int lane, float (&acc)[NT][2][4]) {
// One warp's k tiles [kt0, kt0 + nkt) of an expert matrix for MT 16-member tiles: per-lane loads, the shared decode.
template <int CB, int K2, int NT, int LOAD, int MT = 1>
__device__ __forceinline__ void warp_tiles(const uint32_t* T, int ntiles, int kt0, int nkt, int nt0,
const half* (&x0)[MT], const half* (&x1)[MT],
const int (&r0)[MT], const int (&r1)[MT], int lane,
float (&acc)[MT][NT][2][4]) {
constexpr int TW = tile_words<K2>(), LW = lane_words<K2>();
bool ok0[MT], ok1[MT];
#pragma unroll
for (int m = 0; m < MT; ++m) {
ok0[m] = r0[m] >= 0;
ok1[m] = r1[m] >= 0;
}
const size_t kstride = (size_t)ntiles * TW;
const uint32_t* tb = T + (size_t)kt0 * kstride + (size_t)nt0 * TW;
uint32_t nx[NT][LW]; // the next tile's words, in flight while this one decodes
Expand All @@ -55,28 +63,36 @@ __device__ __forceinline__ void warp_tiles(const uint32_t* T, int ntiles, int kt
for (int j = 0; j < NT; ++j) ldg_lane_words<K2>(tb + (size_t)next * kstride + j * TW, lane, nx[j]);
}
const int k = (kt0 + i) * 16;
const uint32_t a[4] = {ok0 ? *reinterpret_cast<const uint32_t*>(x0 + k) : 0u,
ok1 ? *reinterpret_cast<const uint32_t*>(x1 + k) : 0u,
ok0 ? *reinterpret_cast<const uint32_t*>(x0 + k + 8) : 0u,
ok1 ? *reinterpret_cast<const uint32_t*>(x1 + k + 8) : 0u};
uint32_t a[MT][4];
#pragma unroll
for (int m = 0; m < MT; ++m) {
a[m][0] = ok0[m] ? *reinterpret_cast<const uint32_t*>(x0[m] + k) : 0u;
a[m][1] = ok1[m] ? *reinterpret_cast<const uint32_t*>(x1[m] + k) : 0u;
a[m][2] = ok0[m] ? *reinterpret_cast<const uint32_t*>(x0[m] + k + 8) : 0u;
a[m][3] = ok1[m] ? *reinterpret_cast<const uint32_t*>(x1[m] + k + 8) : 0u;
}
#pragma unroll
for (int j = 0; j < NT; ++j) {
uint32_t b0[2], b1[2];
decode_lane<K2, CB>(w[j], lane, b0, b1);
mma16816(acc[j][0], a, b0);
mma16816(acc[j][1], a, b1);
#pragma unroll
for (int m = 0; m < MT; ++m) {
mma16816(acc[m][j][0], a[m], b0);
mma16816(acc[m][j][1], a[m], b1);
}
}
}
}

// Program (expert u, n block, split, member tile): 16 members times W_q over the split's K range, summed in warp order.
template <int CB, int NT, int W, int LOAD>
// Program (expert u, n block, split, member tile): 16 MT members times W_q over the split's K range, in warp order.
template <int CB, int NT, int W, int LOAD, int MT = 1>
__device__ __forceinline__ void grouped_body(const GroupedArgs a, int u, int nblock, int zz) {
if (u >= a.ucount[0]) return;
const int MT = (a.maxm + 15) / 16;
const int mtile = zz % MT;
const int split = (zz / MT) % a.sk;
const int mat = zz / MT / a.sk;
constexpr int M = 16 * MT; // members a program
const int TILES = (a.maxm + M - 1) / M;
const int mtile = zz % TILES;
const int split = (zz / TILES) % a.sk;
const int mat = zz / TILES / a.sk;
const half* X = mat ? a.x1 : a.x0;
const int e = a.standard ? a.uids[3 * u] : a.uids[u];
if (a.standard && e == a.skip) return;
Expand All @@ -86,36 +102,48 @@ __device__ __forceinline__ void grouped_body(const GroupedArgs a, int u, int nbl
const int g = lane >> 2, t = lane & 3;
const int NTILES = a.ns > 0 ? a.ns : (a.n >> 4); // row stride of the trellis, in tiles

__shared__ int rows_sh[16];
if (threadIdx.x < 16) {
const int m = mtile * 16 + threadIdx.x;
__shared__ int rows_sh[M];
if (threadIdx.x < M) {
const int m = mtile * M + threadIdx.x;
const int count = a.standard ? a.uids[3 * u + 2] : a.maxm;
const int first = a.standard ? a.uids[3 * u + 1] : u * a.maxm;
const int code = m < count ? a.members[first + m] : -1;
rows_sh[threadIdx.x] = a.standard ? code : (code >= 0 ? (code >> 5) * a.slots + (code & 31) : -1);
}
__syncthreads();
if (rows_sh[0] < 0) return; // members come first, so this tile is empty
const int r0 = rows_sh[g], r1 = rows_sh[g + 8];
const half* x0 = X + (size_t)(r0 < 0 ? 0 : r0) * a.k + 2 * t;
const half* x1 = X + (size_t)(r1 < 0 ? 0 : r1) * a.k + 2 * t;
int r0[MT], r1[MT];
#pragma unroll
for (int m = 0; m < MT; ++m) {
r0[m] = rows_sh[16 * m + g];
r1[m] = rows_sh[16 * m + g + 8];
}
const half* x0[MT];
const half* x1[MT];
#pragma unroll
for (int m = 0; m < MT; ++m) {
x0[m] = X + (size_t)(r0[m] < 0 ? 0 : r0[m]) * a.k + 2 * t;
x1[m] = X + (size_t)(r1[m] < 0 ? 0 : r1[m]) * a.k + 2 * t;
}
const int per_warp = (a.k >> 4) / a.sk / W;
const int kt0 = split * (per_warp * W) + warp * per_warp;
const int nt0 = nblock * NT;

float acc[NT][2][4];
float acc[MT][NT][2][4];
#pragma unroll
for (int i = 0; i < NT; ++i)
for (int m = 0; m < MT; ++m)
#pragma unroll
for (int h = 0; h < 2; ++h)
for (int i = 0; i < NT; ++i)
#pragma unroll
for (int c = 0; c < 4; ++c) acc[i][h][c] = 0.f;
for (int h = 0; h < 2; ++h)
#pragma unroll
for (int c = 0; c < 4; ++c) acc[m][i][h][c] = 0.f;

__shared__ __align__(16) float red[W][16][NT * 16];
__shared__ __align__(16) float red[W][M][NT * 16];
switch (k2) {
#define TF_EXL3X_CASE(K2_) \
case K2_: \
warp_tiles<CB, K2_, NT, LOAD>(T, NTILES, kt0, per_warp, nt0, x0, x1, r0 >= 0, r1 >= 0, lane, acc); \
warp_tiles<CB, K2_, NT, LOAD, MT>(T, NTILES, kt0, per_warp, nt0, x0, x1, r0, r1, lane, acc); \
break;
TF_EXL3X_CASE(2)
TF_EXL3X_CASE(3)
Expand All @@ -138,17 +166,19 @@ __device__ __forceinline__ void grouped_body(const GroupedArgs a, int u, int nbl
}

#pragma unroll
for (int i = 0; i < NT; ++i)
for (int m = 0; m < MT; ++m)
#pragma unroll
for (int h = 0; h < 2; ++h) {
const int col = i * 16 + h * 8 + 2 * t;
red[warp][g][col] = acc[i][h][0];
red[warp][g][col + 1] = acc[i][h][1];
red[warp][g + 8][col] = acc[i][h][2];
red[warp][g + 8][col + 1] = acc[i][h][3];
}
for (int i = 0; i < NT; ++i)
#pragma unroll
for (int h = 0; h < 2; ++h) {
const int col = i * 16 + h * 8 + 2 * t;
red[warp][16 * m + g][col] = acc[m][i][h][0];
red[warp][16 * m + g][col + 1] = acc[m][i][h][1];
red[warp][16 * m + g + 8][col] = acc[m][i][h][2];
red[warp][16 * m + g + 8][col + 1] = acc[m][i][h][3];
}
__syncthreads();
for (int idx = threadIdx.x; idx < 16 * NT * 16; idx += W * 32) {
for (int idx = threadIdx.x; idx < M * NT * 16; idx += W * 32) {
const int row = idx / (NT * 16), col = idx % (NT * 16);
const int r = rows_sh[row];
if (r < 0) continue;
Expand Down
Loading