Repository navigation
Conversation
…call copies the next layer's experts A prompt read on a card that holds few of the experts copies a layer's experts outside VRAM ahead of the routing (moe_rows()), into the staging buffer, which is at most one layer wide; with --stage-ring its two halves take turns. The next layer's copy goes out only when the host reaches that layer, after waiting for this layer's router, so on an RTX 4060 Laptop with Qwen4-35B-A3B UD-IQ4_XS the upload copy engine was idle for 11-12 ms of every 38-47 ms layer of a 2,048-token prompt, and neither the kernels (60%) nor the copies (45%) kept the card busy. --stage-next 1 (STRATA_POLY_STAGE_NEXT=1), with --stage-ring 1, in a read of one or two calls through the layers in turn (not read_groups(), and not with three or more calls, whose packs' rows come from pinned memory through the same copy engine) and on an architecture whose call row tables go to the card by a kernel (kernel_tables_; a copy of them would wait behind the next layer's experts): - widen_stage() maps two layers' experts for the read instead of one (Options::stage_next, stage_wide1_ the one- layer width it falls back to when two do not fit, as with a frozen cache), so a layer's experts are one round in one half; - moe_rows()'s card() plans the next MoE layer's rounds (plan_ahead() does not depend on the routing) and copies each into the half this call's round two before it leaves, or at once when that half is free; the next layer's call finds them (ring_next_mine) and copies nothing; - the call's end waits for the halves it used, not the next layer's; anything that drops the ring's halves drops the next layer's copy too (drop_ring_next(), which lets the upload stream finish first). Off by default; nothing changes without it. RTX 4060 Laptop 8 GB (PCIe 4.0 x8), CUDA 13.4, Qwen4-35B-A3B UD-IQ4_XS on this branch plus PR simplexai-labs#440 and the Qwen4 row-table kernel (separate change), --kv q8_0, 2,048-token prompt, 2 runs each: 1,224.8 / 1,225.2 tokens/s against 1,039.7 / 1,040.4 with --stage-ring 1 alone (main and PR simplexai-labs#440 without either setting: 948.6 +- 9.6, 3 runs); the copies now run back to back. A 6,000-token prompt 1,136.9 / 1,125.1 against 1,124.9 / 1,114.4 (inactive there by design). Inkling 2 Mini UD-Q4_K_XL (read_groups(), so inactive), 2,047 tokens: 674.8 / 674.8 against 664.7 / 669.9. The same tokens in every pair. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018j62UGHq9crCFFy7fHrCcW
VecSzn
added a commit
that referenced
this pull request
Dec 6, 2026
Collaborator
|
Integrated on |
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
A prompt read on a card that holds few of the experts copies each layer's experts outside VRAM into the staging buffer ahead of the routing (
moe_rows()). The buffer is at most one layer wide, and with--stage-ring 1its two halves take turns. The next layer's copy goes out only when the host reaches that layer, after it has waited for this layer's router. On an RTX 4060 Laptop with Qwen4-35B-A3B UD-IQ4_XS (2,443 of 10,496 experts in VRAM), a 2,048-token prompt copies 13.6 GB, and an Nsight Systems trace showed every 38-47 ms layer with the upload copy engine idle for 11-12 ms, kernels busy 60% and copies 45% of the time.With
--stage-next 1, the read's staging buffer is two layers wide and each layer's call copies the next layer's experts into the half it does not use while it multiplies. In the trace the copies now run back to back. Measured (same tokens in every run): 2,048-token prompt 1,224.8 / 1,225.2 tokens/s against 1,039.7 / 1,040.4 with--stage-ring 1alone (+17.8%), and 948.6 ± 9.6 with neither setting (main + PR #440, 3 runs). Decode after that prompt is unchanged or faster (76.75 ± 0.95 against 73.23 ± 2.53 tokens/s for the full set of Qwen4 changes, 4 runs).Related discussion
5bddf3729(the staging ring,--stage-ring). No issue.Approach
Options::stage_next(--stage-next 0|1,STRATA_POLY_STAGE_NEXT=1), with--stage-ring 1.widen_stage(two_layers):read()asks for two layers' width only when the read can use it: ring and next on, the architecture's row tables go by kernel (kernel_tables_), the layers are taken in turn (notread_groups()), and one or two calls (n_packs <= 2; with more, the packs' rows come from pinned memory through the same upload copy engine, and a 6,000-token prompt read 35% slower in a first version). When two layers do not fit (a frozen cache gives no VRAM back), it maps one layer's width (stage_wide1_), as before.stage_two_records which.moe_rows()'scard(): when this layer's rounds were all copied ahead and the next MoE layer's experts outside VRAM fit in two rounds, it plans them (plan_ahead()does not depend on the routing) and copies each round into the half this call's round two before it leaves, or at once if that half is free (each layer is one round in the two-layer buffer, so the copy goes out before this layer multiplies). A round of the next layer goes into a half this layer's later calls read only from the layer's last call (ring_last_call_, set by the read loop).moe_rows()start: the next layer's call takes those rounds when its experts are the same (ring_next_mine) and copies nothing; the end of a call waits only for the halves it used, not the next layer's.drop_ring_next(), which lets the upload stream finish first), and a non-ringstage()waits for that copy before it writes the buffer.docs/models/qwen4.md.read_groups()(Inkling 2), reads of three or more calls, a default change, HIP-specific tuning.Validation
Revision
c5d7a9ead. RTX 4060 Laptop GPU 8 GB (sm_89, PCIe 4.0 x8), i9-12900H, 30 GB RAM, Linux, CUDA 13.4.Passed:
742bc191), this commit with PR [Engine] qwen4: read the PLE n-gram table row by row from disk through the Direct reader #440 and the Qwen4 row-table kernel,--kv q8_0 --max-context 8192, 2,048-token prompt: 1,224.8 / 1,225.2 tokens/s with--stage-ring 1 --stage-next 1, 1,039.7 / 1,040.4 with--stage-ring 1.01e1e34f); with frozen experts and the same VRAM reserve, 200 tokens after the 33-token and the 2,048-token prompts are identical to the build without these changes, with and without the settings.read_groups(), so inactive), 2,047 tokens: 674.8 / 674.8 against 664.7 / 669.9 with the ring alone.STRATA_FREEZE_EXPERTS=1): falls back to one layer's width; 1,085.7 against 1,088.0 tokens/s.--stage-nextstays off, 1,147.5 against 1,158.8 (2 runs).python3 -m unittest tools.test_settings_register,python3 tools/check_links.py: OK.Failed:
Not run:
--layer-split),--vram-pool, co-reads, checkpoints during a read (marks).Limits
--prompt-batch); longer prompts take the pinned-memory path and read as before.🤖 Generated with Claude Code