Repository navigation
fix(model-manager): use float32 for CPU Wan GGUF encoders - #10352
wunianze666-netizen wants to merge 3 commits into
Conversation
Resolve dtype and cache placement from the execution target. Account for widened GGUF weights in the initial RAM reservation.
joshistoast
left a comment
There was a problem hiding this comment.
The CPU FP32 fix itself looks right, and the regression tests are solid: main's wan.py fails most of them. I'm requesting changes mostly because of the get_size_fs override. It adds a few seconds to every cold load without changing what gets reserved. Details are inline.
Must fix
- Drop the text-encoder branch of
get_size_fs.unpack_ggml_at_loadalready makes the same reservation, and the branch adds a full GGUF header parse inside the model-load write lock.
Should fix
- Say how much more RAM the CPU /
cpu_onlypath now uses, in the PR body and in the Wan docs. _umt5_compute_dtypedocstring: it no longer holds for CPU, and the dtype rule is now split across two functions.- Remove the
float32_on_cputest fixture, which no longer does anything.
Nit
test_an_incomplete_encoder_never_enters_the_cachetests behaviour this PR doesn't change.
All 20 tests in the PR's test file pass locally (torch 2.7.1, macOS, CPU only). I didn't test on a GPU or with a full-size GGUF, and I didn't measure RAM or encode speed.
|
Thanks for the review. |
joshistoast
left a comment
There was a problem hiding this comment.
Thanks for the follow-up. Everything from the last round is addressed, and the fix itself is right: CPU and cpu_only get float32, and accelerator behaviour is unchanged. I'm requesting changes because the branch no longer works against current main, which is why CI is red.
Must fix
- Rebase onto
main. #10171 changed the cache-key format, and this PR's variant does not fit it.test_cache_keeps_encoder_dtypes_separate_and_reuses_the_tokenizerfails after the merge (1 failed, 19 passed locally, sameIndexErroras CI).
Should fix
- Put back one loose check on the RAM reservation. Nothing tests it now.
- Reword the docs paragraph so it states current behaviour.
Nits
- The header-read test and the 8-case weight-bytes test add little.
- PR body: tick "Documentation added / updated", and the "two header opens at
e3e63bc" line compares against this PR's own first commit, notmain.
What I ran
- Head: 20 passed (Linux, CUDA host, and again with CUDA hidden). Ruff clean.
- Head merged with
main(f7e17da392): 1 failed, 19 passed. - Tiny GGUF on a real CUDA GPU: bfloat16 on the GPU, float32 with
cpu_only, both match the dense reference. - Not run: a full-size UMT5-XXL GGUF (RAM, speed), MPS/XPU, Wan generation.
|
Thanks for the follow-up. I integrated main in |
joshistoast
left a comment
There was a problem hiding this comment.
Thanks, everything from the last round is addressed. Looks good to merge. One optional nit inline.
| def _get_execution_device( | ||
| self, config: AnyModelConfig, submodel_type: Optional[SubModelType] = None | ||
| ) -> Optional[torch.device]: | ||
| device = super()._get_execution_device(config, submodel_type) | ||
| if submodel_type is SubModelType.TextEncoder: | ||
| return device or self._ram_cache.execution_device | ||
| return device |
There was a problem hiding this comment.
Nit, not blocking: this override doesn't change anything in production. The loader's default device already matches its cache's device, and put() treats the cache's own device the same as None. It's only needed because some tests patch choose_torch_device to a different device than the cache. If those tests built each loader on its cache's device, this could go.
Summary
Standalone Wan UMT5 GGUF encoders use FP32 on CPU, including with Run on CPU. Accelerators use BF16 where supported and FP32 when BF16 is unavailable. The loader uses one per-load decision for the cache key and the encoder weights. The CPU FP32 cache record stays separate from an accelerator FP32 record that is still in use, and both keys decode to the installed model for calibration. CPU and accelerator requests reuse the same tokenizer.
The Wan guide gives estimated resident weights of about 9 GB on CPU and 7 GB in accelerator BF16 for Q8_0, and 23 GB on CPU and 11 GB in accelerator BF16 for F16, BF16, and F32 GGUFs. Loading workspace is additional. Encoder admission uses the file size before the read, and the unpacker reserves for resident weights and temporary workspace before allocating. Quantized linear weights stay packed.
Related Issues / Discussions
Refs #10215. #10344 covers the separate Wan safetensors loader.
QA Instructions
IndexError.Review
The first round removed the redundant header parse introduced in this PR and reused the shared T5 dtype selection. First review
The second round integrated the current cache-key API, restored a RAM reservation check, and updated the Wan guide. Current review
AI assistance was used for implementation and verification.
Checklist
What's Newcopy (if doing a release after this PR)Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.