Skip to content

fix(flux2): honor the VAE compute device when encoding FLUX.2 reference images - #10250

Open
mvanhorn wants to merge 1 commit into
invoke-ai:mainfrom
mvanhorn:fix/10204-flux2-reference-vae-device
Open

mvanhorn wants to merge 1 commit into
invoke-ai:mainfrom
mvanhorn:fix/10204-flux2-reference-vae-device

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

FLUX.2 reference-image generation can fail with a CUDA/CPU device mismatch when the VAE runs on CPU. Generation without a reference image can still succeed. Reference-image encoding selected the global default device instead of the VAE's compute device. This could place image tensors on CUDA while the VAE weights remained on CPU, and use the wrong device for tiling and memory estimates.

Reference-image encoding now uses vae_info.compute_device. Regression tests cover a CPU VAE with a mocked CUDA default, checking latent output and device selection for memory estimates and conditional tiling. Another test checks that encoding failures preserve the shared VAE's tiling settings and propagate the original exception.

Related Issues / Discussions

Closes #10204

QA Instructions

./scripts/family_e2e could not run in this environment for the InvokeAI encode_reference_image change (./scripts/family_e2e is not in this checkout).
uv run --frozen --project . pytest -q tests/backend/flux2/test_reference_encode_tiling.py failed during conftest loading because torch was unavailable; no tests ran.
./scripts/family_e2e could not run because the script was absent from the checkout.
A run with the InvokeAI encode_reference_image change reverted gave no clear result, so no test is shown to catch this bug.
The changed test tests/backend/flux2/test_reference_encode_tiling.py did not run here: the torch module is not installed.

Review

Not applicable to this change.

Compatibility / Rollout

Not applicable to this change.

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)

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

…ce images

Reference-image encoding now uses vae_info.compute_device. Regression
tests cover a CPU VAE with a mocked CUDA default, checking latent output
and device selection for memory estimates and conditional tiling.
Another test checks that encoding failures preserve the shared VAE's
tiling settings and propagate the original exception.

Fixes invoke-ai#10204
@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 12, 2026
@Pfannkuchensack Pfannkuchensack self-assigned this Nov 12, 2026

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: FLUX.2 Klein reference image fails with CUDA/CPU BFloat16 device mismatch

2 participants