Repository navigation
inkling2: host-only family package for Inkling 2 Small - #3578
Conversation
7b00db2 to
1e674fa
Compare
|
Thanks @Nipale-ai for a careful first slice. It is host-only, as the title says. Nothing outside the new directory calls it, no served path or default path changes, and the fixture provenance is well written up. A few things before it can go further:
|
|
Thanks for the review. All five points are answered below; the description is rewritten for the new head.
|
|
Thank you @Nipale-ai. The description now matches the reviewed head, the local header parser is gone in favour of core's reader, the unreachable refusal file moved out, the tokenizer generator is not part of the build, and the tiny files are unchanged as asked. The one red check,
|
Reads Inkling 2 Small's config.json into the shapes the engine needs and refuses by key every layout it does not run: the layer types, the fixed switches, the quantization, the draft head and the vision tower. Fixtures are the release's config.json and the tiny-random checkpoint's. The host step is test-inkling2-host.
Reads a safetensors header into entries of name, dtype and shape, sorted by name, for the dtypes this family stores: BF16, F32, F8_E4M3 and U8. A dtype it does not store, a rank past four, a length past the file and bad JSON are each refused.
The map names every tensor a config implies, backbone, vision tower and draft head, with its dtype and shape, and checks a safetensors header against it: missing, wrong and unknown tensors are reported by name. A layer's expert format is read from its tensors, U8 for NVFP4 and F8 for MXFP8. The plan derives sliding and global layers, the block boundaries and the number of states each attention-residual input sums over. The draft head's rnn_proj sizes and fuse_weight's columns are read from two headers, tiny-random/inkling-2 and the release, not from code; fuse_weight's six rows stay open. The fixtures fold the two header tables of tiny-random/inkling-2 with their sha256. Real headers are checked when TF_INKLING2_TINY names tiny-random's two files, and when TF_INKLING2_REAL names the release's 24 shard headers and mtp.safetensors.
Image parts (image, input_image, image_url) and --vision are refused with their own words until the vision tower has kernels; audio and unknown part types are refused too, and text parts, plain strings and string parts pass. A part without a type is read as text, as the chat template reads it. Nothing calls these checks yet: there is no host.
The release's chat template renders 24 chat cases byte for byte, thinking effort names and numbers included, and raises for an unknown effort or one out of range. The tokenizer encodes the rendered prompts and 6 plain texts to the reference's ids and decodes them back when TF_INKLING2_CKPT names the release's tokenizer.json. A cut tokenizer.json (its added tokens, its byte alphabet and the first 1,500 merges, same split regex) runs on every build against 14 cases, with a control that another split regex changes its ids. The expected prompts and ids come from the transformers and tokenizers libraries.
inkling2_fixtures.py writes the files under zig/src/families/inkling2/ fixtures from the release's files and the tiny-random checkpoint's safetensors headers: the prompt and id cases through transformers, the cut tokenizer and its cases through tokenizers, and the folded tensor tables with their sha256. The library versions are pinned and checked; --check compares the committed files without writing.
The notice for the files taken from the Inkling 2 Small release and from the tiny-random checkpoint.
refusal.zig and its test have no caller: the server that would call them is not in this slice. They move to the slice that adds the host. The step description and the package's test list no longer name them.
The AutoTokenizer.from_pretrained call in inkling2_fixtures.py takes local_files_only=True, so a mistyped --release fails instead of reaching the hub.
names.check and names.precisions take core/safetensors.zig's Header, read with its headerSize and parseHeader, in place of the family's own parser and dtype enum. header.zig and its test are gone, and the host test module imports the core reader. names.merge joins the headers of a checkpoint's files and refuses a name held twice.
ecb111a to
70e6d70
Compare
|
Thank you @Nipale-ai. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
Slice 1 of ashhart#4926, host only on the pattern of ashhart#3578: nothing is served and no kernel is added. - config.zig reads config.json through core/config_fields.zig and refuses, by key, a layout the engine does not run. Structural keys are held to the release's values in three groups, named in each refusal: keys the weight map follows, keys the vendor's plugin runs one way only, and keys whose meaning is not read yet. Sizes are read, not pinned; a small hand-written shape parses. Only the FP4 release (FP8 128x128 blocks with MXFP4 routed experts) is admitted. - names.zig expects every tensor of the 128 model shards, with dtype and shape, and checks them against safetensors headers: the folded table of the release's 140,457 tensors, edited copies (missing, retyped, reshaped and extra tensors by name) and, under TF_ERNIE55_HEADERS, the real shards. The optional FlashIndexer file is not in the map. - plan.zig derives each layer's attention (HCA or DSA), its feed-forward (dense or MoE), the HCA compress ratio and the draft head's layer count. - prompt.zig renders a user turn, an optional system turn, thinking on or off and the reasoning effort as the release's chat encoding does, with the request's byte spans, and encodes through the tokenizer core's encodeMasked, so request text never becomes a protocol token. It matches the release's text, spans and ids on 20 requests, with a cut tokenizer in CI and with the release's tokenizer under TF_ERNIE55_CKPT; it needs the anchors the previous commit adds. tools/zig/ernie5_5_fixtures.py rebuilds the five fixtures from the release's files, pinned by sha256, and its headers; --check compares them byte for byte.
Slice 1 of ashhart#4926, host only on the pattern of ashhart#3578: nothing is served and no kernel is added. - config.zig reads config.json through core/config_fields.zig and refuses, by key, a layout the engine does not run. Structural keys are held to the release's values in three groups, named in each refusal: keys the weight map follows, keys the vendor's plugin runs one way only, and keys whose meaning is not read yet. Sizes are read, not pinned; a small hand-written shape parses. Only the FP4 release (FP8 128x128 blocks with MXFP4 routed experts) is admitted. - names.zig expects every tensor of the 128 model shards, with dtype and shape, and checks them against safetensors headers: the folded table of the release's 140,457 tensors, edited copies (missing, retyped, reshaped and extra tensors by name) and, under TF_ERNIE55_HEADERS, the real shards. The optional FlashIndexer file is not in the map. - plan.zig derives each layer's attention (HCA or DSA), its feed-forward (dense or MoE), the HCA compress ratio and the draft head's layer count. - prompt.zig renders a user turn, an optional system turn, thinking on or off and the reasoning effort as the release's chat encoding does, with the request's byte spans, and encodes through the tokenizer core's encodeMasked, so request text never becomes a protocol token. It matches the release's text, spans and ids on 20 requests, with a cut tokenizer in CI and with the release's tokenizer under TF_ERNIE55_CKPT; it needs the anchors the previous commit adds. tools/zig/ernie5_5_fixtures.py rebuilds the five fixtures from the release's files, pinned by sha256, and its headers; --check compares them byte for byte.
What this changes
Host-only family package for Inkling 2 Small (
thinkingmachines/Inkling-2-Small, Apache-2.0): config parsing, which refuses layouts the engine does not run, the weight map checked against the release's safetensors headers (read withcore/safetensors.zig), the layer plan, the chat template and tokenizer checked against the reference's ids, and fixtures. No kernels, no CUDA or Metal code, no host: nothing is served.It is slice 1 of the six in #3476 (host only, original checkpoint first), with no EXL3 and no prototype code. Of the four parts named in the answer on the issue (config parse, weight map, fixtures, refusals), this pull request holds the first three. The refusals of image parts, audio parts and
--visionare not in it:refusal.zigand its test are removed by the commitinkling2: take the refusals out of this slice, and they belong to the slice that adds the host, where the server calls them. It holds three parts beyond those named, so the review can weigh them:The chat template and tokenizer checks (
prompt.zig,template_test.zig,tokenizer_test.zigand four fixtures). Slice 1 of the proposal named them. They show that the template core and the tokenizer core give the reference's prompts and ids. Thefloatfilter they needed is on main (template: add the float filter #3577).The layer plan (
plan.zig). The weight map reads each layer's expert format through it, and it derives the block boundaries and the attention-residual sources from the config, so later slices start from tables that are checked on the tiny and the release config.tools/zig/inkling2_fixtures.py, which rebuilds all eight fixture files from the release and the tiny checkpoint, so a reviewer can check them.If you would rather have any of these as a follow-up pull request, I will split it out.
Issue: Refs Inkling 2 Small on four DGX Sparks: a native CUDA family #3476. Slice 1 of 6; one rank on the tiny checkpoint, the routed experts and four ranks, the drafter, prompt cache and snapshots, and the vision tower are not in this pull request.
Base: main at
af9777b49, which contains thefloatfilter (template: add the float filter #3577, merged); this pull request adds the ten commits listed bygit log af9777b49..ecb111a75: the seven of the previous head1e674fa15, unchanged (git range-diff af9777b49..1e674fa15 af9777b49..ecb111a75shows seven=pairs), and three new ones for the review of 2026-11-18:inkling2: take the refusals out of this slice,tools: load the release's tokenizer from local files onlyandinkling2: read safetensors headers with the core reader. Againstaf9777b49the head changes 21 files, 2241 insertions.Merge with main: on 2026-11-18 at 23:05 UTC,
git merge-tree --write-treeof this head with main at0900b484eends with exit 0 and prints a tree without a conflict.atc overlap --json(atc 0.9.6, withATC_READ_ONLY=1), run in this tree on 2026-11-18 at 23:07 UTC, baseorigin/mainat0900b484e, this headecb111a75:complete: false(otherPullRequestsLimit,pullFilesUnavailable,pullRequestsLimit,timeLimit), 7 overlaps with other pull requests (dsv41 metal: image prompts #1722, qwen27: serve the 27B pair, refuse what a pair cannot keep, and die with the peer #1434, ricursive: serve Ripple-65B on two GB10s with up to 1M tokens of context #2522, qwen3-asr: host slice, the shared tower and Qwen3 schedules over a backend binding (#2105) #2239, idol: Idol's denoiser on CUDA (stacked on #1766) #1767, idol: Idol's denoiser as a native Metal family #1766, Native Vulkan backend for Qwen3.5-2B (opt-in): engine and kernel-contract registration (stacked on #1526) #1544), all 7clean, 0 conflicts; the list is incomplete (the limits above).Parts of the lane core and fabric this slice adapts: none. It touches neither
zig/src/core/lanes/norzig/src/fabric/and adds no scheduler or round loop. Each block of the host table indocs/recipes/adding-a-zig-family.md:core/template: used. One filter was missing, added in template: add the float filter #3577.core/tokenizer: used unchanged. Its split regex with(?i:...),\p{M}and lookahead gives the reference's ids.core/safetensors.zig: used for the headers, throughheaderSize(line 8),parseHeader(line 65),DType(line 13) andHeader. The package has no parser or dtype enum of its own. Three things differ from the reader the package had before: the core reader accepts ranks up to five (max_rank, line 47; the package's own accepted four), it knows sixteen dtypes where the package's enum had four, so a tensor in another of those sixteen dtypes now parses andnames.checkreports it as wrong or unknown instead of the parse failing, and it checks each tensor's byte count against its dtype and shape and that no two byte ranges overlap (lines 110 to 135). The tests read only the first bytes of each file (header-only copies of the release's shards, the whole tiny files), so they callparseHeaderwith the data lengthmaxInt(usize)and the check of an entry's end against the file size does not apply to them.Metadata.read(line 187) is not used: it checks the entries against the real file size (lines 198 and 120), and the real-header tests read only the first bytes of the shards.core/modelopt.zig: not used.admitrequiresconfig_groups, which this config.json does not have (it carriesquant_methodandquant_algoonly), soconfig.zigchecks that itself. Reading the packed experts and the MXFP8 layers is a later slice and will extend the shared reader. The release's headers show the MXFP8 scales as one per row and 32 inputs ([384, 4608, 144]for thew13_weight_scaleof layer 40), while itshf_quant_config.jsonnamesweight_block_shape [32, 32]for its MXFP8 group (the 16 tensors from thew13_weightof layer 40 on; the NVFP4 group has[1, 16]); the map follows the tensors.lanes/engine.zig,lanes/backend.zig,lanes/drafter.zig,lane_host.zig,engine_api.zig,kv_pool.zig,prompt_cache.zig,checkpoint_direct.zig: not used. There is no forward and no host yet.lanes/drafted.zig,lanes/solo_chunk.zig,kv_ledger.zig,prompt_radix.zig,prompt_tail.zig,recurrent_workspace.zig: not used, for the same reason: there is no forward and no host yet.direct_gather.zig,affine4_host.zig,gguf.zig: not used. The host reads no weights yet, and the stored formats are BF16, NVFP4 and MXFP8, not MLX affine or GGUF.rope_yarn.zig: not used. The backbone's attention takes a relative logit bias in place of RoPE.inkling2entry is added to the host tables (thefamilieslists of the native hosts:metal.zig,cuda_families.zig,hip.zigandxpu.zigunderzig/src/native/), because there is no host to open.Callers of
prompt.zigandplan.zig: nothing outside the tests calls them yet, and the attention reference and decode kernel announced on #3476 use neither. The next slice, one rank on the tiny checkpoint, would callplan.buildfrom its layer loop for each layer's kind, block boundary and attention-residual source counts, andprompt.renderandprompt.encodefrom its token check, to turn a prompt into ids. If you would rather have them move to that slice, I will move them.What the package contains:
config.zigrefuses a layout the engine does not run, by key (every sixth layer global, withlocal_layer_idsrequired to agree; ModelOpt NVFP4 only;sconv_kernel_size4; no shared experts; no q, o or projector biases, a router bias; untied embeddings; a draft head with arnn_hiddenMarkov head, the backbone's width and listed layers; a vision tower with a wholemlp_ratioof at most 1024, heads that divide its width and no projector bias).names.zigexpects every tensor's name, dtype and shape for the backbone, the vision tower and the draft head and checks them against safetensors headers: missing, wrong and unknown tensors are reported by name;names.mergejoins the headers of a checkpoint's several files and refuses a name held twice. A layer's expert format (U8 is NVFP4, F8 is MXFP8) is read from its tensors.plan.zigderives local or global layers, block boundaries and the number of attention-residual sources. The draft head'srnn_projsizes and the columns offuse_weightfollow from the headers of tiny-random and the release; its six rows stay open. The expected prompts and ids are rebuilt bytools/zig/inkling2_fixtures.py, which loads the release's tokenizer withlocal_files_only=True, so a mistyped--releasefails instead of reaching the hub.Checks on this head
ecb111a75on mainaf9777b49. Every number below comes from runs on one Mac, on this head or on the commit it names; what could not run there is listed under "Not run".python3 tools/zig/lean_check.py, on the baseaf9777b49and on this head: 221 and 221 problems, 0 new (tools/zig/lean_new.py). The same against main0900b484e: 221 and 221, 0 new. The previous head1e674fa15also has 221. The largest source file of the package isconfig.zigwith 375 lines (limit 600).xcrun metal --version: Apple metal version 32023.922).zig build test-inkling2-host -Dcpu=apple_m1 --summary all, each commit with its own empty build cache directory:TF_INKLING2_TINYandTF_INKLING2_REAL, two tokenizer tests needTF_INKLING2_CKPT).TF_INKLING2_TINY=<tiny-random/inkling-2 at 0a57c72e4e5b68aafe1d983dbb62980344a5fcd7, its two safetensors files>,TF_INKLING2_REAL=<the release at 2ad1157016e1aac77b6ff1b770e7c05229403134, the first bytes (the header) of its 24 shards and of mtp.safetensors>andTF_INKLING2_CKPT=<a folder with the release's tokenizer.json>: 3 of 3 steps, 28 of 28 tests passed. The tiny files, the release'sconfig.json,chat_template.jinja,tokenizer.jsonandtokenizer_config.jsonequal the files of those revisions on the hub (git blob sha1, or sha256 for the LFS files).1e674fa15: 29 of 33 (4 skipped) and 33 of 33;inkling2: take the refusals out of this slice: 25 of 29 (4 skipped) and 29 of 29;tools: load the release's tokenizer from local files only: 25 of 29 (4 skipped) and 29 of 29;inkling2: read safetensors headers with the core reader: 24 of 28 (4 skipped) and 28 of 28.zig fmt --check build.zig zigandgit diff --checkon each of the four: exit 0. The seven commits up to and including1e674fa15are unchanged (range-diff); I did not run them one by one again.header_test.zig's three are gone and two tests are new (29 to 28), one for a header from core's reader fed to the map, one fornames.merge.names.mergeaccepting a name held twice (1 test fails); the rank not compared innames.check(1 test crashes); the dtype not compared (2 fail); unknown tensors not reported (2 crash); U8 read as MXFP8 innames.precisions(3 fail). I did not rerun the earlier planted controls of the first seven commits on this head.python3 tools/zig/inkling2_fixtures.py --release <release files> --tiny <tiny-random files> --check: 8 of 8 files the same, with transformers 5.20.0, tokenizers 0.23.3 and jinja2 3.1.6 (the script exits if the versions differ), before and after thelocal_files_only=Truechange.zig fmt --check build.zig zig: exit 0.git diff --check af9777b49..ecb111a75: exit 0.python3 tools/pr_check.py --base origin/main: 0 errors, 1 warning (--pr NUMBERwas not given, so the Unreleased line is not checked); with--pr 3578: 0 errors, 1 warning (no Unreleased bullet names this pull request). This change carries no CHANGELOG line; given a pull request number,pr_checkreports that as a warning (tools/pr_check.pylines 88 to 91).--cache-dir) for all of the commands below:zig build test test-golden -Dcpu=apple_m1 --summary all: exit 0, 892 of 892 steps succeeded, 14863 of 14987 tests passed, 124 skipped; thetest-goldenstep succeeded; none of the 360 test run steps in it was cached. Then in the same directory, so steps whose inputs had not changed show as cached in their logs and were not run again:zig build dev-tools -Doptimize=Debug: 269 of 269 steps succeeded.zig build -Dfixed-cpu dev-tools: 269 of 269.zig build -Dfixed-cpu check-release-paths: 68 of 68.zig build native -Dcpu=apple_m1 -Dversion=1.0.0: 66 of 66. Plainzig build: 297 of 297.zig build test-cuda-host: 418 of 418 steps succeeded, 956 of 958 tests passed, 2 skipped (154 of its 186 test run steps were cached from thetestrun and are not counted in those numbers).zig build fuzz-cortheon: 3 of 3 steps, 24 of 24 tests passed.python3 tools/zig/nfkd_tables.py --checkwith the Zig 0.17.0 binary on the PATH: exit 0.ecb111a75: 8 of 9 jobs pass (fmt,pytest,zig,zig-b,zig-macos-dev-tools,zig-windows,release-paths,benchmark-clients (windows-latest)).benchmark-clients (ubuntu-latest)fails in one test,test_ttft_starts_at_content_not_headers_role_or_final_usageintools/tests/test_bench_cache_agents.py. This pull request does not touch that file or the benchmark client, and the same test passes in the windows job of the same run. I can't rerun the job from the fork.zig build -Dfixed-cpu test-host --test-timeout 20m(the aggregate is registered for native Linux only),test-kernel-contract,test-goldenandzig build -Dfixed-cpu teston Linux; the Python checks of the previous description (python -m pytestfrom the root,cuda_common_check.py,cuda_fragment_check.pyand its test,flashnext_batch_serve_test.py;build_options_test.pydid run on this head on macOS and ended with exit 0, andhost_tests_test.pyran there with all 13 of its tests skipped); everything on CUDA or a GPU (no GPU code is in this pull request);test-gradient-serving, which main excludes fromtest-host(CI never reaches 246 of the 393 named test steps, and nine of them fail on main #2031,zig/build/host_tests.zigline 27); a model or checkpoint check on Metal (this pull request adds no Metal code); the Windows job.Receipt
n/a: no inference, no kernel, no host. The package is not called by the server.
ecb111a75, Zig 0.17.0, macOS on an Apple M5 Ultra, CPU only, no weights loaded. Releasethinkingmachines/Inkling-2-Smallat2ad1157016e1aac77b6ff1b770e7c05229403134for config, chat template,tokenizer.jsonand the safetensors headers;tiny-random/inkling-2at0a57c72e4e5b68aafe1d983dbb62980344a5fcd7for its config and two headers.mtp.safetensorsare read with core'sparseHeader; the test asserts 1770 expected tensors for the shards and 84 formtp.safetensors, with nothing missing, wrong or unknown. Routed-expert format per layer, read from the tensors and asserted by the test: layers 0 to 39 NVFP4 (packed U8 weights, F8_E4M3 scales over groups of 16), layers 40 to 47 MXFP8 (F8_E4M3 weights, U8 scales over 32 inputs). Only the safetensors headers were read, no weights.\r\n, marker text in the user text) and 6 raw cases: prompts, ids and decoded text equal with the realtokenizer.json(the tokenizer tests withTF_INKLING2_CKPTpass in the 28 of 28 above). The always-running test uses a cuttokenizer.json(added tokens, byte alphabet, the first 1500 merges, same split regex) against 14 cases from the reference library.tools/zig/inkling2_fixtures.pyregenerates all eight fixture files;--checkfinds them the same.prompt.renderreads an effort given as text as a number only when it is a plain finite decimal (digits, sign, point, exponent). Other text, such asnan,inf,0x1p-1or0.5_5, goes in as a string, which the template looks up by name ineffort_map(the names are accepted, anything else is refused as unknown), as the reference does for a string: the template callsfloatonly on a value that is not a string.add_generation_prompthas no effect in this template, as in the reference.license: apache-2.0(README.mdline 2 at the revision above); itsconfig.json,chat_template.jinja, the cuttokenizer.jsonand the case files are listed inTHIRD_PARTY_NOTICES.mdunder that licence. The model card oftiny-random/inkling-2names the release as its base model and states no licence; its config and two header tables are included on that footing and are left as they are, as the review asks. No weights are included.Checklist