Skip to content

Add Inkling 2 model - #2061

Draft
jundot wants to merge 6 commits into
ml-explore:mainfrom
jundot:inkling2
Draft

jundot wants to merge 6 commits into
ml-explore:mainfrom
jundot:inkling2

Conversation

@jundot

@jundot jundot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor
  • ☑️ I understand it is strictly prohibited to use AI to write PR description
  • AI usage disclosure: help write the model code, kernels and tests.

* This is a draft because of the open PR limit. I will mark it ready for review once my other open PRs are merged.

Text and image input. The published NVFP4 checkpoint loads as is, and tensor and pipeline parallel work. DSpark is not included.

Images and kernels follow the same structure as Muse Spark Open. The image processor and the kernels are in the inkling2 package.

Two new kernels. relative_attention is the prefill attention with the relative position bias and the per-token sink, which MLX SDPA does not take. depth_attention mixes the attention residual blocks. Without them the model runs plain MLX ops.

M3 Ultra with 512 GB. Each number is the mean of two runs with 128 generated tokens.

Context Prompt tok/s, kernels off Prompt tok/s, kernels on Change Generation tok/s, kernels off Generation tok/s, kernels on Change
4k 342.4 478.1 +40% 19.9 21.2 +7%
16k 294.3 468.9 +59% 19.4 20.7 +7%

Without the kernels the 16k prefill also takes 24 GB more memory.

Benchmark script

The kernels are off when inkling2.layers._use_kernels returns False. The prompt text is Moby-Dick from Project Gutenberg.

import sys

import mlx.core as mx
from mlx_lm import load, stream_generate
from mlx_lm.models import inkling2
from mlx_lm.sample_utils import make_sampler

model, tokenizer = load(sys.argv[1])
ids = tokenizer.encode(open(sys.argv[2]).read())
sampler = make_sampler(temp=1.0, top_p=0.95, top_k=20)
use_kernels = inkling2.layers._use_kernels


def run(prompt, max_tokens):
    for r in stream_generate(
        model, tokenizer, prompt, max_tokens=max_tokens, sampler=sampler
    ):
        pass
    return r


for context in (4096, 16384):
    prompt = (ids * (context // len(ids) + 1))[:context]
    for kernels in (False, True):
        inkling2.layers._use_kernels = use_kernels if kernels else (lambda: False)
        for _ in range(2):
            run(ids[:256], 1)
            mx.reset_peak_memory()
            r = run(prompt, 128)
            print(
                context,
                "on" if kernels else "off",
                f"prompt {r.prompt_tps:.1f} tok/s",
                f"generation {r.generation_tps:.2f} tok/s",
                f"peak {r.peak_memory:.1f} GB",
            )
curl -L -o moby.txt https://www.gutenberg.org/ebooks/2701.txt.utf-8
python bench_inkling2.py thinkingmachines/Inkling-2-Small moby.txt

Model information

Supported checkpoints

Verification

mlx_lm.generate --model thinkingmachines/Inkling-2-Small -p "The secret to baking a good cake is" -m 1024
==========
<|message_model|><|content_thinking|>The user gives an incomplete sentence: "The secret to baking a good cake is". They likely want completion. Need answer helpfully. Could be open-ended. Need provide concise but useful answer. Need not overthink. We can say: there isn't one secret, but key is accurate measuring, room-temp ingredients, not overmixing, proper oven temp, and letting it cool. Maybe phrase as completion: "...understanding your ingredients and treating them gently." Provide practical tips.

Need ensure no hidden trick? It might be a prompt expecting a specific phrase? "The secret to baking a good cake is" maybe from some quote? Could be "love"? But as coding assistant? No, general. We can answer with culinary guidance.

Need final only. Keep moderate detail.<|end_message|><|message_model|><|content_text|>There isn’t one single secret—but if you want the closest thing to it, it’s **precision plus restraint**: measure accurately, use room-temperature ingredients, don’t overmix the batter, and bake at the right temperature without opening the oven too early.

A few practical keys:
- **Measure flour correctly** (spoon and level, or weigh it).
- **Cream butter and sugar well** for structure and lightness.
- **Mix just until combined** once flour is added.
- **Use fresh leavening** (baking powder/soda).
- **Don’t overbake**—start checking early.
- **Let it cool properly** before frosting or slicing.

If you want a one-line completion: *“The secret to baking a good cake is respecting the chemistry—and not rushing it.”*<|end_message|>
==========
Prompt: 23 tokens, 2.272 tokens-per-sec
Generation: 365 tokens, 21.499 tokens-per-sec
Peak memory: 390.401 GB

jundot and others added 5 commits November 13, 2026 15:18
Text and image input, with Metal kernels for the prefill attention and the attention residuals. The published checkpoint loads as is, and tensor and pipeline parallel work.
Split the model file into config, layers, vision, checkpoint and model modules, and move the processor and the two kernels into the package. The processor now returns a dict of inputs, as load_processor expects, and the image rows use the shared splice. The model code is otherwise unchanged.
@jundot

jundot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Updated this PR for the new models layout in #2082. I moved Inkling 2 into a package with config, layers, vision, checkpoint, model, kernels and processor modules.

The processor now returns a dict of inputs, and the image rows use the shared splice. The model code is otherwise unchanged.

The public checkpoints declare their quantization, so load_model sets up the experts and sanitize only maps the tensors. load_model also reads fp8 with 1x32 ue8m0 blocks as mxfp8, as in Inkling-2-Small-MXFP8.
@jundot

jundot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

The experts now load through load_model, since the public checkpoints declare their quantization. Sanitize only maps the tensors.

load_model also reads fp8 with 1x32 ue8m0 blocks as mxfp8, which Inkling-2-Small-MXFP8 uses.

This branch has not been deployed

No deployments
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.

2 participants