Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
75a0c39
inkling2: accept Mini host config and checkpoint names
ashhart Nov 21, 2026
0841f67
inkling2: model the Mini loop on the host
ashhart Nov 21, 2026
41807f3
inkling2: run checkpoint-packed experts on CUDA
ashhart Nov 21, 2026
7ce4e9c
inkling2: run Mini loop math on CUDA
ashhart Nov 21, 2026
a775a32
inkling2: serve Mini text on one CUDA rank
ashhart Nov 21, 2026
c40710c
lanes: make full lone-window commits opt-in
ashhart Nov 21, 2026
ece3a40
inkling2: add Mini Metal kernels and contracts
ashhart Nov 21, 2026
bbcb8ee
inkling2: serve Mini natively on Metal
ashhart Nov 21, 2026
11c3e3c
inkling2: document Mini fixture and reference provenance
ashhart Nov 21, 2026
e718511
inkling2: normalize before CUDA query reductions
ashhart Nov 21, 2026
840a700
inkling2: control packed-expert contracts by phase
ashhart Nov 21, 2026
5acab1f
inkling2: fix native Metal Mini admission and serving
ashhart Nov 21, 2026
0577913
inkling2: prove Mini CUDA serving equivalence
ashhart Nov 21, 2026
56de510
inkling2: compile Mini CUDA tests against current lane types
ashhart Nov 21, 2026
7e30540
inkling2: link Metal host tests on macOS
ashhart Nov 21, 2026
2a8cdd6
inkling2: fix nonfinite prompt expert launches
ashhart Nov 21, 2026
dd60cf1
inkling2: refresh Mini limits and quiet shape refusal
ashhart Nov 21, 2026
3e0e9bc
inkling2: complete native Metal admission and serving tests
ashhart Nov 21, 2026
9922582
inkling2 metal: the native build finds the checkpoint file cache and …
sethforprivacy Nov 21, 2026
c68340d
inkling2 metal: norm binds its arguments and its output where sp_norm…
sethforprivacy Nov 21, 2026
2f386ca
inkling2 metal: routed experts as one simdgroup an output
sethforprivacy Nov 21, 2026
49c7986
inkling2 metal: loop gates and router as short launches, a simdgroup …
sethforprivacy Nov 21, 2026
a889fac
inkling2 metal: launch records for the rewritten experts, gates and r…
sethforprivacy Nov 21, 2026
d447ca7
lean: the router scores comment fits 120 columns
sethforprivacy Nov 21, 2026
6f0f294
inkling2 metal: a later stream of a shared forward reads its relative…
sethforprivacy Nov 22, 2026
ef5bd87
inkling2 metal: the depth mixes and the loop gates take every row in …
sethforprivacy Nov 21, 2026
2c8338c
inkling2 metal: routed experts grouped by expert for chunks of four r…
sethforprivacy Nov 21, 2026
eaea488
inkling2 metal: sliding attention in 32-key chunks, global attention …
sethforprivacy Nov 21, 2026
c3e8d57
inkling2 metal dspark: attention scale 1/sqrt(128), and the recurrent…
sethforprivacy Nov 21, 2026
b513297
inkling2 metal dspark: base logits a simdgroup an id, and only the ro…
sethforprivacy Nov 21, 2026
4b34498
inkling2 metal dspark: attention scores and weights on all 128 thread…
sethforprivacy Nov 22, 2026
2beb53e
local: pread cap (upstream in #4433/#4435)
sethforprivacy Nov 21, 2026
52db4fd
lean: the global chunk comment fits 120 columns
sethforprivacy Nov 22, 2026
d8d5e7e
lean: the drafter kernel comments fit 120 columns
sethforprivacy Nov 22, 2026
52aa183
inkling2 metal dspark: a hold offers three drafts, so four streams sh…
sethforprivacy Nov 22, 2026
1fc5a43
inkling2 metal dspark: the recurrent step's z scratch holds the three…
sethforprivacy Nov 22, 2026
dedf6ee
inkling2 metal: experts grouped from eight rows, and a projection of …
sethforprivacy Nov 22, 2026
7e4629c
inkling2 metal: the forward on a concurrent encoder in five command b…
sethforprivacy Nov 22, 2026
90e37f0
inkling2 metal dspark: a hold is one command buffer a step for all it…
sethforprivacy Nov 22, 2026
94fb17e
inkling2 metal: routed experts on the tensor units at every width, so…
sethforprivacy Nov 22, 2026
9ffc2f1
inkling2 metal: a greedy row without a token mask is picked sixteen l…
sethforprivacy Nov 22, 2026
48b2f36
inkling2 metal dspark: the engine prices a lone stream's drafts with …
sethforprivacy Nov 22, 2026
67b60d9
inkling2 metal: the depth mix reads four values a thread, and each si…
sethforprivacy Nov 22, 2026
d916bf3
inkling2 metal: the combine orders a token's routes once a threadgroup
sethforprivacy Nov 22, 2026
85c12b1
inkling2 metal dspark: the chain's two kernels under the contract, th…
sethforprivacy Nov 22, 2026
550c4d2
inkling2 metal dspark: the pick's contract entry serves a row with a …
sethforprivacy Nov 22, 2026
89a6fc9
inkling2 metal: prompt chunks of up to 256 rows, so a tensor-unit til…
sethforprivacy Nov 22, 2026
a0f938a
inkling2 metal dspark: no plain rounds beside the drafter, whose firs…
sethforprivacy Nov 22, 2026
b38f0fa
inkling2 metal: the prompt pass a chunk a call, so other streams deco…
sethforprivacy Nov 22, 2026
2048bb3
inkling2 metal: a snapshot copies each key-value head's live rows, so…
sethforprivacy Nov 22, 2026
c0f151c
inkling2 cuda: load the Mini checkpoint (one precision a layer, one a…
jschmied Nov 22, 2026
4c9b273
inkling2 cuda: pass the attention gate and sink to tf_ink2_merge raw
jschmied Nov 22, 2026
e2b3acd
inkling2 cuda: write cross-pass messages plane-major, as the gates re…
jschmied Nov 22, 2026
7f4bc4c
inkling2 cuda: a cache slot per served stream
jschmied Nov 22, 2026
f7377e8
inkling2 metal: the logits kernel reads a vocabulary row once for up …
sethforprivacy Nov 22, 2026
b550319
inkling2 metal: logits on the tensor units, one pass of the vocabular…
sethforprivacy Nov 22, 2026
33dbeab
inkling2 metal: the window fit counts the drafter's bytes a token, no…
sethforprivacy Nov 22, 2026
bd4a87e
inkling2 metal: a window's grammar masks step by the padded vocabular…
sethforprivacy Nov 22, 2026
0c9708e
fixup: the logits kernel's comment on one line
sethforprivacy Nov 22, 2026
eef79df
inkling2 metal: a prompt's rows take their projections on the tensor …
sethforprivacy Nov 22, 2026
11be391
inkling2 metal: a prompt's rows take the sliding layers' attention on…
sethforprivacy Nov 22, 2026
321432e
inkling2 cuda: copy prompt-cache states per key head
jschmied Nov 22, 2026
bec3d0a
inkling2 metal: a chunk wider than a window stages its convolution ta…
sethforprivacy Nov 22, 2026
bfc321f
inkling2 metal: prompt chunks of up to 1,024 rows, which the host may…
sethforprivacy Nov 22, 2026
2d8f8c9
fixup: a stepped chunk is at most 256 rows beside other streams
sethforprivacy Nov 22, 2026
33f547d
inkling2 metal: on M5 the prompt kernel reads a tile's keys and value…
sethforprivacy Nov 22, 2026
8f3ca4b
inkling2 metal: wide chunks take the routed experts on turned tiles, …
sethforprivacy Nov 22, 2026
8d68ee7
inkling2 metal: the real-checkpoint serving tests draw the first toke…
sethforprivacy Nov 22, 2026
ec417ba
inkling2 metal dspark: the block attends on the tensor units, a chunk…
sethforprivacy Nov 22, 2026
27faf52
inkling2 metal: the prompt kernel keeps one set of sums in registers,…
sethforprivacy Nov 22, 2026
1259174
inkling2 metal: a convolution reads its old and new rows where they a…
sethforprivacy Nov 22, 2026
6d22d24
inkling2: one shared per-head kept-state walk, used by CUDA's prompt-…
jschmied Nov 23, 2026
f7e97de
inkling2: a shared DSpark lane host, one tokenBytes for the window fi…
jschmied Nov 23, 2026
df13524
Merge branch 'pr-4724' into local/shared
sethforprivacy Nov 23, 2026
155e9d0
inkling2 metal: the prompt-cache snapshot walks the shared kept state…
sethforprivacy Nov 23, 2026
7a4b861
inkling2 metal: the DSpark drafter is a backend of the shared lane ho…
sethforprivacy Nov 23, 2026
5f17fb0
lean: the grammar mask comment fits 120 columns
sethforprivacy Nov 23, 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 @@ -146,6 +146,10 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel
- Qwen3.8-27B on Metal with `TF_QWEN27_METAL_KV_PAGES=1`: Macs with tensor units (M5) take the flag instead of refusing it, and a paged prompt pass finds each 512-key chunk's two pages once instead of reading the page table at every 32-key step, with every token and cache row unchanged (#3180, part of #1293). Thanks to @CodingEmil.
- Nemotron 3.5 Lightning on HIP: the MTP head file is read at the width its own metadata states, so it drafts beside an oQ checkpoint of any width, and a head at a width the launches do not read is refused by name (#3251, part of #3061). Thanks to @gilby.

- Inkling 2 Mini (`inkling2_loop`) now serves natively on one CUDA rank and on Metal. CUDA runs the 48-visit text loop's cross-pass messages, rank-64 gates and separate sliding Q/K/V inputs with per-visit KV and convolution state, prompt snapshots and exact rollback; routed experts decode stored NVFP4 and MXFP8 weights to bf16 with the reference's rounding and ascending-expert FP32 accumulation, without activation quantization. Metal's default serving path stays unchanged, while opt-in DSpark drafting preserves target tokens and rolls back exactly. CUDA TP, vision and DSpark loading remain refused by name.

- Inkling 2 on CUDA: the family's grouped-expert launches match main's `tf_exl3_grouped_2` bit for bit under the kernel contract, and the vision tower's kernels pass gates 1 to 4 (refs #3476). Thanks to @ajensenwaud.

- Tests: the served-evidence concurrency test pairs its two generated streams in the fake server, so a busy runner can no longer decode them one after the other and turn it red; other conformance fixtures keep their pacing.

- GLM-5.3-Flash on CUDA at tensor-parallel widths where a rank's fused KDA input is not a multiple of eight columns (TP=3, 5, 6 or 7): the stack is padded at load to its own width rounded up to eight columns and stays row-major bf16, so prompt windows take the staged B16 tiles with every byte as before; `TF_GLM_KDA_PAD=1` still tiles the stack for glm_mm (#3697, for #3516). Thanks to @ultradaoto.
Expand Down
31 changes: 31 additions & 0 deletions THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,27 @@ those files. `tiny_config.json` and the tensor tables
`0a57c72e4e5b68aafe1d983dbb62980344a5fcd7`, a randomly initialised model whose model card names that release as its base
model and states no licence; no weights are included. `tools/zig/inkling2_fixtures.py` rebuilds all of these files.

## Inkling 2 Mini fixtures and loop references

`mini_config.json`, `mini_model_header.txt` and `mini_mtp_header.txt` in
`zig/src/families/inkling2/fixtures/` come from the 2026-11-20 published snapshot of
[thinkingmachines/Inkling-2-Mini at `ed40e7da625f594fc9c4990f5f66be24873c22d7`](https://huggingface.co/thinkingmachines/Inkling-2-Mini), under the Apache License 2.0
stated on its model card (see [the license text](LICENSES/Apache-2.0.txt)). The public model API supplied that full revision and last-modified time 2026-11-20T22:55:20Z. The fixture config differs from the supplied published `config.json` only by its explicit `_fixture_provenance` annotation; after excluding that annotation, every checkpoint config field matches. The folded tables contain only metadata from the model and MTP safetensors
headers, no tensor data or weights. `tools/zig/inkling2_fixtures.py` rebuilds all three from the Mini release, or from its
extracted headers, with the same revision annotation. No revision was derived from fixture digests.

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
specification. Its primary reference is huggingface/transformers PR #51050 at head `6173a2f6`: the Mini configuration and
forward pass in `models/inkling2_loop/modular_inkling2_loop.py` and `modeling_inkling2_loop.py`, with the temporary
NVFP4/MXFP8 expert dequantization in `core_model_loading.py` and the checkpoint mappings in `conversion_mapping.py`.
ModelOpt here names the checkpoint format and that Transformers arithmetic; no NVIDIA Model Optimizer source was used or
vendored. The specification also records Neywa-Labs/mlx-vlm at `fd6404fb` as its second reading of the loop and DSpark
implementation (`mlx_vlm/models/inkling2/` and `mlx_vlm/speculative/drafters/inkling2_dspark/`). Transformers is Apache-2.0;
mlx-vlm is MIT (see [`LICENSES/MIT.txt`](LICENSES/MIT.txt)). No reference source code is vendored. The supplied materials
give only these two abbreviated reference heads, not their full commit SHAs.

## Inkling 2 attention kernels

`zig/kernels/cuda/inkling2/attention.cu`, `zig/kernels/cuda/inkling2/prompt_attention.cu` and
Expand All @@ -572,3 +593,13 @@ these layers of Hugging Face transformers' `src/transformers/models/inkling2/mod
`Inkling2NormedEmbedding`, `Inkling2BlockAttentionResidual`, `Inkling2ShortConvolution`,
`Inkling2DynamicShortConvolution`, `Inkling2TopKRouter`, `Inkling2SoftcappedSwiGLU` and `Inkling2Softcap`. The kernels
are TensorFold's own.

## Inkling 2 expert and vision kernels

`zig/kernels/cuda/inkling2/experts.cu` and `zig/src/families/inkling2/experts.zig` run `Inkling2Experts` from Hugging
Face transformers' `src/transformers/models/inkling2/modeling_inkling2.py` at commit `109a7d19bf66`
([huggingface/transformers](https://github.com/huggingface/transformers), Apache-2.0) on main's EXL3 grouped-expert
arithmetic. `zig/kernels/cuda/inkling2/vision.cu` and `zig/src/families/inkling2/vision.zig` compute the same file's
vision tower: `Inkling2VisionEmbeddings`, `Inkling2VisionRotaryEmbedding`, `Inkling2VisionAttention`,
`Inkling2VisionMLP` and `Inkling2VisionMerger`. `zig/src/families/inkling2/image.zig` follows `Inkling2ImageProcessor`
in `image_processing_inkling2.py` at the same commit for its 40-pixel patches and the tower's input tables.
64 changes: 55 additions & 9 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 Inkling 2 Small release and tiny-random/inkling-2."""
"""Rebuild zig/src/families/inkling2/fixtures from the Small, tiny-random and Mini checkpoint inputs."""
import argparse
import hashlib
import json
Expand All @@ -10,6 +10,19 @@
FIXTURES = ROOT / "zig/src/families/inkling2/fixtures"
RELEASE = "thinkingmachines/Inkling-2-Small@2ad1157016e1aac77b6ff1b770e7c05229403134"
TINY = "tiny-random/inkling-2@0a57c72e4e5b68aafe1d983dbb62980344a5fcd7"
MINI_RELEASE = "thinkingmachines/Inkling-2-Mini"
MINI_REVISION = "ed40e7da625f594fc9c4990f5f66be24873c22d7"
MINI_PROVENANCE = {
"release": MINI_RELEASE,
"revision": MINI_REVISION,
"revision_status": "full revision supplied separately; every checkpoint config field matches",
"published": "2026-11-20",
"license": "apache-2.0",
}
MINI_HEADER_PROVENANCE = (
f"release={MINI_RELEASE} revision={MINI_REVISION} "
"published=2026-11-20 license=apache-2.0"
)
PINS = {"transformers": "5.20.0", "tokenizers": "0.23.3", "jinja2": "3.1.6"}
MERGES = 1500

Expand Down Expand Up @@ -46,13 +59,35 @@ def dump(value, depth=0):


def read_header(path):
"""The tensors of a safetensors file as {name: (dtype tag, shape)}, read from its first bytes only."""
with open(path, "rb") as f:
(length,) = struct.unpack("<Q", f.read(8))
meta = json.loads(f.read(length))
"""The tensors of a safetensors file or extracted JSON header as {name: (dtype tag, shape)}."""
if path.suffix == ".json":
meta = json.loads(path.read_text(encoding="utf-8"))
else:
with open(path, "rb") as f:
(length,) = struct.unpack("<Q", f.read(8))
meta = json.loads(f.read(length))
return {name: (v["dtype"], tuple(v["shape"])) for name, v in meta.items() if name != "__metadata__"}


def release_header(directory, stem):
"""Read the supplied extracted header when present, otherwise the release's safetensors file."""
extracted = directory / f"{stem}.header.json"
return read_header(extracted if extracted.is_file() else directory / f"{stem}.safetensors")


def annotated_mini_config(path):
"""The published config with explicit fixture provenance; no revision is inferred from its bytes."""
raw = path.read_bytes()
value = json.loads(raw)
if not isinstance(value, dict) or "_fixture_provenance" in value:
raise SystemExit(f"{path}: expected an unannotated config object")
provenance = json.dumps(MINI_PROVENANCE, ensure_ascii=False, indent=2).replace("\n", "\n ")
annotation = f' "_fixture_provenance": {provenance},\n'.encode("utf-8")
if not raw.startswith(b"{\n"):
raise SystemExit(f"{path}: expected the published indented config layout")
return raw.replace(b"{\n", b"{\n" + annotation, 1)


def spans(layers):
"""Layer numbers as comma-separated ranges, 0-3,5."""
layers = sorted(layers)
Expand All @@ -66,7 +101,7 @@ def spans(layers):
return ",".join(runs)


def fold(tag, tensors):
def fold(tag, tensors, provenance=""):
"""The table the host tests unfold: tag, count and sha256 of the sorted lines, then one line per name pattern."""
names = sorted(tensors)

Expand All @@ -85,7 +120,7 @@ def shape(dims):
parts[at[0]] = "{L}"
dtype, dims = tensors[name]
groups.setdefault((".".join(parts), dtype, shape(dims)), []).append(layer)
lines = [f"{tag} {len(names)} {digest}"]
lines = [f"{tag} {len(names)} {digest}" + (f" {provenance}" if provenance else "")]
for (pattern, dtype, dims), layers in sorted(groups.items()):
lines.append(f"{pattern} {dtype} {dims}" + ("" if layers == [None] else " " + spans(layers)))
return "\n".join(lines) + "\n"
Expand Down Expand Up @@ -152,7 +187,7 @@ def prompt_cases(release):
return {"reference": reference, "chat": chat, "raw": raw}


def build(release, tiny):
def build(release, 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 @@ -165,6 +200,13 @@ def build(release, tiny):
"prompt_cases.json": (dump(prompt_cases(release)) + "\n").encode("utf-8"),
"tiny_model_header.txt": fold("inkling2-tiny-model", read_header(tiny / "model.safetensors")).encode("utf-8"),
"tiny_mtp_header.txt": fold("inkling2-tiny-mtp", read_header(tiny / "mtp.safetensors")).encode("utf-8"),
"mini_config.json": annotated_mini_config(mini / "config.json"),
"mini_model_header.txt": fold(
"inkling2-mini-model", release_header(mini, "model-00001-of-00001"), MINI_HEADER_PROVENANCE
).encode("utf-8"),
"mini_mtp_header.txt": fold(
"inkling2-mini-mtp", release_header(mini, "mtp"), MINI_HEADER_PROVENANCE
).encode("utf-8"),
}


Expand All @@ -173,13 +215,17 @@ def main():
parser.add_argument("--release", type=Path, required=True,
help=f"{RELEASE}: config.json, chat_template.jinja, tokenizer.json, tokenizer_config.json")
parser.add_argument("--tiny", type=Path, required=True, help=f"{TINY}: config.json, model.safetensors, mtp.safetensors")
parser.add_argument(
"--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("--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)
files = build(args.release, args.tiny, args.mini)
differ = 0
if not args.check:
args.out.mkdir(parents=True, exist_ok=True)
Expand Down
1 change: 1 addition & 0 deletions zig/build/cuda_engines.zig
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub fn engines(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.bu
.{ .name = "gemma4_cuda", .module = @import("gemma4_cuda.zig").module(b, target, optimize, cuda, core, lanes) },
.{ .name = "spark25", .module = @import("spark25.zig").module(b, target, optimize, cuda, core, lanes) },
.{ .name = "lfm2_moe_cuda", .module = @import("lfm2_moe_cuda.zig").module(b, target, optimize, cuda, core, lanes) },
.{ .name = "inkling2", .module = @import("inkling2.zig").module(b, target, optimize, cuda, core, lanes) },
.{ .name = "dory", .module = @import("dory.zig").module(b, target, optimize, cuda, core, lanes) },
.{ .name = "dots_mocr_cuda", .module = @import("dots_mocr_cuda.zig").module(b, target, optimize, cuda, core, lanes, @import("cuda_dense.zig").module(b, target, optimize, cuda, core, lanes)) },
.{ .name = "muse_spark", .module = @import("muse.zig").moduleOver(b, target, optimize, cuda, core, lanes, @import("tp.zig").moduleWith(b, target, optimize, cuda, verbs)) },
Expand Down
4 changes: 4 additions & 0 deletions zig/build/cuda_kernels.zig
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ pub const kernels = [_]Kernel{
.{ .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_rows", .src = "inkling2/rows", .flags = glue }, // ours: Inkling 2's router row dots on prompt rows
.{ .name = "inkling2_experts", .src = "inkling2/experts", .flags = &.{ "-O3", "--expt-relaxed-constexpr" } }, // ours: Inkling 2's grouped experts
.{ .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
34 changes: 32 additions & 2 deletions zig/build/inkling2_host.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,44 @@ const std = @import("std");
fn module(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, root: []const u8) *std.Build.Module {
const m = b.createModule(.{ .root_source_file = b.path(root), .target = target, .optimize = optimize, .link_libc = true });
const dir = "zig/src/core/";
m.addImport("tokenizer", b.createModule(.{ .root_source_file = b.path(dir ++ "tokenizer/tokenizer.zig"), .target = target, .optimize = optimize, .link_libc = true }));
m.addImport("safetensors", b.createModule(.{ .root_source_file = b.path(dir ++ "safetensors.zig"), .target = target, .optimize = optimize, .link_libc = true }));
const tokenizer = b.createModule(.{ .root_source_file = b.path(dir ++ "tokenizer/tokenizer.zig"), .target = target, .optimize = optimize, .link_libc = true });
m.addImport("tokenizer", tokenizer);
const core = b.createModule(.{ .root_source_file = b.path(dir ++ "root.zig"), .target = target, .optimize = optimize, .link_libc = true });
core.addImport("gpu_memory", @import("gpu_memory.zig").module(b, target));
core.addImport("tokenizer", tokenizer);
core.addImport("living", b.createModule(.{ .root_source_file = b.path("zig/src/living/living.zig"), .target = target, .optimize = optimize, .link_libc = true }));
m.addImport("core", core);
m.addImport("template", b.createModule(.{ .root_source_file = b.path(dir ++ "template/template.zig"), .target = target, .optimize = optimize, .link_libc = true }));
m.addImport("inkling2_metal", b.createModule(.{ .root_source_file = b.path("zig/kernels/metal/inkling2_sources.zig"), .target = target, .optimize = optimize }));
const metal = b.createModule(.{ .root_source_file = b.path("zig/src/metal/metal.zig"), .target = target, .optimize = optimize });
if (target.result.os.tag == .macos) {
metal.linkFramework("Metal", .{});
metal.linkFramework("Foundation", .{});
metal.linkSystemLibrary("objc", .{});
}
m.addImport("metal", metal);
m.addImport("kernel_sources", b.createModule(.{ .root_source_file = b.path("zig/kernels/metal/sources.zig"), .target = target, .optimize = optimize }));
const inkling2_metal_ref = b.createModule(.{ .root_source_file = b.path("zig/src/families/inkling2/metal/ref.zig"), .target = target, .optimize = optimize });
inkling2_metal_ref.addImport("metal", m.import_table.get("metal").?);
m.addImport("inkling2_metal_ref", inkling2_metal_ref);
m.addImport("inkling2_glue_plan", b.createModule(.{ .root_source_file = b.path("zig/src/families/inkling2/metal/glue_plan.zig"), .target = target, .optimize = optimize }));
m.addImport("inkling2_loop_plan", b.createModule(.{ .root_source_file = b.path("zig/src/families/inkling2/metal/loop_plan.zig"), .target = target, .optimize = optimize }));
const lanes = b.createModule(.{ .root_source_file = b.path(dir ++ "lanes/lanes.zig"), .target = target, .optimize = optimize, .link_libc = true });
m.addImport("lanes", lanes);
m.addImport("engine_api", b.createModule(.{ .root_source_file = b.path(dir ++ "engine_api.zig"), .target = target, .optimize = optimize, .link_libc = true, .imports = &.{.{ .name = "lanes", .module = lanes }} }));
return m;
}

pub fn tests(b: *std.Build, target: std.Build.ResolvedTarget, test_step: *std.Build.Step) void {
const run = b.addRunArtifact(b.addTest(.{ .root_module = module(b, target, .Debug, "zig/src/families/inkling2/host_test.zig") }));
b.step("test-inkling2-host", "Inkling 2 family package: config, weight map, layer plan, chat template and tokenizer").dependOn(&run.step);
test_step.dependOn(&run.step);

const metal_run = b.addRunArtifact(b.addTest(.{ .root_module = module(b, target, .Debug, "zig/src/inkling2_metal_host_test.zig") }));
b.step("test-inkling2-metal-host", "Inkling 2 Mini Metal launch plans and arithmetic references").dependOn(&metal_run.step);
test_step.dependOn(&metal_run.step);
const native = b.addObject(.{ .name = "inkling2-native", .root_module = module(b, target, .Debug, "zig/inkling2_native_compile.zig") });
_ = native.getEmittedBin();
b.step("compile-inkling2-native-host", "Analyze the actual Inkling 2 Mini native opener without shaders or devices").dependOn(&native.step);
test_step.dependOn(&native.step);
}
Loading
Loading