Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a89a509
inkling2: grouped expert and vision kernels under the contract
ajensenwaud Nov 20, 2026
196ec30
inkling2: size the vision projector from the config
ajensenwaud Nov 21, 2026
0150b8d
inkling2: refuse expert bit widths the grouped kernels cannot decode
ajensenwaud Nov 21, 2026
14fa28d
inkling2: test the expert and image refusals
ajensenwaud Nov 21, 2026
9940923
inkling2: orient RGBA pictures with core picture's pixel map
ajensenwaud Nov 21, 2026
26618bc
inkling2: wrap the two long kernel table lines
ajensenwaud Nov 21, 2026
21d75c0
inkling2: say why the vision rotary and scaled add stay in the family
ajensenwaud Nov 21, 2026
c6f4dbf
inkling2: run vision attention on the core ViT kernel
ajensenwaud Nov 23, 2026
e66e49d
exl3: give the grouped expert kernel 32-member tiles
ajensenwaud Nov 21, 2026
2c3c9be
exl3: add Inkling 2's softcapped SwiGLU as a gate/up epilogue
ajensenwaud Nov 21, 2026
ec12ae5
exl3: define the wide grouped kernel before the others
ajensenwaud Nov 21, 2026
5cef42d
exl3: take any codebook, 32-member items and softcaps in runWith
ajensenwaud Nov 21, 2026
3228cbd
inkling2: run the experts on the core grouped kernel
ajensenwaud Nov 21, 2026
3b8b756
inkling2: use the core softcapped epilogue for the experts
ajensenwaud Nov 21, 2026
d2361b7
core: one image-rows module for the four vision families
ajensenwaud Nov 21, 2026
95150b6
vit: give the pointwise kernel a gamma mode
ajensenwaud Nov 21, 2026
e1b6855
qwen27: export core's image rows from the roots Qwen 2.7 builds against
ajensenwaud Nov 22, 2026
8bae576
exl3: round the capped expert epilogue as written
ajensenwaud Nov 24, 2026
e128c7a
inkling2: main's capped epilogue and layer scale equal the core kerne…
ashhart Nov 24, 2026
055542a
inkling2: load standard exllamav3 packs with two-rank cuts
ajensenwaud Nov 23, 2026
9a8a1da
inkling2: serve Small on two GB10s from an EXL3 pack
ajensenwaud Nov 23, 2026
c6b04d0
docs: add the Inkling 2 Small CUDA recipe page
ajensenwaud Nov 23, 2026
65ded79
inkling2: choose a stream's slot before publishing its lane
ajensenwaud Nov 24, 2026
4525974
inkling2: compare every shard byte across the ranks at ready
ajensenwaud Nov 24, 2026
b4d0a13
inkling2: make a call's scratch safe to free at every failed allocation
ajensenwaud Nov 24, 2026
f7e9fca
inkling2: bind the config each rank runs into the ready check
ajensenwaud Nov 25, 2026
3c262e5
inkling2: free the prompt projections when engine setup fails
ajensenwaud Nov 25, 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
15 changes: 15 additions & 0 deletions THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -625,3 +625,18 @@ under the Tencent Hy License 1.0 (see [the license text](LICENSES/Tencent-Hy-1.0
`ace1100dcde7bf4eb06add6ae11ce4f43a11ddfe` (all but its last, ByteLevel), under the Apache License 2.0 stated on its
model card (see [the license text](LICENSES/Apache-2.0.txt)), and the pieces the Hugging Face tokenizers library splits
with them and with a few other patterns. `tools/zig/onig_anchor_fixtures.py` rebuilds the file.

## 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.

## Inkling 2 serving

`zig/src/families/inkling2/forward.zig`, `engine.zig` and the files they call run the decoder in the layer order of
Hugging Face transformers' `src/transformers/models/inkling2/modeling_inkling2.py` at commit `109a7d19bf66`
([huggingface/transformers](https://github.com/huggingface/transformers), Apache-2.0): `Inkling2SlidingDecoderLayer`,
`Inkling2FullDecoderLayer` and `Inkling2TextModel`. The two-rank engine, the lanes and the prompt path are TensorFold's
own.
2 changes: 2 additions & 0 deletions docs/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ Diagnostics quote and escape the supplied text so it cannot create another termi
| `TF_NEMOTRON_RANK` | Nemotron 3.5 Super on CUDA: a whole rank index from 0 through 4294967295, set with `TF_NEMOTRON_WORLD`; unset with it gives one rank |
| `TF_NEMOTRON_WORLD` | Nemotron 3.5 Super on CUDA: a whole rank count from 1 through 4294967295, set with `TF_NEMOTRON_RANK`; unset with it gives one rank |
| `TF_NEMOTRON_WIDE_ROUNDS` | Exactly `0` or `1`, checked when the CUDA backend starts; default off. `1` lets Nemotron's shared rounds hold 16 streams and 32 rows on GB10 (one rank, non-latent, not Bolt, no `--precision checkpoint`, no bf16 experts, no Sliding Weights or saved lessons; refused with a log line naming why), each row's bits as in two 16-row rounds; a lone stream's window is unchanged |
| `TF_INKLING2_RANK` | Inkling 2 on CUDA: a whole rank index, 0 or 1 at two ranks, set with `TF_INKLING2_WORLD`; unset with it gives one rank |
| `TF_INKLING2_WORLD` | Inkling 2 on CUDA: a whole rank count, 2 on CUDA, set with `TF_INKLING2_RANK`; unset with it gives one rank |
| `TF_MINIMAX_RANK` | MiniMax-M3.1-Flash on CUDA: a whole rank index, 0 or 1 at two ranks, set with `TF_MINIMAX_WORLD`; unset with it gives one rank |
| `TF_MINIMAX_WORLD` | MiniMax-M3.1-Flash on CUDA: a whole rank count, 2 at CUDA, set with `TF_MINIMAX_RANK`; unset with it gives one rank |
| `TF_MINIMAX_GRAPHS` | MiniMax-M3.1-Flash on CUDA: exactly `0` or `1`, the same on every rank; default off. `1` records each one-stream decode verify window's launches as a CUDA graph and updates the held graph with that round's arguments before launching it (one graph per row count, sparse or dense attention, and taps); the same kernels with the same arguments in the same order, so tokens keep their bits. A refused capture or refresh on any rank sends every rank back to eager launches |
Expand Down
1 change: 1 addition & 0 deletions docs/recipes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ For agent-assisted contributions, read the [TensorFold contributor skill](SKILL.
| Recursive Flint | [Native Metal, the publisher's affine 4-bit export, reasoning and tool calls](flint.md) |
| Unlimited-OCR-2 | [Native Metal, the bf16 release: page images to structured text, 131k context](unlimited-ocr-metal.md) |
| Muse Spark Open | [EXL3 on CUDA, two-rank DGX Spark, plain decode](muse-spark.md) |
| Inkling 2 Small | [EXL3 on CUDA, two-rank DGX Spark, images, plain decode](inkling-2-small-cuda.md) |
| Ripple-65B-Preview | [Native CUDA, the publisher's NVFP4 release](ripple-65b-cuda.md), [native Metal, the publisher's NVFP4 and bf16 releases](ripple-65b-metal.md) |
| Ling-3.0-tiny | [Native CPU on aarch64 Linux, the Q4_K_M GGUF, exact greedy decode from token IDs](ling-3.0-tiny-cpu.md) |
| SenseNova-Loop-9B | [Native Metal, BF16 and AWQ g128, 512k context, MTP drafts, images](sensenova-loop-9b.md) |
Expand Down
52 changes: 52 additions & 0 deletions docs/recipes/inkling-2-small-cuda.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Inkling 2 Small on CUDA

The `inkling2` family serves a standard exllamav3 EXL3 pack of Thinking Machines' Inkling 2 Small on the native CUDA
server, on two DGX Sparks (GB10, sm_121) as tensor-parallel ranks. Package: `zig/src/families/inkling2/`, kernels in
`zig/kernels/cuda/inkling2/`. It reads the pack exllamav3 writes (`config.json` with `quantization_config`, an index
and shards), so any exllamav3 1.x pack of the model on the `mul1` codebook loads.

## The model

- 48 layers of hidden size 4,608: 40 sliding-window layers (1,024 keys) and 8 global layers, no RoPE. The global
layers keep every key, so the served window is the model's own 1,048,576 tokens.
- Attention: 48 query heads and 8 key heads of 128, a learned relative-position bias, sinks and a sigmoid output gate.
Short convolutions sit on the keys, the values and both residual branches.
- MoE: 384 routed experts, 8 a token, softcapped SwiGLU.
- A vision tower (`vision.safetensors` beside the pack) turns pictures into rows that replace the image placeholders.

## Checkpoint

| | Repository | Revision |
|---|---|---|
| Pack (EXL3 mul1, 2.2 bpw, head 8 bits) | `ajensenwaud/inkspark-2dgx` | `aa29f3a011b011896826416f03b8ac55d7ec7c6f` |
| Source | `thinkingmachines/Inkling-2-Small` | `aac974122acd33ddb0d3e1f54433a9c5dd2249ce` |

## Files

| File | What it does |
|---|---|
| `exl3.zig`, `pack_weights.zig`, `shard.zig`, `shape.zig` | The pack's reader: EXL3 projections, grouped experts, the head, each cut to its rank |
| `forward.zig`, `prompt_dense.zig` | A call's rows through every layer: decode rows of several streams, or a prompt chunk |
| `engine.zig`, `kept.zig`, `sampler.zig` | One rank's engine: slots, graphed decode rows, prompt chunks, kept prompt states, draws |
| `follow.zig`, `lanes.zig`, `native.zig`, `admit.zig` | Rank 0 serves and sends each step to rank 1; the lanes backend behind `serve` |
| `pictures.zig` | The server's image offer and each slot's image rows on every rank |
| `engine_main.zig` | `tf-inkling2-engine`: graph replay against eager rows, and greedy decode, on two ranks |

A row's bits do not depend on the other streams in its forward, the graph or how its prompt is cut into chunks, so
graphed decode equals eager decode and a resumed prompt equals a fresh one.

## Serving

Both hosts run the server with the same flags; rank 0 answers the API.

```bash
# on each host, RANK 0 on the head and 1 on the worker
TF_INKLING2_RANK=$RANK TF_INKLING2_WORLD=2 NCCL_COMM_ID=<head address>:<port> TF_ROCE=1 \
tensorfold-native serve /model --name Inkling-2-Small --context 1048576 --parallel 1 --vision --no-drafts
```

`--context 131072 --parallel 4` gives four streams of 128K. The KV cache is bf16. The bundled DSpark drafter
(`mtp.safetensors`) is not read yet, so every stream decodes one token a step.

The family refuses any other setup by name: one rank, a GPU other than GB10, another codebook or exllamav3 version,
and a pack whose tensors differ from what the reader expects.
8 changes: 5 additions & 3 deletions zig/build/cuda_kernels.zig
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,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
9 changes: 7 additions & 2 deletions zig/build/inkling2.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ pub fn module(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.bui
return m;
}

/// The family in tf-cuda-test's `runner`, where the kernel contract reaches its launchers.
/// The family in tf-cuda-test's `runner`; tf-inkling2-engine (the engine's graph and greedy checks).
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 m = b.createModule(.{ .root_source_file = b.path("zig/src/families/inkling2/engine_main.zig"), .target = target, .optimize = optimize, .link_libc = true, .strip = strip });
m.addImport("cuda", cuda);
m.addImport("inkling2", module(b, target, optimize, cuda, core, lanes));
const exe = b.addExecutable(.{ .name = "tf-inkling2-engine", .root_module = m });
b.installArtifact(exe);
b.step("tf-inkling2-engine", "Inkling 2's engine checks: graph replay against eager rows, greedy decode").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
Loading
Loading