Repository navigation
[Engine] Inkling 2: route guessed tokens like single tokens - #327
Open
okada-shogo wants to merge 1 commit into
Open
okada-shogo wants to merge 1 commit into
okada-shogo wants to merge 1 commit into
Conversation
With the doorbell (bell_on(): Inkling 2 with experts outside VRAM) a token alone is routed on the card: route_card(), whose gate sigmoid uses the card's expf. A window of several tokens (--window N lookup guesses, the drafter's verify) went to moe(), which routed each row on the host: route(), the same formula with the host's std::exp. The two need not round alike in the last bit, so a guessed token's expert weights (and, at a near tie, an expert) could differ from the ones it got alone. Greedy answers with guesses then parted from the answers without them after some tokens, and since the policy picks the window length from measured times, from run to run as well. run() now does for a window what step() does for its rows since 1d4d9e2: where a token alone routes on the card, up() routes the window's rows there before the router's event, with the picks and weights written straight to pinned memory (h_ids_, h_wts_, now also allocated for bells() with a window over 1), and moe() takes them (step_ids_). step()'s tests move into picks_like_alone() and picks_like_alone(L), shared by both; step() behaves as before. Not in a window's halves (they need reads_by_layer(), which no family with the doorbell has), not with --cache-bias, and not on HIP or Metal (no doorbell there). Class: same bits as one token at a time (frozen experts, 2070 Super: per-layer states and logits of every verified row equal the token alone's); other families, HIP and Metal do not reach the new code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem and result
On 8 GB cards, Inkling 2 with guesses (
--window Nlookup guesses, or the DSpark drafter) did not give the same greedy tokens as plain one-token decode. Which tokens changed also varied from run to run, because the draft policy picks the window length from measured times.Cause: with experts outside VRAM, a single token is routed on the GPU (the doorbell path,
route_card(), the card'sexpf). A window of several tokens went tomoe(), which routed each row on the CPU (route(), the host'sstd::exp). The two can round a gate differently in the last bit. The expert weights then differ by an ulp, and at a near tie the chosen expert differs. Per-layer dumps on an RTX 2070 Super showed it: the first difference was always the experts' sum (fo) of a window row, with identical router scores.Fix: a window's rows are now routed on the GPU too, exactly as
step()already does for--batchrows (1d4d9e2). After this PR,--window 4and the drafter's verify give the same tokens as no guesses in every case tested, with or withoutSTRATA_SPEC_FIXED.Greedy tokens vs no guesses (frozen experts, 128 tokens, RTX 2070 Super 8 GB and a second RTX 2070 8 GB):
--window 4--window 4--stage-read-mib 0, see Limits)Decode tok/s on the same tokens (both builds
--followthis PR's greedy answer, so they check the same guesses), frozen experts, 256 tokens, mean of 6 texts (code/chat/prose x 2048/8192) x 3 runs, RTX 2070 8 GB + Ryzen 7 5800X:--window 4(tok/s)No change beyond noise. Prompt speed does not change (no new code on that path).
Decode tok/s of each run, per text (W = `--window 4`, D = drafter)
An earlier version copied the picks through
d_ids_with one more launch per layer: -0.3% / -0.1% on the same card, and -0.4% / +0.3% on the RTX 2070 Super 8 GB. Writing the picks straight into pinned memory removed that launch.Related discussion
none
Approach
run(): when a single token would be routed on the card (picks_like_alone()),up()callsroute_card()for the window's rows before the router's event and writes the picks and weights straight to pinned memory (h_ids_,h_wts_).moe()uses them throughstep_ids_, the same pathstep()uses.step()'s two conditions moved intopicks_like_alone()andpicks_like_alone(const Layer&), shared by both.step()behaves as before.h_wts_is now also allocated when the window is over 1 (rows_ * n_used_floats of pinned memory).reads_by_layer(), which Inkling 2 does not have), with--cache-bias, or on HIP and Metal (no doorbell there: a single token is routed on the CPU like the window).Validation
Passed:
--no-graphs, frozen cap 600, code and prose 2048, 64 tokens): main has the first difference infoof a 2- or 3-row window. This PR: every tensor of every position and the logits are bit-identical between window 1 and--window 4.STRATA_FREEZE_EXPERTS=1 STRATA_GPU_EXPERTS=600(Q2: 1000), 128 tokens,--serve: table above. Also with the timing-adaptive policy (noSTRATA_SPEC_FIXED): 0 differ.d_ids_: same tokens, and--window 4and the drafter = no guesses, in code/chat 2048 and chat 8192 (RTX 2070,--stage-read-mib 0).--window 4and drafter: 6 of 6 differ before, 0 of 6 after, same expert placement in every mode). That port goes with [Engine] Inkling 2 on AMD: GPU doorbell for experts in RAM #306.Failed:
Not run:
Limits
read()takes the two 1,024-row calls through each layer together, and the second call (1,023 rows, under--stage-ahead) uses the first call's staged experts, so its sums are split as a larger call's (asread()'s comment says). With the drafter loaded, the read gives the same bits as--stage-read-mib 0, where each call reads on its own.read_groups()sizes its groups from free VRAM, which the drafter lowers. This PR does not change it.vram_ahead()uploads can still send a window's miss to the GPU where a single token computes it on the CPU. That depends on upload timing, as before this PR.--tail-skip,--route-top,--skip-weight) still act differently on a window than on a single token, as before.🤖 Generated with Claude Code
🤖 Generated with Claude Code