Repository navigation
Studio: quantise the hosted int8 leftovers on the GPU on offloaded loads - #17002
Conversation
…e uploads The hosted Qwen-Image int8 file leaves the text-stream projections and the img_mod/txt_mod modulations dense. On an offloaded load both were quantised on the host: the leftovers hopped to the GPU one module at a time, the modulations were split and quantised on the CPU. Both now go through one helper that quantises each host-placed Linear on the CUDA device and moves it back, with the next upload overlapping the current quantise. Same codes, scales and outlier columns as the CPU path.
A pageable host-to-device copy of the dense leftovers ran at about 1-2 GB/s on the Colab A100 host (11 s for the 360 text-stream Linears, 13 s for the 120 modulations). Each host tensor now goes through a pinned copy (the caching host allocator, emptied after the loop) and a non-blocking upload; anything that cannot be staged exactly falls back to module.to.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b8ed270884
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| work = torch.device(device) | ||
| except Exception: # noqa: BLE001 - an unparsable device quantises in place | ||
| return None | ||
| return work if work.type == "cuda" else None |
There was a problem hiding this comment.
Resolve the CUDA ordinal before starting the upload thread
When device is the unindexed "cuda" and the loading thread has selected a nonzero GPU, this leaves work.index unset. _hop_loop now executes uploads on a fresh executor thread, which does not inherit the caller's thread-local CUDA device, so .to(work) resolves to GPU 0 instead of the selected GPU. This is reachable through the cached-prequant loader in diffusion.py, which passes target.device (intentionally unindexed in DiffusionDeviceTarget). Consequently, offloaded loads can allocate large temporary weights on another user's GPU or fail quantization because GPU 0 lacks memory, whereas the previous synchronous loop used the caller's selected device. Resolve an omitted index using torch.cuda.current_device() before handing the device to the worker, or explicitly propagate the caller's CUDA device into that thread.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b22df9e: _hop_device resolves an unindexed cuda to torch.cuda.current_device() in the calling thread before the upload thread starts. Added a test for the resolution.
The hop now uploads on a helper thread, which does not inherit the loading thread's current CUDA device, so an unindexed "cuda" (the cached prequant loader passes one) would land the uploads on cuda:0. _hop_device resolves it to the caller's current card first.
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
The hosted Qwen-Image-2512 int8 file stores 360 Linears as int8. It leaves the text-stream projections (
add_q/k/v_proj,to_add_out,txt_mlp) and the 120img_mod/txt_modmodulations dense, and the runtime quantises them after the load. On an offloaded load, where the transformer stays on the host, the two runtime passes ran like this:On a fresh 8 GiB load on a Colab A100 that came to about 10 s plus 41-44 s of the load.
This PR sends both passes through one helper. Each host-placed Linear is uploaded to the CUDA device through page-locked copies, split and quantised there, and moved back. The next module's upload overlaps the current quantise on a helper thread. The codes, the scales and the outlier columns are the same as the CPU path: the helper only moves tensors, and torchao's per-row int8 math gives the same bits on both devices (checked below). Without a CUDA device, or for a tensor that cannot be staged exactly, the old in-place /
module.topath runs.The integrity fingerprint is untouched: it still hashes every quantised weight.
Measurements
Colab A100-40 GB, Qwen/Qwen-Image-2512 with the default int8 build (hosted
unsloth/Qwen-Image-2512-FP8int8 + int8 ConvRot encoder), 1024x1024, 20 steps, CFG 4. Each arm runs in a fresh process with a fresh Studio home, and base and head are interleaved. Base is main3d41bf4af3, and head is this branch.8 GiB VRAM budget (streamed placement), final head:
The first base arm of each run is slower, because it reads the checkpoint cold. An earlier run of the first commit alone (no page-locked staging) gave a median load of 88.6 s for base and 56.7 s for head.
Resident (no budget): load 24.2 s vs 23.9 s, first image 26.2 s vs 26.1 s, steady 11.26 s on both. The resident path never quantises on the host, so this is the no-change control.
Outputs: every image is bit-identical between base and head (same file md5 for all 3 prompts in every pair, at 8 GiB and resident).
Quantise parity on the A100 (torch 2.13.0+cu130, torchao 0.18.0): the CPU path and the CUDA hop were run on the Qwen-Image Linear shapes (3072x18432, 3072x3072, 3072x12288, 12288x3072). This covered int8 weight-only with and without 4 outlier columns, and W8A8. All of them give identical canonical weight digests and identical dense tensors (
PARITY_OK).Tests
tests/test_diffusion_quant_hop.py(new) covers four cases:tests/test_diffusion_qwenimage_mod_int8.py,tests/test_diffusion_qwenimage_text_int8.pyandtests/test_diffusion_prequant.pypass unchanged.