Skip to content

fix(model-manager): use float32 for CPU Wan GGUF encoders - #10352

Open
wunianze666-netizen wants to merge 3 commits into
invoke-ai:mainfrom
wunianze666-netizen:fix/wan-umt5-gguf-cpu-10215
Open

wunianze666-netizen wants to merge 3 commits into
invoke-ai:mainfrom
wunianze666-netizen:fix/wan-umt5-gguf-cpu-10215

Conversation

@wunianze666-netizen

@wunianze666-netizen wunianze666-netizen commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Windows CPU baseline with the PR head merged into current main: 19 passed and the original warm-cache test reproduced the CI IndexError.
  • Windows CPU candidate: 20 focused tests passed. They cover CPU numerics, simulated accelerator selection, pinned FP32 isolation, calibration attribution, tokenizer reuse, and RAM reservation bounds. Related loader, cache, quantization, and calibration checks finished with 383 passed and 8 skipped.
  • Ruff lint and format, Git whitespace checks, and targeted MDX compilation passed. The local checks used tiny fixtures and simulated accelerator selection. Physical accelerators, full-size peak RAM, and Wan family generation were not tested locally.

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

  • The PR has a short but descriptive title, suitable for a changelog
  • Meaningful regression coverage added / updated where needed; obsolete tests/code removed
  • Persisted-state and API changes include required migrations / compatibility validation
  • Relevant performance/efficiency opportunities considered; material claims have evidence
  • Material review findings resolved and relevant checks rerun
  • Documentation added / updated (if applicable)
  • Updated What's New copy (if doing a release after this PR)

Run Proof
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Resolve dtype and cache placement from the execution target. Account for widened GGUF weights in the initial RAM reservation.
@github-actions github-actions Bot added python PRs that change python files backend PRs that change backend files python-tests PRs that change python tests labels Nov 22, 2026
@lstein lstein added the 7.0.0 label Nov 22, 2026
@lstein lstein moved this to 7.0.0: UX overhaul in Invoke - Community Roadmap Nov 22, 2026

@joshistoast joshistoast left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_load already 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_only path now uses, in the PR body and in the Wan docs.
  • _umt5_compute_dtype docstring: it no longer holds for CPU, and the dtype rule is now split across two functions.
  • Remove the float32_on_cpu test fixture, which no longer does anything.

Nit

  • test_an_incomplete_encoder_never_enters_the_cache tests 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.

@github-actions github-actions Bot added the docs label Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. a39699b499 removes the extra GGUF header pass under the model-load lock. The same real cold-load fixture now opens the header once instead of twice, and the unpacker still reserves retained weights and temporary workspace. CPU FP32 and the accelerator fallback use the shared T5 device rule. I also updated the Wan docs with the standard-shape resident RAM estimates. Windows CPU verification: 20 focused passes and 293 related passes with 8 skips.

@joshistoast joshistoast left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_tokenizer fails after the merge (1 failed, 19 passed locally, same IndexError as 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, not main.

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.

Copy link
Copy Markdown
Contributor Author

Thanks for the follow-up. I integrated main in 2e77e39b82 with a normal merge to keep the existing branch history. The encoder now uses the current storage-key format, with a distinct CPU FP32 record that still resolves to the installed model for calibration. The warm-reload test exercises the loader, and the RAM check covers both file admission and retained weights without depending on call order. The original combined tree reproduced the CI IndexError. Windows CPU checks passed on the revision: 20 focused and 383 related, with 8 skips. The guide now describes Run on CPU and labels the RAM figures as estimates.

@joshistoast joshistoast left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, everything from the last round is addressed. Looks good to merge. One optional nit inline.

Comment on lines +849 to +855
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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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

7.0.0 backend PRs that change backend files docs python PRs that change python files python-tests PRs that change python tests

Projects

Status: 7.0.0: UX overhaul

Development

Successfully merging this pull request may close these issues.

4 participants