Repository navigation
Conversation
Derive per-visit cache access and exact arithmetic for the 48 visits so CUDA admission and kernels have a reference before serving is enabled.
Decode stored NVFP4 and MXFP8 expert weights to BF16 and launch them beside the grouped expert/vision kernels, with exact tensor baselines and planted faults.
Launch cross-pass messages, rank-64 gates, residual steps and split QKV with FP32 reductions, BF16 rounding controls and per-launch resource records.
Run all 48 visits with per-visit cache state, prompt snapshots and exact rollback. Refuse TP, vision and DSpark loading until those engines exist.
…ttn_norm upload a sliding layer)
The merge kernel takes the sink as a logit and applies the gate's sigmoid itself; the engine applied a sigmoid to both first, so every layer's attention output was wrong from layer 0.
…ad them tf_ink2_loop_messages wrote [row][core][role][c]; the engine reads each role's rows as one plane at messages + role * rows * c. The two agree for one row, so decode was right and every multi-row prompt chunk from the first visit of pass 2 on was not. The kernel now writes [core][role][rows][c] and the contract reference indexes the same way.
The backend held one stream, so with --parallel N every request past the first failed with NoFreeSlot. The model now keeps a slot per stream (K/V rows, conv states, rewind sites), the loaded engine takes the server's stream count through reserve, and forwards still run one stream at a time on shared scratch. inkling2-serving adds four concurrent streams, greedy and seeded, equal to solo, and a fifth refused.
The CUDA caches are head-major ([kv head][ring][dim]); copyState copied rows as [ring][kv*dim], so a state held part of head 0's ring and none of the others. A resumed prompt looked right only because the slot still held its own keys: after another prompt resumed the shared prefix, it answered that prompt. inkling2-serving adds that order (A keeps 14 and 39, B resumes A's 14 and decodes, A resumes 39 == fresh).
…ts row and sampling rule Admission read only the cache layout's bytes a stream, but each extra stream also allocates its rewind-site table (four sites a visit) and, in the backend, a vocabulary row of last logits and a sampling rule: 806,408 bytes more on Mini (48 x 4 x 32 + 200,058 x 4 + 32). engine.slotAllocs and backend.laneAllocs now size those allocations, and backend.streamBytes, which cuda_native reports, is their sum. A host test installs a DeviceBuffer hook that sums what Model.newSlot and Backend.slotBuffers ask for and pins stream_bytes to it, and the 806,408 bytes past the cache to the formula. The layout test that needed no CUDA moved from loop_engine.zig to loop.zig.
… rows where prep wrote them
… a resumed prompt reads the rows a fresh one wrote
…n before its row, and resume a turn the cache can keep
…y's words, so structured replies pass their second row
The ten modelopt and loop-math launches held zero usage at sm_80, sm_86, sm_89 and sm_120, so the kernel registry test failed with 40 "no compiled usage recorded" entries. tf_ink2_mix's rows at those four SMs were stale. The values are nvcc 13.0's, from kernel-contract-limits over fatbins built for all five SMs. No kernel changes.
…thing, refused calls counted Five fixes from the review of the reply split, all inside Inkling 2's path: - A special token outside the parser's eight controls, such as <|message_user|>, <|endoftext|> or <|content_xml|>, joined the block's text and was decoded with its spelling. Every token the tokenizer loads as special (Text.isSpecial, from its own config) is now never payload. - A sampling end stopped parsing, so text that ignore_eos keeps generating past it was dropped while still counted in completion_tokens. It now closes nothing: what follows is parsed by the same grammar, and a channel still open at the end is still reported. - Refused tool calls (malformed, unoffered or left unfinished) vanished without a trace. The parser counts them; the reply's tensorfold block gives rejected_tool_calls and the server logs a warning. Kimi does not report its refused calls, so its replies are unchanged. - A <|message_model|> inside an unclosed block was dropped, and the block's channel took the next message's header name and tool JSON as text. It now closes the block, as the template starts every message; a JSON call left open there is refused and counted. - With stop strings, every streamed frame decoded the whole reply only to clear calls that streamed frames never send. The check now runs once, on the finished reply. Tests: each fix has a test in inkling2_reply_test.zig or inkling2_chat_test.zig that fails on the previous parser. Two expectations that pinned the old sampling-end rule now expect the text past it. Other models' replies are unchanged: every change is in Inkling 2's parser or behind its flag.
…hole characters Mini's checkpoint never reached the reply split. Its config.json gives model_type "inkling2_loop", and HfText switched the split on for "inkling2" alone, so a served Mini reply took the generic path and showed its markers. The gate now takes both of the family's model types (families/inkling2/ config.zig): Small's "inkling2" and Mini's "inkling2_loop". With the split on, a reply a grammar holds from its first token is bare: JSON for response_format, or the generic call envelope the tool grammar writes for Inkling. Text before any message header is now the reply's content, and a bare reply's calls come from the shared parser, numbered as the native ones are; while it streams with tools offered its text waits for the finished reply. From the review of the previous fixes: - A stop string is matched on the raw reply, where the generation stops and stop_sequence reports it. The reply is what the raw text shows before that point, a partial token included; text joined across removed controls no longer makes stops of its own, and calls finished before the stop stay. - Every role header, user, system or tool as well as the model's, ends the model's turn: it closes an open block, refuses an open call, and the other role's blocks are never the model's. - Channels collect token bytes, an unfinished character waiting for its next byte, so a dropped special token between byte tokens leaves it whole. - reasoning_tokens counts every id of a thinking block from its message header through its close, as docs/api.md states. - A streamed raw completion takes the generation's own incremental decode instead of decoding every prefix. Tests fail on the previous parser for each: the release config, tokenizer config and chat template routed through HfText (new fixtures), bare JSON and call envelopes, both stop cases, the split character, role headers, token counts and the raw decode count. Expectations that pinned the old token counts, a headerless reply, and role headers as plain specials move with them. The fake tokenizer moves into inkling2_fake.zig for both parser test files. Other models are unchanged: every change is behind the Inkling flag.
…ents, full usage Seven release-path findings from the re-review of the Mini reply split: 1. A bare reply a tool grammar wrote, cut by the token cap, showed its partial <tool_call> envelope and no call. A bare reply with no finished call now takes the shared cut recovery at the cap, and the reply keeps finish_reason length, as the shared route does. 2. Streaming held back a possible stop in the parsed channels, which lack the controls a stop can spell, so a stop across a removed special leaked its start. What may begin a stop is now held in the raw text. 3. A stop's offset came from the lossy decode and was walked through exact token bytes, so an invalid byte before it showed part of the stop. The parser keeps the reply's exact token bytes, and stops and hold-backs are found there. 4. An unfinished character at the end read as one replacement per byte. Channels now read one replacement for each maximal invalid subpart, as the tokenizer's lossy decode does. 5. A stop inside thinking left its token out of reasoning_tokens. Usage now counts every generated id; the stop cuts only what is shown. 6. A bare reply's unoffered or malformed envelopes were kept as content without the shared route's kept_tool_calls block, warning and metric. They now carry all three. 7. The stop check decoded the longest stop's characters plus 8 tokens, and a byte-level tokenizer can spend several tokens on one character, so a stop of ten two-byte characters was missed. For Inkling 2 the window counts the stop's bytes; other models keep the shared window. Each fix's test is KS50's exact fixture, through HfText on the release fixture with each control id mapped to the fixture tokenizer's own, whole and streamed at strides 1, 2, 3 and 256; each fails on the previous code. Other models are unchanged: every change is in Inkling 2's parser or behind its flag, and the new Reply and Result fields default to the old behaviour.
…are calls in the shared order Four release-path findings from the re-review of the reply split: 1. Generation and stop_sequence matched stops in the lossy decode, while the cut searched exact token bytes, so a U+FFFD stop (byte CE alone) stopped the reply but was never cut. Stops and hold-backs are now found in the reply's lossy decode, kept incrementally beside its exact bytes with a map from each decoded piece to its bytes, and the cut is placed through that map. Inkling's stop check decodes its window the same way, skipping the continuation bytes it may open on, which no stop can start in. 2. Channels judged UTF-8 with their own check, which let leads C0, C1 and F5-F7 through. Channels and the raw text now decode with the tokenizer's own unicode.scan: each maximal invalid subpart is one U+FFFD. 3. A finished bare call kept the token cap's cut recovery from running, so a call cut after it was lost and the reply ended tool_calls. Bare calls now follow the shared route's order: cut recovery at the cap is tried whenever it applies and preferred when it finds a call. 4. Under parallel_tool_calls false the cut recovery still ran. It now runs only without that, and a bare reply's content takes the one-call filter the shared route applies, so an unfinished envelope stays hidden. Each finding's exact trigger is a route test, whole and streamed at strides 1, 2, 3 and 256, in inkling2_ks51_test.zig, with overlong, surrogate, past-U+10FFFF and valid-boundary UTF-8 cases. Each fails on the previous code. Other models are unchanged: every change is in Inkling 2's parser, glue or behind its flag.
…e cut reply reads them Two findings from the re-review of the reply split: 1. The stop check skipped up to three continuation bytes a token window opens on, even when the window is the whole reply and no character before it owns them. A raw reply opening on byte 80 then missed a U+FFFD stop and ran on to the cap. The check now takes the whole reply's ids and skips a window's leading bytes only when the last lead in the three bytes before it owns them, as unicode.scan reads that character. 2. After a stop, the final call routing and the stream's hold-back asked the cursor whether the reply was bare, and the cursor had read past the stop into a message header. A stop right after a bare envelope then left the envelope as content with no call. The parse result now carries its own bareness, so both read the cut reply's. inkling2_ks53_test.zig has both exact triggers, whole and streamed at strides 1, 2, 3 and 256; each fails on the previous code. A table beside them covers stops at offset zero, equal to, inside and spanning a control, right after a block's close, at a bare envelope's opening and closing edges, and raw windows opening on owned and unowned continuation bytes. Other models are unchanged: the stop-check change is behind the Inkling flag and Result.bare defaults to false.
…he cap keep length Under tool_choice "required" Inkling 2 Mini made three identical calls and ran to max_tokens, and the reply said finish_reason tool_calls. Inkling's template ends a call's message with <|end_message|> and only then the end of sampling. A grammar on Inkling holds the whole reply, so its calls are bare envelopes, and after a complete call the grammar allowed only blanks, another call or the eos id: the model's own next token, the end of the call's message, was never allowed, so another call was its best choice. - The grammar compiler on Inkling also takes <|end_message|> as an end, so the mask allows it exactly where the grammar may end, and a grammar-held Inkling request stops there (request eos). - In a bare Inkling reply, an end of message closes no message, so the server ends the turn on it; a native reply's ends of message are untouched. - Calls in a reply the token cap ended keep finish_reason length. A different second call before the end still returns when parallel calls are allowed; parallel_tool_calls false keeps one. Other families get the same eos slice as before and their routes are unchanged. inkling2_required_test.zig: the served shape, two different calls, one call under parallel_tool_calls false, length at the cap (bare and native) and a native reply's inner ends, whole and streamed at strides 1, 2, 3 and 256; the first three fail on the previous code. One existing test now ends its bare call on the fixture's EOS, since a script that runs out reports the cap.
… grammar only The previous change let any bare Inkling 2 chat reply end at <|end_message|> and gave every Inkling grammar that extra stop. So a reply with no tools or with auto tools that wrote "left", an end of message and "right" came back as "left", and a JSON-mode grammar could end at an end of message where it used to allow only the end of sampling. - The shared grammar compiler is opened with the eos ids alone again. On Inkling 2, a required call's grammar alone compiles on a second compiler whose ends also take the end of message. - A request takes the end of message among its ends only when its final structure is the required call's grammar; a response_format that would replace it keeps the eos ids (the request boundary already refuses that pair). - The server ends a bare reply at an end of message only for such a request, and only once a complete call parses from what came before. Plain, JSON-schema and auto replies are main's again. Other families get the same compiler, ends and route as before. inkling2_required_test.zig: a bare left/end/right reply with no tools and with auto tools; a JSON-mode reply with an end of message inside; a required reply whose first end of message comes before any call; the request's end ids in each case. The first three fail on the previous code. The earlier required-call tests now send tool_choice "required", through a stub grammar compiler in the route harness, and pass as before.
…n it is complete calls The required call's bare stop accepted any prefix that parsed one call. So with a complete first call, an end of message inside an unfinished or malformed second envelope ended the turn: the client got the first call, lost the second, and the stream was cancelled at the same point. The stop now holds only when the reply before the end of message is complete calls and nothing else: at least one call, no refused envelope, and no text left after taking the calls and blanks out. An earlier bare end of message carries no text and is left out of that reading. Other replies, routes and families are unchanged. inkling2_required_test.zig: the exact trigger (a complete call, an open second one, the end of message, its close and EOS) and a table around it: a malformed and an unoffered envelope, text beside the call, only blanks after the call and two complete calls; whole and streamed at strides 1, 2, 3 and 256. The trigger and the table fail on the previous code. A json_schema reply's token ids, compiler and ends are pinned too: it ends on the end of sampling, as before the call stop existed, compiled by the shared compiler with the eos ids alone. The route harness now counts each compiler's grammars and reads return_token_ids.
…o keeps The test added with the opt-in expected no keep calls at all with it off. Main's rule keeps a window whenever part of it is not committed, and the 24-token reply's last window is cut short by max_new, so main makes that one keep too. The default path was unchanged; the expectation was wrong. The fake now also counts windows kept whole. With the opt-in off there are none, as on main; with it on there are some, and the partial keeps are the same in both runs. Making the default path keep whole windows fails it.
On today's main the macOS qwen27 dev tools stopped compiling with this series. checkpoint_metal.zig now reaches the shard file cache through its `core` module, and the qwen27 tools' core root (qwen27_core.zig) did not export it; it now does, from the same file safetensors.zig already imports in that module. The engine module also gained its own engine_api import, while qwen27.zig made a second engine_api module for the served tools, so tools importing both held engine_api.zig in two modules; they now reuse the engine's. No source behaviour changes.
…in the cache rows test-inkling2-metal-host compiles main's metal module, which reaches Darwin-only std.c (os_unfair_lock, and timespec in metal4.zig on Windows), so registering it on every OS broke `zig build test` on Linux and Windows and put it in Linux's test-host shards. It is now registered, and added to the test step, only when the target is macOS, as main's own Metal host steps are. compile-inkling2-native-host stays on every OS. Inkling 2 Mini's CUDA family has snap_save, so the generic CUDA host builds its prompt cache, and TF_CACHE_EVICT and TENSORFOLD_PROMPT_CACHE_KEEP_OTHERS apply to it. inkling2_loop joins profile.cuda_cache, which cuda_keep_others_test.zig checks against the registry, and the profiles doc's family list.
Owner
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CI for a landing train: #4387 stacked on main in that order. Nothing merges from this PR: each PR above lands on its own once this tip is green, and this PR is then closed.