Repository navigation
Conversation
…, as Inkling 2's do In a prompt read of several calls, moe_rows() copies each call's row tables (about 100 KB) to the card with cudaMemcpyAsync on the main stream. The layer's experts outside VRAM are copied ahead of the routing on the up stream, and a GeForce card has one copy engine for uploads, so the tables' copy waited behind those uploads and the layer's multiplications, the cached experts' too, waited behind the tables. Inkling 2 has the tables read by a kernel from pinned memory instead (kernel_tables_, f0ab63a); Qwen4 now does the same. The same tables reach the same buffers. STRATA_QWEN4_KERNEL_TABLES=0 keeps the copies. CUDA only, as for Inkling 2. RTX 4060 Laptop 8 GB (PCIe 4.0 x8), UD-IQ4_XS, --kv q8_0, 2,048-token prompt: 1,039.8 +- 34.4 tokens/s against 1,023.9 +- 45.6 with =0 (4 runs each, this branch); on top of PR simplexai-labs#440 990.6 +- 5.5 against 974.3 +- 6.4 (3 runs). The same tokens in every run. It matters more with --stage-ring and the next layer's experts copied ahead (separate change), where the tables otherwise wait behind a whole layer's uploads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018j62UGHq9crCFFy7fHrCcW
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
In a prompt read of several calls,
moe_rows()copies each call's row tables (about 100 KB) to the card withcudaMemcpyAsyncon the main stream. The layer's experts outside VRAM are uploaded ahead of the routing on the up stream, and a GeForce card has one copy engine for uploads, so the tables' copy waits behind those uploads, and every multiplication of the layer, the cached experts' too, waits behind the tables. In an Nsight Systems trace of a 2,048-token prompt (RTX 4060 Laptop, Qwen4-35B-A3B UD-IQ4_XS) a table copy enqueued before 394 expert copies ran after all of them, 27 ms later.Inkling 2 avoids this since
f0ab63a90: its tables are read by a kernel (copy2) from pinned memory (kernel_tables_). Qwen4 now does the same. The same tables reach the same buffers, so the results are the same bits. Alone it is a small gain (+1.5 to +1.7% on a 2,048-token prompt); with the next layer's experts copied ahead (--stage-next, a separate PR) it is what lets that work, since there the tables would wait behind a whole layer's uploads.Related discussion
f0ab63a90(Inkling 2's row tables by kernel). No issue.Approach
Qwen4::load_geometry():kernel_tables_ = trueon CUDA, asinkling2.cppsets it;STRATA_QWEN4_KERNEL_TABLES=0keeps the copies. HIP and Metal never take it, as for Inkling 2.terminal/data/settings-register.json, status rollback) anddocs/SETTINGS.mdis regenerated from it.moe_rows()itself, other models.Validation
Revision
9a5e8770e. RTX 4060 Laptop GPU 8 GB (sm_89, PCIe 4.0 x8), i9-12900H, 30 GB RAM, Linux, CUDA 13.4; Qwen4-35B-A3B UD-IQ4_XS (pinned commit742bc191),--kv q8_0 --max-context 8192, 2,048-token prompt, 2 tokens written.Passed:
=0, 4 interleaved runs each (the mapped table's page cache makes these noisy).01e1e34f); with frozen experts, 200 tokens after a 2,048-token prompt are identical to the build without it.python3 -m unittest tools.test_settings_register: OK.Failed:
Not run:
Limits
--stage-nextare the stronger evidence.🤖 Generated with Claude Code