Repository navigation
qwen27 CUDA: pack weight tensors into 128 MiB blocks (~1 GiB back on a 24 GB card) - #5
Closed
CanadaApollo6 wants to merge 1 commit into
Closed
CanadaApollo6 wants to merge 1 commit into
CanadaApollo6 wants to merge 1 commit into
Conversation
…Alloc each The driver rounds each allocation up to whole 2 MiB pages, which costs ~1 GiB over the 27B's ~900 large tensors. Both loaders (the 27B's and DFlash2's) now take tensors first fit out of 128 MiB blocks. The bytes and math are unchanged; only the addresses move.
Author
|
Closing: ashhart#608, this branch's base, was closed in favour of ashhart#836 as the one Qwen CUDA base. The sm_86 pieces that ashhart#836 still needs will come back as focused pull requests on it, after it runs on an RTX 3090. |
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.
Against ashhart#608's branch, one commit (
549653b1, 2 files, +36 −6). It doesn't depend on #3 or #4.The problem
The qwen27 CUDA loaders give every weight tensor its own
cuMemAlloc. The driver rounds each allocation up to whole 2 MiB pages. The 27B has ~900 tensors over 2 MiB, and many sit just past a page: a 2.8 MiB scale table takes 4 MiB. Summed over the checkpoint's tensor sizes, the rounding costs ~1.1 GiB. The server's own count (model … GiB) doesn't see it, because it adds up the requested lengths. So the memory is gone before the stream gate runs.The change
weights.Pool: both loaders (the 27B's and DFlash2's) take tensors first fit out of 128 MiB blocks, 256-byte aligned ascuMemAllocgives them. A simulation over the checkpoint's tensors leaves ~70 MiB of block tails unused.Weights.buffersowns the blocks, sodeinitandbytes()work as before.bytes()now counts whole blocks, which is the memory actually held. No kernel, layout or arithmetic changes: only the addresses move.Checks (RTX 3090, CUDA 13.4, driver 615.71)
sm_86 needs #3 to run the 27B, so the checks ran on #3 with this commit applied:
tf-qwen27-cuda windows(fresh 0.6.6capture_windows.pycapture, same card)run/draft/multi --context 8192bench_openai.py, code and chat, 2 reps)tools/zig/lean_check.pyMemory,
serve --context 32768 --parallel 1with the drafter (the startup line):Speed is unchanged (code 127.4 → 130.5, chat 90.6 → 89.6 tok/s, single runs). On my 3090 fork, this is what lets a 262K window load with the default reserve.
Not checked: GB10 and the RTX PRO 6000. The change is host-side allocation only, but their unified or large memory may show a smaller effect.
🤖 Generated with Claude Code