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

## Unreleased

- Tests: a config and a metadata-only model header for the tiny Inkling 2 Mini test checkpoint (`hf-internal-testing/tiny-inkling2-mini`), with host tests for parsing, the weight map and the 30-visit plan (#5369). Thanks @AbrahamCete.

- Hy4 Flash CUDA gains its FP8 Engram kernels with kernel-contract gates, controls and five-SM launch limits (slice 2b of #4795) (#5087). Thanks to @GrgaPalcic.

- CUDA: a host guard now fails any programmatic dependent launch of a kernel without its dependency wait, and DeepSeek's generic x3ld kernels wait first (#PR, after #5308).
Expand Down
6 changes: 6 additions & 0 deletions THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,12 @@ extracted headers, with the same revision annotation. No revision was derived fr
`release_chat_template.jinja` and `release_tokenizer_config.json` in the same folder are byte-identical copies of that
revision's `chat_template.jinja` and `tokenizer_config.json`, under the same license.

`tiny_mini_config.json` and the tensor table `tiny_mini_model_header.txt` in the same folder describe
`hf-internal-testing/tiny-inkling2-mini` at revision `ee242a48af34ff0729518f4ac28cfcb847e470ab`, the tiny checkpoint
that `docs/design/inkling-2-mini.md` names for same-engine exactness; its model card states no licence. The config is a
byte-identical copy and the table holds only metadata from the `model.safetensors` header, no tensor data or weights.
`tools/zig/inkling2_fixtures.py` rebuilds both, from that file or its extracted `model.header.json`.

The Mini loop host/reference implementations in `zig/src/families/inkling2/loop.zig`, `loop_model.zig`, `loop_engine.zig`,
`loop_math_cuda.zig`, the CUDA and Metal loop kernels and the stored-expert implementations in `modelopt.zig` and
`zig/kernels/cuda/inkling2/modelopt.cu` are independent TensorFold implementations of the supplied math-only Mini
Expand Down
13 changes: 10 additions & 3 deletions tools/zig/inkling2_fixtures.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Rebuild zig/src/families/inkling2/fixtures from the Small, tiny-random and Mini checkpoint inputs."""
"""Rebuild zig/src/families/inkling2/fixtures from the Small, tiny-random, Mini and tiny Mini checkpoint inputs."""
import argparse
import hashlib
import json
Expand All @@ -10,6 +10,7 @@
FIXTURES = ROOT / "zig/src/families/inkling2/fixtures"
RELEASE = "thinkingmachines/Inkling-2-Small@2ad1157016e1aac77b6ff1b770e7c05229403134"
TINY = "tiny-random/inkling-2@0a57c72e4e5b68aafe1d983dbb62980344a5fcd7"
TINY_MINI = "hf-internal-testing/tiny-inkling2-mini@ee242a48af34ff0729518f4ac28cfcb847e470ab"
MINI_RELEASE = "thinkingmachines/Inkling-2-Mini"
MINI_REVISION = "ed40e7da625f594fc9c4990f5f66be24873c22d7"
MINI_PROVENANCE = {
Expand Down Expand Up @@ -187,7 +188,7 @@ def prompt_cases(release):
return {"reference": reference, "chat": chat, "raw": raw}


def build(release, tiny, mini):
def build(release, tiny, mini, tiny_mini):
"""Every fixture file as bytes."""
full = json.loads((release / "tokenizer.json").read_text(encoding="utf-8"))
cut = json.dumps(cut_tokenizer(full), separators=(",", ":"), ensure_ascii=False) + "\n"
Expand All @@ -207,6 +208,8 @@ def build(release, tiny, mini):
"mini_mtp_header.txt": fold(
"inkling2-mini-mtp", release_header(mini, "mtp"), MINI_HEADER_PROVENANCE
).encode("utf-8"),
"tiny_mini_config.json": (tiny_mini / "config.json").read_bytes(),
"tiny_mini_model_header.txt": fold("inkling2-tiny-mini-model", release_header(tiny_mini, "model")).encode("utf-8"),
}


Expand All @@ -219,13 +222,17 @@ def main():
"--mini", type=Path, required=True,
help=f"{MINI_RELEASE}: config.json and model/MTP safetensors or extracted .header.json files; full revision supplied separately after config-field match",
)
parser.add_argument(
"--tiny-mini", type=Path, required=True,
help=f"{TINY_MINI}: config.json and model.safetensors or its extracted model.header.json",
)
parser.add_argument("--out", type=Path, default=FIXTURES, help="the fixtures directory to write or compare")
parser.add_argument("--check", action="store_true", help="write nothing; exit 1 if a file differs from the one in --out")
args = parser.parse_args()
for name, want in PINS.items():
if version(name) != want:
raise SystemExit(f"{name} {version(name)} is installed, {want} is pinned")
files = build(args.release, args.tiny, args.mini)
files = build(args.release, args.tiny, args.mini, args.tiny_mini)
differ = 0
if not args.check:
args.out.mkdir(parents=True, exist_ok=True)
Expand Down
27 changes: 26 additions & 1 deletion zig/src/families/inkling2/config_test.zig
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
//! Config parsing: the real checkpoint's config.json, the tiny-random one, and what parse refuses.
//! Config parsing: the real checkpoint's config.json, the tiny-random one, the tiny Mini, and what parse refuses.
const std = @import("std");
const config = @import("config.zig");

const t = std.testing;
pub const real = @embedFile("fixtures/config.json");
pub const tiny = @embedFile("fixtures/tiny_config.json");
pub const mini = @embedFile("fixtures/mini_config.json");
pub const tiny_mini = @embedFile("fixtures/tiny_mini_config.json");

fn refused(json: []const u8, from: []const u8, to: []const u8, want: anyerror, says: []const u8) !void {
if (std.mem.count(u8, json, from) != 1) return error.EditAnchor;
Expand Down Expand Up @@ -94,6 +95,30 @@ test "tiny-random's config.json parses: 12 layers, 96 experts, width 128, no qua
try t.expectEqual(@as(u32, 1024), c.text.extent(5));
}

test "tiny-inkling2-mini's config.json parses: 18 weight layers, a 6-layer core, 30 visits and no drafter" {
var why: config.Why = .{};
const c = try config.parse(t.allocator, tiny_mini, &why);
try t.expectEqual(@as(u32, 256), c.text.hidden);
try t.expectEqual(@as(u32, 18), c.text.layers);
try t.expectEqual(@as(u32, 30), c.text.visitCount());
try t.expectEqual(config.Heads{ .q = 4, .kv = 2, .dim = 128 }, c.text.global);
try t.expectEqual(config.Heads{ .q = 4, .kv = 2, .dim = 128 }, c.text.local);
try t.expectEqual(@as(u32, 8192), c.text.log_floor);
try t.expectEqual(@as(u32, 16), c.text.experts);
try t.expectEqual(@as(u32, 4), c.text.topk);
try t.expectEqual(@as(u32, 256), c.text.expert_inter);
try t.expectEqual(@as(u32, 128), c.text.extent(0));
try t.expectEqual(@as(u32, 256), c.text.extent(5));
const loop = c.text.loop.?;
try t.expectEqual(@as(u32, 6), loop.core_start);
try t.expectEqual(@as(u32, 12), loop.core_end);
try t.expectEqual(@as(u32, 3), loop.passes);
try t.expectEqual(@as(u32, 64), loop.gate_rank);
try t.expectEqual(@as(u32, 256), c.vision.text_hidden);
try t.expectEqual(@as(u32, 2), c.vision.layers);
try t.expect(c.mtp == null);
}

test "a config that is not Inkling 2 is refused by name" {
try refused(tiny, "\"model_type\": \"inkling2\"", "\"model_type\": \"llama\"", error.NotInkling2, "not an Inkling 2 checkpoint");
try refused(tiny, "Inkling2ForConditionalGeneration", "Inkling2ForCausalLM", error.NotInkling2, "not an Inkling 2 checkpoint");
Expand Down
84 changes: 84 additions & 0 deletions zig/src/families/inkling2/fixtures/tiny_mini_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"architectures": [
"Inkling2LoopForConditionalGeneration"
],
"model_type": "inkling2_loop",
"eos_token_id": 200006,
"text_config": {
"model_type": "inkling2_loop_text",
"model_max_length": 1048576,
"torch_dtype": "bfloat16",
"hidden_size": 256,
"num_hidden_layers": 18,
"vocab_size": 201024,
"num_attention_heads": 4,
"num_key_value_heads": 2,
"head_dim": 128,
"d_rel": 16,
"rel_extent": 256,
"q_bias": false,
"o_bias": false,
"log_scaling_n_floor": 8192,
"log_scaling_alpha": 0.1,
"rms_norm_eps": 1e-06,
"use_value_norm_no_gamma": true,
"qk_l2_clip_threshold": 22.627416997969522,
"rel_l2_clip_threshold": 8.0,
"local_layer_ids": [
0,
1,
2,
3,
4,
6,
7,
8,
9,
10,
12,
13,
14,
15,
16
],
"sconv_kernel_size": 4,
"unpadded_vocab_size": 200058,
"final_logit_softcapping": 30.0,
"swa_head_dim": 128,
"swa_num_attention_heads": 4,
"swa_num_key_value_heads": 2,
"sliding_window_size": 128,
"n_layers_per_attn_res_block": 6,
"attn_res_normalize_values": true,
"n_routed_experts": 16,
"num_experts_per_tok": 4,
"n_shared_experts": 0,
"intermediate_size": 256,
"mlp_gate_softcap": 4.0,
"mlp_up_softcap": 25.0,
"route_scale": 8.0,
"use_gate_bias": true,
"loop_config": {
"core_start": 6,
"core_end": 12,
"num_passes": 3,
"gate_rank": 64,
"is_varloop": false
}
},
"vision_config": {
"model_type": "inkling2_vision",
"text_hidden_size": 256,
"temporal_patch_size": 2,
"native_patch_size": 20,
"adapter_merge_size": 2,
"projection_hidden_dim": 256,
"projector_bias": false,
"hidden_size": 128,
"num_hidden_layers": 2,
"num_attention_heads": 2,
"mlp_ratio": 4.0,
"posemb_grid_size": 32,
"layer_norm_eps": 1e-05
}
}
87 changes: 87 additions & 0 deletions zig/src/families/inkling2/fixtures/tiny_mini_model_header.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
inkling2-tiny-mini-model 622 d3a5b3d2d4da72ebeeeabb017add88b05a28d0f691e3a135745c17983bc988fc
model.llm.attn_res.attn_queries.{L} F32 256 0-3,5-9,11-15
model.llm.attn_res.attn_queries.{L} F32 3x256 4,10,16
model.llm.attn_res.mlp_queries.{L} F32 256 0-17
model.llm.attn_res.output_query F32 256
model.llm.embed.weight BF16 201024x256
model.llm.embed_norm.weight BF16 256
model.llm.layers.{L}.attn.attn_sink_proj.weight BF16 4x256 0-17
model.llm.layers.{L}.attn.gate_attn.weight BF16 512x256 0-17
model.llm.layers.{L}.attn.k_sconv.static_w BF16 4x256 5,11,17
model.llm.layers.{L}.attn.k_sconv.weight BF16 256x1x4 0-4,6-10,12-16
model.llm.layers.{L}.attn.k_sconv.weight_proj BF16 8x256 5,11,17
model.llm.layers.{L}.attn.q_l2_clip.scale BF16 4x128 0-17
model.llm.layers.{L}.attn.rel_l2_clip.scale BF16 4x16 0-17
model.llm.layers.{L}.attn.rel_logits_proj.proj BF16 16x128 0-4,6-10,12-16
model.llm.layers.{L}.attn.rel_logits_proj.proj BF16 16x256 5,11,17
model.llm.layers.{L}.attn.v_sconv.static_w BF16 4x256 5,11,17
model.llm.layers.{L}.attn.v_sconv.weight BF16 256x1x4 0-4,6-10,12-16
model.llm.layers.{L}.attn.v_sconv.weight_proj BF16 8x256 5,11,17
model.llm.layers.{L}.attn.wk_dv.weight BF16 256x256 0-17
model.llm.layers.{L}.attn.wo_ud.weight BF16 256x512 0-17
model.llm.layers.{L}.attn.wq_du.weight BF16 512x256 0-17
model.llm.layers.{L}.attn.wr_du.weight BF16 64x256 0-17
model.llm.layers.{L}.attn.wv_dv.weight BF16 256x256 0-17
model.llm.layers.{L}.attn_norm.weight BF16 256 0-4,6-10,12-16
model.llm.layers.{L}.attn_sconv.weight BF16 256x1x4 0-17
model.llm.layers.{L}.controllers.attn.down_weight BF16 64x512 6-11
model.llm.layers.{L}.controllers.attn.forget_weight BF16 256x64 6-11
model.llm.layers.{L}.controllers.attn.gain_weight BF16 256x64 6-11
model.llm.layers.{L}.controllers.k.down_weight BF16 64x512 6-11
model.llm.layers.{L}.controllers.k.forget_weight BF16 256x64 6-11
model.llm.layers.{L}.controllers.k.gain_weight BF16 256x64 6-11
model.llm.layers.{L}.controllers.mlp.down_weight BF16 64x512 6-11
model.llm.layers.{L}.controllers.mlp.forget_weight BF16 256x64 6-11
model.llm.layers.{L}.controllers.mlp.gain_weight BF16 256x64 6-11
model.llm.layers.{L}.controllers.v.down_weight BF16 64x512 6-11
model.llm.layers.{L}.controllers.v.forget_weight BF16 256x64 6-11
model.llm.layers.{L}.controllers.v.gain_weight BF16 256x64 6-11
model.llm.layers.{L}.k_input_norm.weight BF16 256 5,11,17
model.llm.layers.{L}.mlp.experts.w13_weight F8_E4M3 16x512x256 14-17
model.llm.layers.{L}.mlp.experts.w13_weight U8 16x512x128 0-13
model.llm.layers.{L}.mlp.experts.w13_weight_amax F32 16 0-13
model.llm.layers.{L}.mlp.experts.w13_weight_outer_scale_denominator F32 1 0-13
model.llm.layers.{L}.mlp.experts.w13_weight_scale F8_E4M3 16x512x16 0-13
model.llm.layers.{L}.mlp.experts.w13_weight_scale U8 16x512x8 14-17
model.llm.layers.{L}.mlp.experts.w2_weight F8_E4M3 16x256x256 14-17
model.llm.layers.{L}.mlp.experts.w2_weight U8 16x256x128 0-13
model.llm.layers.{L}.mlp.experts.w2_weight_amax F32 16 0-13
model.llm.layers.{L}.mlp.experts.w2_weight_outer_scale_denominator F32 1 0-13
model.llm.layers.{L}.mlp.experts.w2_weight_scale F8_E4M3 16x256x16 0-13
model.llm.layers.{L}.mlp.experts.w2_weight_scale U8 16x256x8 14-17
model.llm.layers.{L}.mlp.gate.bias F32 16 0-17
model.llm.layers.{L}.mlp.gate.weight BF16 16x256 0-17
model.llm.layers.{L}.mlp_norm.weight BF16 256 0-17
model.llm.layers.{L}.mlp_sconv.weight BF16 256x1x4 0-17
model.llm.layers.{L}.q_input_norm.weight BF16 256 5,11,17
model.llm.layers.{L}.v_input_norm.weight BF16 256 5,11,17
model.llm.middle_cycle_cross_pass_kv_queries F32 12x256
model.llm.middle_cycle_cross_pass_queries F32 12x256
model.llm.norm.weight BF16 256
model.llm.unembed.weight BF16 201024x256
model.visual.backbone.embeddings.class_embedding BF16 128
model.visual.backbone.embeddings.cls_position_embedding BF16 128
model.visual.backbone.embeddings.patch_embedding.weight BF16 128x1200
model.visual.backbone.embeddings.position_embedding BF16 1024x128
model.visual.backbone.layers.{L}.ln_1.bias BF16 128 0-1
model.visual.backbone.layers.{L}.ln_1.weight BF16 128 0-1
model.visual.backbone.layers.{L}.ln_2.bias BF16 128 0-1
model.visual.backbone.layers.{L}.ln_2.weight BF16 128 0-1
model.visual.backbone.layers.{L}.ls_1.gamma BF16 128 0-1
model.visual.backbone.layers.{L}.ls_2.gamma BF16 128 0-1
model.visual.backbone.layers.{L}.mlp.c_fc.bias BF16 512 0-1
model.visual.backbone.layers.{L}.mlp.c_fc.weight BF16 512x128 0-1
model.visual.backbone.layers.{L}.mlp.c_proj.bias BF16 128 0-1
model.visual.backbone.layers.{L}.mlp.c_proj.weight BF16 128x512 0-1
model.visual.backbone.layers.{L}.self_attn.k_proj.bias BF16 128 0-1
model.visual.backbone.layers.{L}.self_attn.k_proj.weight BF16 128x128 0-1
model.visual.backbone.layers.{L}.self_attn.out_proj.bias BF16 128 0-1
model.visual.backbone.layers.{L}.self_attn.out_proj.weight BF16 128x128 0-1
model.visual.backbone.layers.{L}.self_attn.q_proj.bias BF16 128 0-1
model.visual.backbone.layers.{L}.self_attn.q_proj.weight BF16 128x128 0-1
model.visual.backbone.layers.{L}.self_attn.v_proj.bias BF16 128 0-1
model.visual.backbone.layers.{L}.self_attn.v_proj.weight BF16 128x128 0-1
model.visual.backbone.ln_pre.bias BF16 128
model.visual.backbone.ln_pre.weight BF16 128
model.visual.proj_in.weight BF16 256x512
model.visual.proj_out.weight BF16 256x256
52 changes: 52 additions & 0 deletions zig/src/families/inkling2/names_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const model_fixture = @embedFile("fixtures/tiny_model_header.txt");
const mtp_fixture = @embedFile("fixtures/tiny_mtp_header.txt");
const mini_model_fixture = @embedFile("fixtures/mini_model_header.txt");
const mini_mtp_fixture = @embedFile("fixtures/mini_mtp_header.txt");
const tiny_mini_model_fixture = @embedFile("fixtures/tiny_mini_model_header.txt");

fn byName(_: void, a: []const u8, b: []const u8) bool {
return std.mem.lessThan(u8, a, b);
Expand Down Expand Up @@ -86,6 +87,11 @@ fn loadMini(a: std.mem.Allocator) !config.Config {
return config.parse(a, config_test.mini, &why);
}

fn loadTinyMini(a: std.mem.Allocator) !config.Config {
var why: config.Why = .{};
return config.parse(a, config_test.tiny_mini, &why);
}

test "the folded fixtures unfold to the 404 and 84 tensors of tiny's two files, digests equal" {
var arena = std.heap.ArenaAllocator.init(t.allocator);
defer arena.deinit();
Expand Down Expand Up @@ -270,6 +276,52 @@ test "Mini's visit plan repeats only the core, gives all 48 visits private state
try t.expectEqual(@as(u32, 5), p.final_sources);
}

test "tiny-inkling2-mini's config parses and the map names exactly the 622 tensors of its model file" {
var arena = std.heap.ArenaAllocator.init(t.allocator);
defer arena.deinit();
const a = arena.allocator();
const c = try loadTinyMini(a);
const entries = try unfold(a, tiny_mini_model_fixture, "inkling2-tiny-mini-model");
try t.expectEqual(@as(usize, 622), entries.count());
const model = try names.check(a, &c, entries, .model);
try t.expectEqual(@as(usize, 622), model.expected);
try t.expect(model.clean());
}

test "tiny-inkling2-mini's expert precision is NVFP4 on layers 0 to 13 and MXFP8 on 14 to 17" {
var arena = std.heap.ArenaAllocator.init(t.allocator);
defer arena.deinit();
const entries = try unfold(arena.allocator(), tiny_mini_model_fixture, "inkling2-tiny-mini-model");
var prec: [18]plan.Precision = undefined;
try names.precisions(entries, 18, &prec);
for (prec, 0..) |p, i| try t.expectEqual(if (i < 14) plan.Precision.nvfp4 else plan.Precision.mxfp8, p);
}

test "tiny-inkling2-mini's visit plan repeats its 6-layer core three times over 30 visits and banks the previous pass" {
var arena = std.heap.ArenaAllocator.init(t.allocator);
defer arena.deinit();
const a = arena.allocator();
const c = try loadTinyMini(a);
var prec: [18]plan.Precision = undefined;
try names.precisions(try unfold(a, tiny_mini_model_fixture, "inkling2-tiny-mini-model"), 18, &prec);
const p = try plan.build(&c.text, &prec);
try t.expectEqual(@as(u32, 30), p.n_visits);
try t.expectEqual(@as(u32, 5), p.visitCount(.global));
try t.expectEqual(@as(u32, 25), p.visitCount(.local));
for (0..p.n_visits) |i| {
const v = p.visit(@intCast(i));
const layer: u32 = if (i < 6) @intCast(i) else if (i < 24) 6 + @as(u32, @intCast((i - 6) % 6)) else @intCast(i - 12);
const pass: u32 = if (i >= 6 and i < 24) 1 + @as(u32, @intCast((i - 6) / 6)) else 0;
try t.expectEqual(layer, v.layer);
try t.expectEqual(pass, v.pass);
try t.expectEqual(@as(u32, @intCast(i)), v.cache_slot);
try t.expectEqual(pass >= 2, v.hasMessages());
const previous: ?u32 = if (pass == 2) 6 else if (pass == 3) 12 else null;
try t.expectEqual(previous, v.previous_core_start);
}
try t.expectEqual(@as(u32, 4), p.final_sources);
}

/// A file's header through the core reader; the files may hold the header alone, so no data length is checked.
fn headerOf(a: std.mem.Allocator, dir: []const u8, file: []const u8) !st.Header {
const path = try std.fmt.allocPrint(a, "{s}/{s}", .{ dir, file });
Expand Down
Loading