Skip to content

Qwen3.5: offload BF16 input embeddings to host RAM - #5052

Draft
tacosta wants to merge 1 commit into
ashhart:mainfrom
tacosta:feat/4942-qwen35-host-embeddings-evidence
Draft

tacosta wants to merge 1 commit into
ashhart:mainfrom
tacosta:feat/4942-qwen35-host-embeddings-evidence

Conversation

@tacosta

@tacosta tacosta commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Qwen3.5 CUDA can keep BF16 input embeddings in mapped host RAM. --embedding-residency auto|device|host selects host rows when device-memory admission requires them or honors explicit placement. The BF16 row payload is copied unchanged. Supported checkpoint formats are ModelOpt NVFP4 and compressed-tensors NVFP4, including Unsloth; the embedding table itself remains BF16. Existing EXL3 automatic offload behavior is retained.

The shared MTP sizing helper is used so embedding auto-selection accounts for an active drafter’s actual startup and resident memory. It preserves the existing scratch layout and does not reduce recurrent scratch or implement the separate MTP charge change from #5134; the admission calculation includes allocator alignment padding (zero for the tested Qwen3.8-27B geometry).

Checks

  • Focused host tests for embedding offload/admission, supported formats, MTP selection/memory, CLI residency, and execution witness passed.
  • zig fmt --check and git diff --check passed.
  • CUDA product build for sm_120 passed.
  • Lean check: 123 findings on base and head, 0 new.
  • Required zig build test test-golden: 14,211 passed, 107 skipped; one XPU-only test failed during Level Zero initialization (zeInit: 0x78000001). Golden comparison reported 327/340 equal and 0 unexpected differences (13 known differences). The failure is recorded as an environment limitation; a baseline reproduction was not completed.
  • GPU smoke validation ran on an RTX 5090 Laptop GPU with 24,463 MiB VRAM. These are single-run measurements, not performance claims.

ATC overlap

Latest scan: 2026-11-27 03:12 UTC, against base 77eae824e425d7d3bea11f15e191983b99b53ba8. It is incomplete because of GitHub result limits. It reports conflicts with PRs #3729, #3567, #3566, #3565, #3564, and #3563, plus 108 overlaps with unknown status. One overlapping worktree is stale and was excluded from this work as directed. The remaining overlap evidence is noted for coordination.

Receipt

  • Platform/path covered: Qwen3.5 CUDA embedding load and serve paths for ModelOpt and compressed-tensors NVFP4; BF16 embeddings are placed in mapped host RAM when selected.
  • Setting: --embedding-residency, values auto, device, host; default auto.
  • Exactness evidence: at 4K with ModelOpt NVFP4 and MTP3, device and host embedding placement produced identical output hashes.
  • Main-against-branch performance comparison: not run. The smoke runs below establish successful execution and placement equivalence only.
  • No weights or drafter are added.

Checklist

  • The title and description match the updated head, including scope and receipt.
  • New tests were not run against the pre-change revision, and missing-dependency skip behavior was not separately qualified.
  • Formatting and diff checks passed; the patch contains no local paths, machine identifiers, or AI attribution lines.
  • Embedding row payload remains BF16 and is copied unchanged.
  • Host and device embedding placement produced identical output hashes in the 4K ModelOpt NVFP4 + MTP3 smoke check.
  • Comparison against draft: false, resumed versus fresh prompts, concurrent versus solo requests, and main-versus-branch performance remain unqualified.

@tacosta
tacosta force-pushed the feat/4942-qwen35-host-embeddings-evidence branch from 3081dd2 to bf0e6f6 Compare November 25, 2026 14:34
@tacosta tacosta changed the title Qwen3.5: offload NVFP4 embeddings to host RAM Qwen3.5: offload BF16 input embeddings to host RAM Nov 25, 2026
@tacosta
tacosta force-pushed the feat/4942-qwen35-host-embeddings-evidence branch from bf0e6f6 to 7c5b820 Compare November 25, 2026 15:32
@tacosta

tacosta commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

24 GB Qwen3.8-27B context and VRAM measurement

Measured on an NVIDIA GeForce RTX 5090 Laptop GPU (24,463 MiB) using TensorFold commit 7c5b8202da6968912980b9cb4b04df0ff29ec2ab.

Both variants were started with explicit host embedding residency, one stream (--parallel 1), BF16 target KV, the checkpoint's own MTP drafter (--drafter <same checkpoint> --mtp-drafts 3), and the default 1 GiB CUDA admission reserve. The server accepted the listed maximum context at startup and rejected the next token on its CUDA memory admission check.

Checkpoint Max / first rejected Target BF16 KV MTP KV ring Non-context CUDA active CUDA active / peak NVML process / card free
NVIDIA ModelOpt NVFP4 56,014 / 56,015 3.419 GiB 0.214 GiB 17.769 GiB 21.402 / 21.447 GiB 21.686 / 1.662 GiB
Unsloth NVFP4 25,053 / 25,054 1.529 GiB 0.096 GiB 19.778 GiB 21.402 / 21.565 GiB 21.684 / 1.664 GiB

Safetensors source payload breakdown:

Checkpoint Target body LM head Target subtotal Host input embeddings MTP drafter source
NVIDIA ModelOpt NVFP4 16.591 GiB 0.666 GiB 17.257 GiB 2.368 GiB 0.791 GiB
Unsloth NVFP4 17.465 GiB 1.185 GiB 18.650 GiB 2.368 GiB 0.791 GiB

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 compressed-tensors, and its Safetensors index contains weight_packed tensors. TensorFold's Qwen CUDA loader maps these to NVFP4. The generic tensorfold info formatter's “full precision” label does not identify compressed-tensors formats.

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.

@tacosta

tacosta commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

24 GB VRAM follow-up: reserve and FP8 KV experiment

Hardware: NVIDIA GeForce RTX 5090 Laptop GPU, 24,463 MiB capacity (23.89 GiB, sm_120).
Common setup: Qwen3.8-27B ModelOpt NVFP4 or Unsloth NVFP4, input embeddings in host RAM, one stream, MTP drafts=3.

Checkpoint KV / reserve Context started Next tested rejection CUDA active / NVML free
NVIDIA ModelOpt NVFP4 BF16 / 1.0 GiB 56,014 56,015 21.402 GiB / 1,662 MiB
Unsloth NVFP4 BF16 / 1.0 GiB 25,053 25,054 21.402 GiB / 1,704 MiB
NVIDIA ModelOpt NVFP4 BF16 / 0.5 GiB 63,724 64,000 21.902 GiB / 1,190 MiB
Unsloth NVFP4 BF16 / 0.5 GiB 32,763 not searched above 21.902 GiB / 1,192 MiB
NVIDIA ModelOpt NVFP4 FP8 / 0.5 GiB* 118,500 119,000 21.894 GiB / 1,198 MiB
Unsloth NVFP4 FP8 / 0.5 GiB* 59,000 60,000 21.831 GiB / 1,262 MiB

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.

@tacosta

tacosta commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

24 GB VRAM follow-up: tap ring and recurrent scratch

A 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 stream_bytes was computed before that and MTP's per-stream facts omit the target tap. The physical CUDA-active sample after cache reservation includes the allocated ring in its non-context remainder; the per-stream admission charge does not. The previously reported startup acceptance points therefore remain observations of the current code, not corrected admission limits; they need a rerun after this charge is fixed.

The 0.13 GiB variation. The earlier 17.83 GiB run logged CUDA window costs: measured 64 widths; all three controlled repeats logged cached 64 widths and charged 17.96 GiB. A cache hit warms widths 1–64, then checkKept probes width 32. For this geometry, logBytes(32) is 138,706,944 bytes = 0.12918 GiB. The 64-row log plus that 32-row log totals 416,120,832 bytes, below the pool's 431,357,952-byte bound, so the cached validation retains both; the cold width sweep collects the smaller idle logs when it acquires the 64-row log. That is the observed delta. The model charge is sampled before stream reservation, so calibration scratch affects admission. Forward graphs read per-forward segment metadata from the stable e.tables buffer, so they do not retain a direct pointer to these recurrent log allocations; an idle/collect after calibration can reclaim them safely.

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 log64 must stay for this exact configuration unless copy width is capped or copies are disabled. The separate one-row before-state copy is unnecessary for ordinary inference: the lane acceptance path always starts with row 0, and inference passes undo = false; the before copy is used by the empty-path single-row rollback case. Prefill runs are unrecorded, and cancellation/yield checks happen between completed cuts, retaining only the last completed prefix.

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 log64. After adding the omitted 60 MiB tap charge, the net modeled per-stream reduction would be about 0.0848 GiB. This is a source-derived opportunity, not a new context-capacity result. No code or context limit was changed in this audit.

Sources: tap sizing and allocation, target stream charge, MTP stream facts, cost-cache validation, recurrent bound, and copy width setup.

@tacosta
tacosta force-pushed the feat/4942-qwen35-host-embeddings-evidence branch 4 times, most recently from 00a7fe7 to 3fdd3d9 Compare November 26, 2026 00:54
@tacosta
tacosta force-pushed the feat/4942-qwen35-host-embeddings-evidence branch from 3fdd3d9 to a7c26dd Compare November 27, 2026 07:01
@tacosta

tacosta commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Qualification evidence for a7c26dd98e7bd5c8b97a0edbbd5686bdca5e0735

Build and host checks

  • zig fmt --check build.zig zig and git diff --check upstream/main...HEAD: passed.
  • Focused host targets passed: test-qwen35-embedding-offload-host, test-qwen35-modelopt-admission-host, test-qwen35-formats-host, test-qwen35-mtp-selection-host, test-qwen35-mtp-memory-host, test-embedding-residency-cli-host, and test-execution-witness-host.
  • CUDA product build with -Dgpu=sm_120 -Dnvcc=/usr/local/cuda/bin/nvcc: passed (NVCC warnings only).
  • Lean checker: 123 findings on base and 123 on head, 0 new.
  • zig build -j2 test test-golden: 14,211 tests passed, 107 skipped. The aggregate job exited 1 only at test-lfm3-xpu-refusal-host, where Level Zero initialization returned zeInit: 0x78000001. This is an XPU initialization failure; a baseline reproduction was not completed. Golden comparison: 327/340 equal, 0 unexpected differences (13 known differences).

Runtime smoke checks on 24 GB VRAM

Hardware: RTX 5090 Laptop GPU, 24,463 MiB reported VRAM. All figures below are single-run smoke measurements; they are not a controlled performance comparison.

Checkpoint revisions from local Hugging Face metadata: ModelOpt dbb8f445b3145f8a4c18ddc769f032d57d32867c; Unsloth 60e813d4dbbdc5d64cf3f5a8caf2897bedf03679.

  • ModelOpt NVFP4 Qwen3.8-27B, 4K context, MTP3: device embeddings and explicit host embeddings each completed 32 output tokens; both reported 20/35 accepted drafts and the same output SHA-256 (7d0808c8bd37770f196096221330c17c52e2246a95f4907540b6d3086e0f4604). Measured decode rates were 77.3 tok/s (device) and 83.9 tok/s (host), one request each.
  • ModelOpt NVFP4 Qwen3.8-27B, 32K context, auto host embeddings, MTP3: prompt 32,759 tokens, context 32,768, completion 8; 4/4 drafts accepted, 52.3 tok/s. The engine log confirmed host-mapped embeddings and the MTP drafter. During the request, device use was 20,737 MiB with 3,248 MiB free.
  • Unsloth compressed-tensors NVFP4 Qwen3.8-27B, 4K context, host embeddings: completed an 8-token smoke request at 32.3 tok/s; MTP was not enabled for this run.

The result supports successful host embedding placement for both requested NVFP4 families. The short, single-run samples do not establish a general speedup or a main-versus-branch performance comparison.

Scope and overlap

MTP sizing is shared with the embedding residency planner so the auto decision includes the active drafter’s startup and resident requirements. Its scratch layout is unchanged; this does not reduce recurrent scratch or implement #5134’s separate MTP charge change. The admission formula now includes at most 255 bytes of alignment padding (zero for this tested model geometry).

ATC overlap scan at 2026-11-27 03:12 UTC, base 77eae824e425d7d3bea11f15e191983b99b53ba8: incomplete due to GitHub result limits; conflicts listed with #3729, #3567, #3566, #3565, #3564, and #3563; 108 overlaps have unknown status. One worktree overlap is stale per the task instructions.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant