Skip to content

Inkling 2: image input, a streaming tool guard, branch checkpoints (second follow-up to #401) - #405

Closed
data-angel wants to merge 7 commits into
Atlas-Inf:mainfrom
Enntity:inkling2/images-and-serving-20261123
Closed

data-angel wants to merge 7 commits into
Atlas-Inf:mainfrom
Enntity:inkling2/images-and-serving-20261123

Conversation

@data-angel

@data-angel data-angel commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Second follow-up to #401. With #401 and #404 merged, this branch carries a merge of main at 7a717b659, so the
diff here is only this PR: six commits. The first five are the engine SparkInkling 0.4.1 shipped (6cf40a5a0); the
sixth (1a3675294) makes streamed tool calls something a request has to ask for, and is in SparkInkling 0.4.2.
Happy to split it further if you want one change per PR: the commits are independent, except that the sixth builds
on the stream setting.

What

Image input (6cf40a5a0)

The checkpoint's vision tower (model.visual.*, transformers Inkling2VisionModel) as a third VisionTower
(spark-model/src/inkling2_vision.rs), on the shared vision_encoder kernels (the nemotron file, symlinked):

  • vision_config (inkling2_vision) parses to a VisionConfig with a new is_inkling2 marker. The image token is
    the processor's <|unused_200054|>; the template writes one per image and expand_vision_pads repeats it.
  • Preprocessing (vision_preprocess/inkling2.rs) follows Inkling2ImageProcessor: no resize, the image padded to
    40x40 pixel tiles (padding -1 on the 0-255 scale, alpha on the 204/153 checkerboard), one token per tile. One
    deviation: an image of more tiles than the encoder holds (derive_max_patches) is scaled down first. Video is
    refused.
  • The tower: Linear patch embed, CLS token, the learned 32x32 position table resampled bilinearly per image,
    pre-LayerNorm, 23 blocks with axial 2D RoPE on Q/K and layer scale, then a bias-free projector over each 2x2
    block of patch states. The kernels rotate channel pairs (d, d + D/2) and know no layer scale, so at load the
    q/k rows are permuted per head from the reference's interleaved pairs and layer scale is folded into out_proj
    and c_proj.
  • Embedding norm: the reference norms token embeddings inside the embedding and scatters image features in after
    it. The first visit normed its whole input, image rows included. The table is now normed once at load, in place,
    with the same kernel and epsilon, and no visit norms; the drafter's anchor row skips its copy of that norm.
  • On one GB10 (Strict, development build): tower output against the transformers implementation on a 760x300
    text image (152 tokens): mean row norm 5.437 vs 5.432 (float32), sampled values within 0.003; an invoice image
    transcribed exactly; greedy text of three text prompts byte-identical to before the norm moved.

A streaming tool guard, on request (887d17894, 1a3675294)

  • --tool-guard stream (any model; default unchanged): the guard checks each call at its end, as on does, but for
    a request that asks, the call's header and arguments go out as they are written. A call it blocks, or one the
    response cuts off, ends that response content_filter (not tool_calls) with
    atlas_tool_guard::STREAMED_REFUSAL, which says part of the call streamed and that it must not run.
  • A request asks with the body field stream_tool_arguments: true, an Atlas extension on /v1/chat/completions.
    Without it the call is held and the response is the same as under --tool-guard on, so a client that does not
    read content_filter never receives a blocked call. Under on and off the field is accepted and ignored. This
    covers the generic stream path and the Poolside v1 string-argument path; a working-directory hint,
    ATLAS_BUFFER_TOOL_ARGS and tool retry still hold a call as before.
  • As first proposed here (887d17894 alone), stream streamed every request's calls; a client that ignored the
    finish reason could have run a call the guard blocked. 1a3675294 closes that.

Branch checkpoints for aux-state models (f4684808c)

pc_plan_branch returned early for a model with no SSM layers, so ATLAS_GLM_PC_BRANCH never planted a checkpoint
for Inkling, whose prefix hits resume from its short-conv state on the same snapshots. It now gates on
snapshot_prefix_state(), as the prefix lookup does (identical for SSM models).

  • Branch checkpoints for a client that rebuilds its last messages every turn (a voice rig: system, history, three
    trailing user blocks re-rendered each turn): each user turn diverged ~500-700 tokens before the previous prompt's
    end and replayed from the cold prefill's chunk boundary (4.1-5.1K tokens). With ATLAS_GLM_PC_BRANCH=1,
    ATLAS_GLM_PC_BRANCH_MIN=512, observed on one GB10 (Strict, 16.4-17.4K-token prompts, 8 turns, single run):
    user-turn TTFT 1.33-1.73 s -> 0.61-0.82 s, follow-ups unchanged.
    Short-prompt C4 / C8 aggregate: 77.3 / 112.7 with the split on every prompt, 80.0 / 118.4 with the rule,
    79.4 / 117.1 with the cache off.
  • kv_nvme: the disk tier restores KV only up to a snapshot anchor for any model with per-sequence state, not only
    SSM models (before, an aux-only model would have restored the whole on-disk run over stale conv state).

Checked on one GB10: a 7.5K-token prompt replayed at TTFT 0.11-0.14 s against 2.3-2.6 s cold, greedy text
byte-identical, DSpark and concurrent requests included; with the disk tier (pool held to 5,373 blocks, ~20K-token
conversations pushed out by five others) a returning conversation restored 1,237 blocks in 403 ms and resumed at its
token-19,776 snapshot, TTFT 5.82 s -> 0.90 s, answer identical to the tier-off run.

A call written with no block header (be99fe2ce)

tool_choice required (or a named function) constrains the output to the Hermes grammar, so the model writes
<tool_call> text with no Inkling block header. The turn rewrite passed that through without the think end, so a
streamed request with thinking on read the call as reasoning and the in-think leak guard cut the response (finish
length, guard in_think_tool_leak). Text between blocks now closes the reasoning first, as a text block does.

Fused Strict projections (8ff871196)

  • With BF16 projections (Strict), a visit's input projections (q, k, v, relative bias, gate, sinks, dynamic conv
    taps: six to eight small GEMVs) run as one inkling2_proj_gemv launch over a per-visit device table, each output
    row the chain dense_gemv_bf16_batchm computes (its body now takes the block index). Plain Strict decode, one
    GB10, greedy text and concurrency hashes identical: C1 35.9 -> 36.4 tok/s, aggregate C8 115-118 -> 118-120.

Changes outside the Inkling files

  • atlas-tool-guard: Policy::stream and STREAMED_REFUSAL; --tool-guard accepts stream. off and on are
    unchanged and off stays the default.
  • Requests: stream_tool_arguments on the OpenAI chat request and the IR request (false from the Anthropic and
    Responses paths); StreamCtx::streams_tool_calls decides per request.
  • VisionConfig::is_inkling2 (false in every existing literal); VisionTower::Inkling2; image_pad_token_id() also
    resolves Inkling's image token; a video part is refused for this tower.
  • pc_plan_branch's gate, above. dense_gemv_bf16_batchm's body takes the block index (the entry passes
    blockIdx.x).
  • No new ATLAS_* names.

Benchmarks

RigMark protocol 1.1.0 on one GB10, the first five commits (6cf40a5a0) built into the SparkInkling 0.4.1 image (default profile, DSpark with
ATLAS_DFLASH_BATCH_DEPTH=1:7,1000000:0 and ATLAS_DFLASH_ADAPTIVE=1, branch checkpoints on), medians, tok/s; receipts in
Enntity/sparkinkling results/2026-11-23-release-0.4.1.

32K prefill code decode prose decode structured C1 / C2 / C4 / C8 short code
Atlas Strict + DSpark 3,283 54.2 35.0 79.9 36.8 / 53.4 / 84.5 / 121.0
Atlas Spark + DSpark 3,274 68.4 54.9 95.3 51.6 / 76.1 / 105.4 / 135.2
Atlas Strict, #401's head (0.4.0 image) 3,277 49.2 33.6 86.4 35.9 / 49.1 / 78.1 / 119.6
vLLM, no speculation 2,722 35.1 35.6 35.6 35.1 / 54.0 / 86.6 / 122.4

Strict structured decode is lower than at #401's head: its two runs read 72.7 and 87.1, and in the slower one half
the steps decoded without drafts (serial=0.51). Not fixed here.

Test plan

  • inkling2_vision host tests (patch order, bilinear taps, RoPE table layout, head-row permutation, layer-scale
    folding), vision_preprocess::inkling2 tests (tiling, padding value, the capacity fit, the checkerboard), the
    vision_config parser test; GB10: tower output against transformers, an invoice transcription, a labelled grid
  • tool_security_tests: under --tool-guard stream an allowed call streams and finishes tool_calls; a
    metadata URL, an oversized call and a cut-off call each finish content_filter with the streamed refusal;
    Poolside calls stay held; the CLI parses stream
  • chat_wire::stream_tool_arguments_is_an_opt_in_request_field; on the SparkInkling 0.4.2 image (which carries
    this head) a metadata-address call asked for streamed sent its arguments in 31 chunks and finished
    content_filter, and the same call not asked sent no arguments and finished content_filter; a benign call
    not asked arrived whole in one chunk
  • inkling_turn: a call written with no block header (tool_choice required or a named function, which
    constrains output to the Hermes grammar) is the answer; streamed with thinking on it had been read as
    reasoning and cut by the in-think leak guard
  • Fused projections: greedy text of three probe prompts and concurrency hashes identical to the unfused build;
    pdl_tests.rs with the new kernel; check_kernel_shadows.py OK
  • The image's build ran the workspace suite (8,803 passed) and Clippy; on the image in both modes: task probe
    30/30 and 10/10, tool calls blocking and streamed with thinking on and off and with a forced tool choice, a call
    to a metadata address streamed then finished content_filter
  • spark benchmark run <gate> --pull-request-gate gates: left to the maintainers

Authorship

AI-authored: Claude (Opus 5.5 and Fable 5.2) in Claude Code, directed and reviewed by a human; no hand-written code.

CLA

  • I have read and agree to the Contributor License Agreement.

🤖 Generated with Claude Code

data-angel and others added 5 commits November 22, 2026 15:45
q, k, v, the relative-bias and gate projections, the sinks and the
dynamic convs' taps ran as six to eight GEMV launches a visit, each small
(24 to 3,072 outputs over K = 2,304). inkling2_proj_gemv runs them as one:
each segment of a per-visit device table (written once the shared buffers
attach, one a row count up to 8) is one projection's input rows, weight
and output, and every output row is the chain dense_gemv_bf16_batchm
computes for it (the common body now takes its block index). A visit with
a quantized projection (Spark weights) keeps one launch each.

Observed on one GB10, plain Strict decode (no drafter), saver size,
greedy text and the six-prompt concurrency hashes identical to engine
d1b138e: C1 code/prose 35.84/35.87 -> 36.37/36.37 tok/s (server rate,
3 runs), aggregate C2 51-53 -> 52-55, C4 79-80 -> 80-82, C8 115-118 ->
118-120 (2 rounds of 2 runs).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`--tool-guard stream` screens the same calls as `on`, at the same point
(each call's end, and the aggregate size bound as bytes arrive), but sends
a call's header and arguments as they are written instead of holding them
until the call passes. A call it blocks, or one the response cuts off,
ends the response `content_filter` (not `tool_calls`) with
STREAMED_REFUSAL, which says part of the call streamed and that it must
not be run. Poolside v1 calls stay held: its detector buffers them anyway.
`off` and `on` are unchanged, and `off` stays the default.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`pc_plan_branch` returned early for a model with no SSM layers, so
`ATLAS_GLM_PC_BRANCH` never planted a checkpoint for Inkling 2, whose
prefix hits resume from its short-conv state on the same snapshots. Gate on
`snapshot_prefix_state()` instead, the gate the prefix lookup already uses
(identical for SSM models).

For a client that rebuilds its last few messages every turn (a voice rig:
system, history, then three trailing user blocks re-rendered each turn),
every user turn diverged ~500-700 tokens before the previous prompt's end
and restored from the cold prefill's chunk boundary, replaying a growing
4.1-5.1K tokens. With the switch on (min 512), the first such turn plants a
checkpoint at the divergence and later turns restore there.
Observed, single run, one GB10, Strict, saver flags (prefix caching, 64
slots, chunk 4096), 16.4-17.4K-token prompts, 8 turns: user-turn TTFT
1.33-1.73 s -> 0.61-0.82 s (the planting turn 1.33 -> 1.49 s); follow-ups
unchanged at 0.29-0.32 s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`tool_choice` required (or a named function) constrains the output to the
Hermes grammar, so the model writes `<tool_call>` text with no Inkling
block header. The rewrite passed that through without the think end, so a
streamed request with thinking on read the call as reasoning and the
in-think leak guard cut the response (finish `length`, guard
`in_think_tool_leak`); effort none and the blocking path were unaffected.
Text between blocks now closes the reasoning first, as a text block does.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Inkling 2 Mini takes images; the target served text only. This adds its
tower (`model.visual.*`, transformers `Inkling2VisionModel`) as a third
`VisionTower`:

- config: `vision_config` (`inkling2_vision`) parses to a `VisionConfig`
  with the new `is_inkling2` marker; the image token is the processor's
  `<|unused_200054|>` (200054), which `config.json` does not carry.
- preprocessing (`vision_preprocess/inkling2.rs`): no resize. The image is
  padded to 40x40 pixel tiles (padding -1 on the 0-255 scale, alpha on the
  reference checkerboard), one token per tile, patches emitted tile by
  tile. An image of more tiles than the encoder holds is scaled down first
  (the reference has no such bound). Video is refused.
- tower (`inkling2_vision.rs`): Linear patch embed, CLS token, a learned
  32x32 position table resampled bilinearly per image, pre-LayerNorm, 23
  blocks with axial 2D RoPE on Q/K and layer scale, then a bias-free
  projector over each 2x2 block. It runs on the shared `vision_encoder`
  kernels (the nemotron file, symlinked): q/k rows are permuted per head at
  load from the reference's interleaved rotation pairs to the kernels'
  halves, and layer scale is folded into out_proj / c_proj.
- prompt: the template writes one image token per image;
  `expand_vision_pads` repeats it per tile (no start/end markers).
- embedding norm: the reference norms token embeddings inside the embedding
  and scatters image features in afterwards. The first visit normed its
  whole input, which also normed image rows (coarse content survived, text
  in an image did not). The table is now normed once at load, in place, with
  the same kernel and epsilon, and no visit norms; the drafter's anchor row
  skips its own copy of that norm (`embed_norm` NULL).

Checked on one GB10 (Strict, development build): tower output against the
transformers implementation on a 760x300 text image (152 tokens): mean row
norm 5.437 vs 5.432 (float32), sampled values within 0.003; an invoice
image transcribed exactly, a 3x3 labelled colour grid read 9/9. Greedy text
of three text prompts byte-identical to d1b138e after the norm moved.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@AzeezIsh

Copy link
Copy Markdown
Contributor

@data-angel thanks for this. Please split it into one PR per change: our merge rule is one verified change per PR, each gated against its own parent's binary. The five changes:

  1. 8ff871196: a visit's BF16 input projections in one launch
  2. 887d17894: tool guard stream
  3. f4684808c: pc branch checkpoints for aux-state models
  4. be99fe2ce: a call with no block header is the answer
  5. 6cf40a5a0: image input

Please stack them linearly, each based on the branch of the one below it, starting from main once #404 lands. #404's gate is in its last leg on sparky now. main has also moved since this branch was cut: #401's file-size split 9132aa78b and the AMD port #403 are in, and this PR now conflicts.

Three of the changes reach past Inkling on GB10, so their gates will be wider:

  • f4684808c changes shared prefill_b/pc_policy.rs, so it gets a Qwen3.8-27B prefix-cache regression check.
  • 8ff871196 and 6cf40a5a0 change kernels/gb10/common/dense_gemv_bf16_batchm.cu and add inkling2_proj_gemv.cu. The strix-hip target links the gb10 Inkling kernels, and its copy of dense_gemv_bf16_batchm.cu carries an AMD-only 64-bit warp-mask branch. Each of those PRs also needs a strix-hip build, plus an AMD runner check that it still serves. I'll handle the AMD side (symlink + any HIP branch) on top of each one.

@github-actions github-actions Bot added the needs-rebase Conflicts with main — its green checks are NOT real (GitHub skips merge-commit workflows) label Nov 23, 2026
@data-angel

Copy link
Copy Markdown
Contributor Author

@AzeezIsh thanks for merging 401 and for the file split.

This PR now conflicts with main (two files: layers/inkling2/mod.rs, where your owner_runs and this stack's proj are both declared, and pdl.rs, where inkling2_proj_gemv belongs in your new pdl_inkling2.rs). I have the rebase ready and checked locally on main 855df74b9 plus a merge of 404's head: cargo fmt --check --all, Clippy and the unit suites pass, and the 500-line cap check is clean.

I have not pushed it, so that 404 stays at d1b138e67, the commit your gate runs against. Once 404 merges I will rebase this branch (and the draft 408 behind it) onto main and note the new heads here. If you would rather have this one rebased onto main now with 404's two commits underneath, say so and I will push it today.

🤖 Generated with Claude Code

…split, Atlas-Inf#403, Atlas-Inf#404, Atlas-Inf#406, Atlas-Inf#410) into the images follow-up

Two conflicts, both from the split of 401: layers/inkling2/mod.rs declares
owner_runs and proj, and inkling2_proj_gemv joins the PDL list in its new
file pdl_inkling2.rs. The tree equals this branch's five commits replayed
onto main.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@data-angel

Copy link
Copy Markdown
Contributor Author

@AzeezIsh 404 is in, thanks. This branch now has main (7a717b659) merged into it and is mergeable; head a7b3a3681.

  • I merged rather than rebased so the branch only moved forward. The merge commit's tree is identical to the five commits replayed onto main (I replayed them first and checked the two trees are the same hash), so you can treat it either way.
  • The two conflicts were the ones from the 401 file split: layers/inkling2/mod.rs declares both owner_runs and proj, and inkling2_proj_gemv joins the PDL list in pdl_inkling2.rs.
  • On that tree: cargo fmt --check --all, Clippy with tests for atlas-core, spark-runtime, spark-model and spark-server, the 500-line cap check, and the unit suites (atlas-core 228, spark-runtime 590, spark-model 2,508, spark-server 3,252 passed, with the failures that need a git checkout or a real disk in my container). No GPU run on the merged tree; the five commits were measured on the old base as the description says.
  • One thing for the AMD target: this PR sets vision = true in kernels/gb10/inkling-2-mini/MODEL.toml and adds the vision_encoder and inkling2_proj_gemv kernels under gb10 only. I have not touched kernels/strix-hip/inkling-2-mini; if strix-hip needs a mirror as in 410, tell me what you want there and I will add it, or leave it to you.

🤖 Generated with Claude Code

Under `--tool-guard stream` every request got its tool calls as they were
written. A client that does not read `content_filter` would run a call the
guard blocked at its end, or an unclosed one. A request now gets streamed
tool calls only with the body field `stream_tool_arguments: true` (an Atlas
extension on /v1/chat/completions); without it the call is held, and the
response is the same as under `--tool-guard on`. This covers the generic
stream path and the Poolside v1 string-argument path. Under `on` and
`off` the field is accepted and ignored. A working-directory hint,
ATLAS_BUFFER_TOOL_ARGS and tool retry still hold a call as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@data-angel

Copy link
Copy Markdown
Contributor Author

@AzeezIsh I've split this into one PR per change, stacked linearly on main (7a717b659) in the order you listed. I'm closing this PR in their favour.

  1. Inkling 2: a visit's BF16 input projections in one launch (1/5, split from #405) #414 8ff871196: a visit's BF16 input projections in one launch
  2. tool guard: --tool-guard stream, tool calls streamed for a request that asks (2/5, split from #405) #415 887d17894 + 1a3675294: tool guard stream, together with the follow-up that makes streaming something a request asks for (stream_tool_arguments: true). The follow-up builds on the setting, so the two stay together.
  3. pc branch checkpoints: plan them for aux-state models too (3/5, split from #405) #416 f4684808c: pc branch checkpoints for aux-state models (shared pc_policy.rs, so this one gets the 27B prefix-cache check)
  4. inkling: a call written with no block header is the answer (4/5, split from #405) #417 be99fe2ce: a call with no block header is the answer
  5. Inkling 2: image input, the checkpoint's vision tower (5/5, split from #405) #418 6cf40a5a0: image input

🤖 Generated with Claude Code

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