Skip to content

device: fit a Qwen4 pack by the bytes it holds in GPU memory - #6477

Merged
ashhart merged 3 commits into
mainfrom
lead/qwen4-device-fit
Dec 5, 2026
Merged

ashhart merged 3 commits into
mainfrom
lead/qwen4-device-fit

Conversation

@ashhart

@ashhart ashhart commented Dec 5, 2026

Copy link
Copy Markdown
Owner

tensorfold device compared a Qwen4 checkpoint's whole snapshot with the machine's weight budget. The Qwen4 engine never uploads its PLE n-gram tables: it reads the rows each step needs from the read-only file mapping. So a 64 GB Mac reported the Qwen4-35B-A3B TFQ packs (53 to 63 GiB on disk, 17.5 to 26.9 GiB held in GPU memory) as too large, although they load.

What changes:

  • New cli/resident.zig: sums the .ple.ple_embedding.ngram_embedding. tensors from each safetensors header (no tensor bytes read), for qwen4 and qwen4_text only. Every other family keeps its whole size.
  • models.onDisk returns the resident bytes; tensorfold device fits by them and the report line names both sizes when they differ, e.g. 60.8 GiB (25.0 GiB in GPU memory; its lookup tables stay on disk): fits. --json gains a resident field.
  • A 64 GB M5 Pro fixture: all three packs read too_large by size on disk and fits by resident bytes.

Load path, kernels and output tokens are unchanged; no new refusal.

Checks: test-device (2 new tests), test-cli (same results as main plus the new test), check-native-cuda-host, test-cli-host, test-gradient-serving, test-qwen4-host, test-qwen4-ple-host, zig fmt --check --ast-check, pr_check.py --base main (lean, cycle and cross-family counts unchanged). Each new test fails when its change is removed.

  • Synthena

@ashhart

ashhart commented Dec 5, 2026

Copy link
Copy Markdown
Owner Author

READY to land on this head. Device report only (CLI fit check); no served path, kernels or tokens touched. test-device, test-cli, check-native-cuda-host, test-cli-host, test-gradient-serving, test-qwen4-host, test-qwen4-ple-host, fmt/AST and pr_check pass; each new test fails without its change.

  • Synthena

@ashhart

ashhart commented Dec 5, 2026

Copy link
Copy Markdown
Owner Author

READY to land on this head. Device report and tensorfold info only; no served path, kernels or tokens touched. test-device, test-cli, check-native-cuda-host, test-cli-host, test-gradient-serving, test-qwen4-host, test-qwen4-ple-host, fmt/AST and pr_check pass; each new test fails without its change.

  • Synthena

The Qwen4 engine never uploads its PLE n-gram tables: device_weights
`take` skips every table role and `lookup` reads the needed rows from the
read-only mapping each step. `tensorfold device` still compared the whole
snapshot with the weight budget, so a 64 GB Mac read the Qwen4-35B-A3B TFQ
packs (53 to 63 GiB on disk, 17.5 to 26.9 GiB resident) as too large.

models.onDisk now also returns the resident bytes: the snapshot's size
less the `.ple.ple_embedding.ngram_embedding.` tensors in its safetensors
headers, for qwen4 and qwen4_text only. The device verdict uses that, and
the report line names both sizes when they differ. Load, kernels and
output tokens are unchanged; other families keep their whole size.
`tensorfold info` still printed a Qwen4 checkpoint's whole snapshot as
its weights and priced the memory floor on it, while `tensorfold device`
now uses the resident bytes. For qwen4 and qwen4_text, info now takes
the same resident.residentBytes: the weights line names the bytes held
in GPU memory, a new "on disk:" line names the snapshot's size and the
PLE lookup tables left on disk, and the floor adds the margin to the
resident bytes. Every other family prints byte for byte as before.
Load, kernels and output tokens are unchanged.
@ashhart
ashhart force-pushed the lead/qwen4-device-fit branch from ef5b8ca to 7d2417b Compare December 5, 2026 12:37
@ashhart
ashhart merged commit 7a4d3d4 into main Dec 5, 2026
8 of 12 checks passed
@ashhart
ashhart deleted the lead/qwen4-device-fit branch December 5, 2026 12:37
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