Skip to content

Inkling 2 Mini on Metal: the startup line reports the demand of the asked streams (no change to admission) - #4705

Merged
ashhart merged 3 commits into
ashhart:mainfrom
BlivionIaG:port/admit
Nov 24, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
BlivionIaG:port/admit

Conversation

@BlivionIaG

@BlivionIaG BlivionIaG commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Inkling 2 Mini on Metal prints the demand it was asked for in its one startup line, and nothing else changes. Before: inkling2_loop: 15.6 GiB for stream and prompt state, context up to 8192 tokens. After: the same line, followed by what the asked streams need: ; 4 streams ask 20.23 GiB (18.39 GiB weights, dense layers and scratch, 4 x 0.46 GiB a stream, 0.00 GiB shared). The numbers are state.cacheBytes(window) plus, with --drafter, Drafter.streamBytes(window) and the shared score buffer, and the weights, dense layers and scratch main already computes.

This slice does not change admission: the window fit, the stream count, what starts and what is refused, and the per-request held + need > budget check are main's, byte for byte. The line allocates nothing (std.log.info with stack arguments), so no ownership moves before it.

Left open, as a separate problem: with --parallel 4 --context 131072 on a 48 GiB Mac, four requests that each reserve the whole window start, three run, and the fourth fails with HTTP 500 InklingStateFull (a stream needs 4.2 GiB of state; 12.6 of 15.6 GiB are held). The line above makes the cause visible (4 x 4.21 GiB against 15.6 GiB) but does not change it. The DSpark window fit (#4622) is also separate.

Checks on this head

  • Head commit: d79dcfe744.
  • Lean checker, python3 tools/zig/lean_check.py, on main (e3c6f79bac) and on this head: 165 and 165, 0 new.
  • python3 tools/pr_check.py --base upstream/main --pr 4705: 0 errors, 0 warnings.
  • Tests run: zig build test-inkling2-metal-host compile-inkling2-native-host test-inkling2-host -Dcpu=apple_m1 -Doptimize=ReleaseFast: 126 pass, 0 fail, 8 skip (they need TF_INKLING2_METAL_DIR), 4 of the passes new in admit_test.zig (the 48 visits' state, DSpark's terms, the room by RAM class and the whole streams it holds at each window, a drafted demand). With the 48 GiB, 131072-token count changed from 3 to 4 the step fails with expected 4, found 3; put back.
  • zig fmt --check build.zig zig: clean. ./zig-out/bin/tf-kernel-contract --only inkling2: SUMMARY 41 kernels: 41 pass gates 1-4, 0 fail, 0 known findings; 41 controls: 41 red as planted, 0 missed; 0 limit problems (no kernel, launch or record is touched).
  • CI: not yet reported.
  • Not run, and why: CUDA, HIP, M1 to M3 and M5: the change is one log line in the Metal opener.

Receipt

  • Main against branch, --parallel 4, four short concurrent requests, greedy, --no-thinking --prompt-cache-gib 0, /usr/bin/time -l peak footprint. Both start or refuse alike:

    settings main this branch
    --context 8192 starts, 21.58 GB starts, 21.57 GB; 4 x 0.46 GiB, 20.23 GiB asked
    --context 65552 starts, 21.57 GB starts, 21.58 GB; 4 x 2.21 GiB, 27.24 GiB asked
    --context 131072 starts, 20.49 GB starts, 21.58 GB; 4 x 4.21 GiB, 35.23 GiB asked
    --drafter --context 8192 refused: --context exceeds the largest window this Mac can afford beside the checkpoint and DSpark state refused, same text

    (Rows are from the main build 5e390519d0 whose inkling2.zig and Inkling 2 Metal files equal e3c6f79bac's. Footprints at the same settings differ by up to 1 GB between runs because the four requests land at different points of their prefill within the 45 s window; they are not a measure of this change.)

  • Boxes it reaches: Macs, the inkling2_loop Metal path, at open.

  • New switch? None.

  • Environment: this head, Zig 0.17.0, Xcode Metal toolchain, Apple M4 Pro, 48 GiB, macOS 27.2, thinkingmachines/Inkling-2-Mini@ed40e7da625f594fc9c4990f5f66be24873c22d7. Load average 1.6 to 3.7 and OS memory pressure level 1 at the start of each run. These rows are start behaviour and footprint, not timings.

  • Exactness: greedy chat hashes (--parallel 1 --context 8192 --no-drafts), main at e3c6f79bac and this branch: 7781f06a3160 33a29a1cc9d2 753dc475f8b6 83614a01d8ae on both (prompt lengths 26, 26, 414, 1034 tokens). An older main build (5e390519d0) gave 0b037128ee78 b37d8a0e39c4 146f8038bfc7 870a47079391 at prompt lengths 28, 28, 416, 1036; the prompt lengths moved on main before this change, not with it.

  • Decode speed and prompt speed before and after: n/a, no kernel, launch or prompt path is touched; the line is logged once at open.

  • Licence of any new weights or drafter: n/a.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • No precision traded for speed. No bits change.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo: not re-run; no token path changes.
  • Decode and prompt processing no slower than main: not re-measured, nothing on those paths changes.

@BlivionIaG

Copy link
Copy Markdown
Contributor Author

@ashhart a question on this draft before I restack it. lead/inkling2-mini at f790014399 now admits Mini streams by state bytes at stream start: prefillFn sizes each stream by prompt plus max_new and fails with InklingStateFull when it does not fit (a stream needs 4.2 GiB of state; 12.5 of 15.6 GiB are held). On a 48 GiB M4 Pro, --parallel 4 --context 131072 starts on lead, serves four short requests, and four requests of max_tokens 130000 start three streams and refuse the fourth.

This draft does something stricter: it reserves window-sized state per stream when the server opens, so on the same flags it refuses to start (--parallel 4 needs 16.84 GiB, 3 fit), prints its demand line, and --parallel unset serves 3 streams. I restacked the two commits on f790014399 (they apply cleanly and their tests pass: test-inkling2-metal-host 81 pass 4 skip, test-inkling2-host 44 pass, test-lane-api-host 761, test-lane-explore-host 36, contract 41 of 41), but "before: refused with no count" in the description no longer matches lead.

Do you want admission at open (a refusal that names the count and the largest window that fits), or is the per-stream check on lead the intended behavior? If lead's is, I'd close this draft rather than keep two admission rules; the one shared-core piece (Governor.hold_from, to hold admission to one stream from critical and not warning) would stay open as its own question if you still want it. I'm holding the restack until you say.

@ashhart
ashhart force-pushed the lead/inkling2-mini branch 3 times, most recently from aefb063 to c41911e Compare November 24, 2026 09:43
@ashhart
ashhart deleted the branch ashhart:lead/inkling2-mini November 24, 2026 09:43
@ashhart ashhart closed this Nov 24, 2026
@ashhart ashhart reopened this Nov 24, 2026
@ashhart
ashhart changed the base branch from lead/inkling2-mini to main November 24, 2026 09:48
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Sorry for the noise: this was closed automatically when #4387 landed on main and its base branch was removed. It is reopened and now targets main. We will follow up here on what it needs next; nothing is needed from you yet.

  • Synthena

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @BlivionIaG. The demand breakdown is useful, and this head no longer changes the shared pressure governor.

I found a cleanup bug in the new refusal path: it frees the model and drafter before allocating the message. If that allocation fails, the existing error cleanup frees them again. Please allocate the message before freeing those owners, or give cleanup one owner, and add a focused allocation-failure case.

On the admission question, I recommend keeping main's check by actual request size and separating the diagnostics. Reserving a full window per stream at startup rejects four short requests that main can serve. The whole-window fourth-request failure is a separate admission problem. The DSpark token-size correction in #4622 also remains separate.

  • Synthena

@BlivionIaG BlivionIaG changed the title Inkling 2 Mini on Metal: streams admitted by the bytes they need, with the demand in the startup line Inkling 2 Mini on Metal: the startup line reports the demand of the asked streams (no change to admission) Nov 24, 2026
@BlivionIaG

Copy link
Copy Markdown
Contributor Author

Thank you, @ashhart. Done as you recommended: the head is now one commit (d79dcfe744, squashed on current main) that changes no admission decision. main's window fit, stream count, refusals and per-request checks are untouched; the refusal path is gone, and with it the double free. The one change is the startup line, which gains ; N streams ask X GiB (W GiB weights, dense layers and scratch, N x S GiB a stream, H GiB shared) after main's own text; it is a std.log.info with stack arguments, so it allocates nothing.

Measured at --parallel 4 with four short concurrent requests, main (the build 5e390519d0, whose inkling2.zig and families/inkling2 files equal the current ones) against this head: --context 8192 starts on both (21.58 and 21.57 GB peak), 65552 starts on both (21.57 and 21.58 GB), 131072 starts on both (20.49 and 21.58 GB; I take the 1 GB as run-to-run, how far the four prefills got inside my 45 s client window), and --drafter --context 8192 is refused with the same text on both. Greedy chat hashes on main at e3c6f79bac and this head: both 7781f06a3160 33a29a1cc9d2 753dc475f8b6 83614a01d8ae. Host tests 126 pass, 0 fail, 8 skip; contract 41 of 41 with 41 controls red; pr_check 0 and 0; lean 165 and 165.

I did not re-run the whole-window fourth-request HTTP 500 and the body says it is left open as its own problem. The new line makes its cause readable (4 x 4.21 GiB against 15.6 GiB). #4622 stays separate.

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @BlivionIaG. This version keeps main's admission and cleanup paths and only adds the demand breakdown. Removing the refusal path also removes the double free. The new receipts and focused tests are useful.

This diagnostic slice is ready for normal landing checks. The whole-window admission case and DSpark sizing correction remain separate.

  • Synthena

BlivionIaG and others added 3 commits November 24, 2026 22:37
- Weights, dense layers and scratch, the state of each stream at the window and what the streams share, beside the room the load limit leaves.
- Which streams and windows start is unchanged.
…ng test

The admission test opens native/inkling2.zig for cacheBudget. Since ashhart#4897 a
family file imports no native (native/inkling2.zig imports the family's Metal
model, backend, state and dspark, so the other way made a cycle), so the test
moves unchanged to native/inkling2_admit_test.zig, reaching the family files by
path as native/inkling2.zig does, and is registered under
test-inkling2-metal-host's root beside native's other tests.
@ashhart
ashhart merged commit a191976 into ashhart:main Nov 24, 2026
1 check failed
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you @BlivionIaG. 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.

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