Skip to content

Inkling 2, phase 1: the file format and a reference forward pass, checked on the real model (#974) - #981

Draft
mrsirg97-rgb wants to merge 1 commit into
mw00:mainfrom
mrsirg97-rgb:inkling2-phase1
Draft

mrsirg97-rgb wants to merge 1 commit into
mw00:mainfrom
mrsirg97-rgb:inkling2-phase1

Conversation

@mrsirg97-rgb

Copy link
Copy Markdown
Contributor

For #974. This is the groundwork for an Inkling-2-Small engine, done the way GLM's started (docs/GLM5-FLASH.md's phase
1: the format, ref/glm.py, a tiny test model): it does not run Inkling in Maya yet - no kernels, no engine. It
pins down exactly what an engine has to compute and checks it against transformers, so the kernels can be written
against it a step at a time.

What's in it

  • tools/inkling2_gguf.py - the checkpoint as an inkling2 GGUF in the layout of llama.cpp's Inkling 2
    conversion (model : add Inkling 2 (stacked on Inkling 1) ggml-org/llama.cpp#32187, draft), which is what unsloth/Inkling-2-Small-GGUF ships, so an engine
    that reads it reads unsloth's files too. Written from that PR's conversion; its code is not copied or run here.
    The experts keep their original bits (NVFP4 with a scale per expert; layers 40-47's MXFP8 as exact BF16).
    Against unsloth's UD-IQ1_S:
    • --plan --against: the same 1,260 tensors, name for name and shape for shape; F32 in the same places; every
      inkling2.* key the same value.
    • The 653 tensors unsloth keeps in F32 that the checkpoint holds as such (the folded short convs, norms, clip
      scales, relative projections, residual queries, the router and its bias, the experts' scales): bit-equal to
      unsloth's bytes.
  • ref/inkling2.py - the forward pass over any inkling2 GGUF in float64, in ref/glm.py's conventions, with
    each step a kernel produces recorded under a name (--dump-dir). Its docstring is the forward written out.
  • ref/load.py - reads NVFP4 and the IQ types unsloth's quants use (block sizes checked against gguf-py's).
  • tests/inkling2_ref_test.py - a small random Inkling 2 built by transformers, written as the checkpoint
    (NVFP4 and MXFP8 experts, BF16 dense), converted, read back by the reference: over 300 tokens (past the window,
    the relative extent and the log-scaling floor) max |dlogp| 6.4e-6, max KL 1.6e-12, top-1 100%. 4 s. Each of
    these breaks fails it: the dynamic conv's taps in the wrong order, the sink dropped, the log scaling dropped, an
    expert's scale dropped, the stream not restarted at a block boundary, the residual norm's eps, the window off by
    one, the selection bias in the weights.
  • tests/inkling2_real_check.py - the real model (below).
  • docs/INKLING2.md - the model, the format's conventions a kernel has to follow (the conv folds, the expert
    scales, the residual queries), what maps onto Maya's engines and what's new, memory.

On the real model

The real Inkling-2-Small converted (11 files, 484 GB, as unsloth's BF16), through the reference, against
transformers' own decoder layers over the original checkpoint (fp32 on one RTX 5090, every expert decoded from the
checkpoint's bits), 256 tokens, all 48 layers:

transformers, the checkpoint ref/inkling2.py, the GGUF
perplexity (the next token right: 61.2%) 3.597 3.597
max |dlogp| against transformers 4.7e-5
KL, mean / max 2.6e-12 / 1.4e-11
the same top-1 token 100% of positions

transformers' greedy answer on the same weights to "In two sentences: why does a short convolution before attention
help a language model?" (thinking effort none, cut at 32 tokens):

A short convolution before attention helps a language model by capturing local patterns and nearby token
relationships that attention might otherwise miss. This gives the model a stronger

What it needs

transformers' main with inkling2 (from 109a7d19bf; no release has it yet - the tests skip without it) and gguf-py
with NVFP4 (llama.cpp's). No build change; nothing in src/ changes.

Next

The kernels for what's new to Maya (the attention's relative bias, sinks and clips; the short convs; the attention
residuals; the expert scale with the softcapped SwiGLU), each checked against the reference's recorded steps, then
the engine. Happy to take those on, or to leave it here as a base if you'd rather build it yourself.

…cked on the real model (mw00#974)

tools/inkling2_gguf.py writes the checkpoint in the layout of llama.cpp's
Inkling 2 conversion (ggml-org/llama.cpp#32187), what unsloth's GGUFs ship:
the same 1,260 tensors and keys as their UD-IQ1_S, 653 F32 tensors bit-equal.
ref/inkling2.py is the forward over any inkling2 GGUF in float64, each step
recorded. Against transformers: a small random model within 6.4e-6, the real
model (256 tokens, all 48 layers) within KL 1.4e-11, the same top-1 token at
every position. ref/load.py reads NVFP4 and unsloth's IQ types.
docs/INKLING2.md: the model, the format's conventions, what maps onto Maya.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant