Repository navigation
Qwen3.5: offload BF16 input embeddings to host RAM - #5052
Conversation
3081dd2 to
bf0e6f6
Compare
bf0e6f6 to
7c5b820
Compare
24 GB Qwen3.8-27B context and VRAM measurementMeasured on an NVIDIA GeForce RTX 5090 Laptop GPU (24,463 MiB) using TensorFold commit Both variants were started with explicit host embedding residency, one stream (
Safetensors source payload breakdown:
Pinned host memory measured 2.429 GiB for both runs (about 0.061 GiB beyond the embedding payload). The startup lines reported 17.83 GiB and 19.83 GiB of model allocation before per-stream reservation, respectively. The 1 GiB admission reserve reduces the usable budget; it is not a separate allocation. NVML process memory is about 0.28 GiB above TensorFold's active allocator metric, and whole-card use includes about 0.08 GiB outside the process. Target BF16 KV costs 64 KiB/token (16 full-attention layers × 4 KV heads × 256 dimensions × K/V × 2 bytes); the MTP ring adds 4 KiB/token. The non-context column is measured CUDA active memory minus those cache amounts. It includes target/drafter allocations, fixed state and workspaces. TensorFold does not expose separate live counters for target weights, MTP weights and scratch, so this remainder is not a scratch-only figure. The source payloads are not exact device allocations; MTP source tensors are BF16 and are quantized to affine-4 tables at load. Loader note: the Unsloth checkpoint config declares No prompt was submitted at the maximum, so these results establish startup allocation capacity, not full-context prefill, quality or throughput. This means we can store a context of 56,014 tokens with NVIDIA ModelOpt NVFP4, or 25,053 tokens with Unsloth NVFP4, in this 24 GB card under the measured settings. |
24 GB VRAM follow-up: reserve and FP8 KV experimentHardware: NVIDIA GeForce RTX 5090 Laptop GPU, 24,463 MiB capacity (23.89 GiB, sm_120).
The default 1 GiB reserve is an admission margin, not a separate VRAM allocation. With BF16 KV and a 0.5 GiB reserve, ModelOpt started at 63,724 tokens, close to 64k; the 64,000-token probe was refused (rounded planner estimate: 4.76 GiB required versus 4.74 GiB available). FP8 KV is lossy and may change generated tokens. We are aware the current project policy disallows introducing lossy cache formats, including opt-in support; the existing Qwen FP8 path predates that policy (issue #4107). These rows are an interesting experiment in the specific context of constrained 24 GB VRAM capacity, not a proposal to expand FP8 support or change policy. No prompt or output-fidelity comparison was run. Every row reports startup admission only. No prompt was submitted, so these figures do not establish that a full-length prefill succeeds. |
24 GB VRAM follow-up: tap ring and recurrent scratchA source audit explains the earlier 0.13 GiB startup-charge difference and found a separate 60 MiB per-stream omission in MTP admission accounting. MTP tap ring. Qwen3.5 uses 6,144 rows for this scenario (2,048 tap-window rows + 4,096 prompt-pass rows). One BF16 tap at hidden size 5,120 is 62,914,560 bytes = 60 MiB. The target cache allocates it after the MTP drafter installs its tap list, but the target's The 0.13 GiB variation. The earlier 17.83 GiB run logged Rollback and cancellation. MTP depth 3 alone would need at most four verify rows, but the measured dense Qwen3.8 setup also has root/context copies enabled. With a 64-row family width, copy proposals can reach 64 rows, so For this 27B geometry, dropping only the inference before-copy allowance would reduce the current recurrent bound by 153,944,064 bytes = 0.14337 GiB per stream while preserving Sources: tap sizing and allocation, target stream charge, MTP stream facts, cost-cache validation, recurrent bound, and copy width setup. |
00a7fe7 to
3fdd3d9
Compare
3fdd3d9 to
a7c26dd
Compare
Qualification evidence for
|
672a918 to
1b33142
Compare
1b33142 to
2d49c06
Compare
2d49c06 to
7a81575
Compare
7a81575 to
7dccce2
Compare
7dccce2 to
6541480
Compare
|
Thank you @tacosta. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
What this changes
Before this change, Qwen3.5 CUDA kept BF16 input embedding rows on the GPU. This commit adds
--embedding-residency auto|device|hostfor ModelOpt NVFP4 and compressed-tensors/Unsloth NVFP4 checkpoints. Rows stay BF16 and are copied unchanged.autouses host-mapped rows when device capacity needs the space and retains device placement when they fit. Existing EXL3 automatic offload is unchanged.The shared MTP sizing helper includes the active drafter's startup and resident memory when choosing placement. MTP scratch layout and recurrent scratch are unchanged; the separate MTP admission-charge work in #5134 is out of scope.
mainat2d15aaeca2eecedb1ca0346fb9c337da5fad5e32; one commit:1b33142432d8a1e6aeec701efbe9c1f35b5e1699.ATC overlap
atc overlap --jsonran on this base and head. Selected checks completed for all 112 visible candidates: 56 conflicts with separate open PRs, 53 clean, and 3 with no shared files or no result. GitHub result caps may hide other PRs. Conflicting PRs: #728, #1394, #1522, #1886, #2008, #2020, #2340, #2523, #2634, #2982, #3041, #3075, #3076, #3218, #3333, #3563, #3564, #3565, #3566, #3567, #3640, #3723, #3729, #3867, #3878, #3884, #3885, #4416, #4449, #4471, #4500, #4502, #4523, #4592, #4594, #4598, #4608, #4618, #4631, #4644, #4645, #4649, #4660, #4664, #4666, #4685, #4689, #4695, #4698, #4701, #4746, #4749, #4841, #4883, #4966, and #5095. A 22-file stale local worktree conflict was excluded as directed. Since then, upstreammainadvanced from2d15aaeca2eecedb1ca0346fb9c337da5fad5e32to6c225463591863b1473ff8040df53ebb063d0986, including MTP memory-admission commit95f14d9c73. GitHub now reportsmergeable_state=dirty; a local merge-tree check against currentmainfinds content conflicts inzig/build/cuda_family_host.zigandzig/src/families/qwen3_5/cuda_mtp.zig. The PR is ready for review but not merge-ready until the base conflict is resolved. The latest ATC scan is incomplete because of PR and changed-file coverage limits; the overlap list above is from the earlier base.Checks on this head
zig fmt --check build.zig zigandgit diff --check: passed.zeInit: 0x78000001on both base and head; classified as the same environment-level initialization failure.tools/zig/env_names.py: inherited check failure on base and head forNOT_READLD_AUDITandLD_PRELOAD(761 variables scanned);env_names_test.py: 17 tests passed.Zig formatrun #14441 passed. InNo GPUrun #14455 on this head,pytest,zig-windows, both Windows and Ubuntu benchmark-client jobs,zig-macos-dev-tools,comfyui-moss-installer,release-paths, andzig-bpassed.zigfails only at the environment-name check for the same two base/headNOT_READfindings listed above; later steps in that job were skipped. Both nightly jobs were skipped by workflow conditions. The sole completed failure is classified as inherited.Runtime receipt
Measured on Linux x86_64, Zig 0.17.0, CUDA 13.3, NVIDIA RTX 5090 Laptop GPU (24,463 MiB, SM120). Checkpoints are Qwen3.8-27B loaded by the Qwen3.5 CUDA path: ModelOpt revision
dbb8f445b3145f8a4c18ddc769f032d57d32867c; Unsloth revision60e813d4dbbdc5d64cf3f5a8caf2897bedf03679. KV stayed BF16. ModelOpt MTP3 used its BF16 drafter. ModelOpt one-stream decode used the default 1 GiB reserve; context and concurrency checks used a matched 0.5 GiB reserve. Unsloth checks used 0.5 GiB.One-stream decode
Seeded MTP3 used 10 repetitions per prompt and temperature. Prompt-seeded token and output hashes matched 10/10 for both prompts, greedy and sampled.
Five-run no-draft chat medians were also close: ModelOpt 27.87 → 27.86 tok/s greedy and 35.04 → 35.00 sampled; Unsloth 32.11 → 32.11 greedy and 32.09 → 32.09 sampled. No speedup is claimed.
Cold prompt and context admission
Prompt caching was disabled for these cold prompts; each result below completed the full prompt.
autokept embeddings on device; 64kautochose host and completed 65,520 tokens in 46.82 s.autochose host at 32k and completed 32,752 tokens in 22.92 s; explicit-host 2k and 8k cold prompts completed.At 8k context, maximum admitted parallelism was one stream on main and four with host placement for ModelOpt MTP3, ModelOpt no-draft, and Unsloth no-draft. Three-repetition concurrent checks matched solo and serial outputs. Four-stream median aggregate chat throughput was 183.31 tok/s for ModelOpt MTP3, 110.40 for ModelOpt no-draft, and 107.24 for Unsloth no-draft. Main could not admit four streams in these configurations.
Base/head cache-resume checks passed for ModelOpt MTP and Unsloth no-draft. Drafted versus
draft:false, concurrent versus solo, and greedy main/head output hashes matched. No GPU kernel or precision changed; kernel contract is n/a.Platforms run: Linux/CUDA SM120 on RTX 5090 Laptop GPU; Windows CI and macOS dev-tools CI passed. Other CUDA SMs, Metal, and HIP have not been run for this change.
Checklist
zig-band all other runnable checks passed exceptzig, whose only failure is the inherited environment-name check above. Both nightly jobs were skipped by workflow conditions.draft:false, concurrent/solo, and seeded greedy/sampled MTP3 comparisons passed.