Skip to content

Unsloth Studio (AMD/Windows): load Qwen-Image-2.1's FP8 text encoder without torchao - #11782

Closed
tweekli wants to merge 3 commits into
unslothai:mainfrom
tweekli:fix/te-plain-safetensors-load
Closed

tweekli wants to merge 3 commits into
unslothai:mainfrom
tweekli:fix/te-plain-safetensors-load

Conversation

@tweekli

@tweekli tweekli commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Fixes #11638

Motivation

A published text-encoder checkpoint can be a plain safetensors file with no torchao subclass metadata. On Windows ROCm, torch may have no torch.distributed, so torchao can be unavailable; the current gate then rejects a readable file and the later .pt fallback can appear as a missing artifact.

Changes

  • Separate plain-safetensors readability from torchao-flattened checkpoint support.
  • Load plain safetensors pre-quant text encoders directly.
  • Keep the stricter torchao path for checkpoints that actually carry torchao metadata.

Tests

pytest studio/backend/tests/test_prequant_safetensors.py::test_a_plain_safetensors_prequant_loads_without_torchao
pytest studio/backend/tests/test_diffusion_te_prequant.py::test_the_te_safetensors_gate_does_not_require_torchao

Focused tests pass locally.

@danielhanchen

Copy link
Copy Markdown
Member

Checked the diff against #11638: the readability gate in diffusion_te_prequant.py still requires torchao even for plain-tensor safetensors, which is what sends Windows ROCm to the missing .pt and the dense encoder. Will get this reviewed.

@LeoBorcherding

Copy link
Copy Markdown
Collaborator

the hosted unsloth/Qwen-Image-2.1-FP8 text encoder (Qwen-Image-2.1-text_encoder-FP8.safetensors) does carry tensor_names, with all 750 entries {"_type": "Tensor"}, alongside unsloth_format. so the new "tensor_names" not in raw branch in load_prequant_safetensors never runs for it. with this PR the readability gate passes, so Windows ROCm now downloads the fp8 encoder, then raises "cannot read a torchao safetensors…", and diffusion_te_prequant falls back to dense anyway (the except in load_prequant_text_encoder). treating a header whose entries are all _type: Tensor as plain would cover it; a test built from a torchao-written header would pin it.

read from the file's header over a range request and traced through the branch; not run on hardware.

@LeoBorcherding LeoBorcherding changed the title Read plain safetensors pre-quant text encoders without torchao Unsloth Studio (AMD/Windows): load Qwen-Image-2.1's FP8 text encoder without torchao Sep 25, 2026
@danielhanchen danielhanchen self-assigned this Sep 30, 2026
The hosted Qwen-Image-2.1 fp8 text encoder keeps tensor_names with every
entry {"_type": "Tensor"}, so the no-tensor_names branch never ran for it
and Windows ROCm still downloaded it, raised, then fetched the dense encoder.
Treat an all-Tensor header as plain, keep the leftover-tensor check and the
root-tensor restore, and pin it against torchao's own unflatten.
@danielhanchen

Copy link
Copy Markdown
Member

Thank you for the PR and for tracking down #11638! This is now fixed on main by #12333 (fa595c6), which takes the same approach at a narrower scope, so I'm closing this one as superseded.

For the record, what I checked here before #12333 landed:

  • The hosted Qwen-Image-2.1-text_encoder-FP8.safetensors header does carry tensor_names, with all 750 entries {"_type": "Tensor"}, so the original "tensor_names" not in raw branch never ran for it. On a torchao-less install the gate then passed, the 9 GB file downloaded, the loader raised, and it fell back to the dense encoder anyway. dec8600 fixed that by treating an all-Tensor header as plain, and with it the real artifact loaded without torchao.
  • Studio: load plain FP8 encoder safetensors without torchao #12333 does the same with a separate reader used only by the text-encoder loader, leaving the shared DiT reader untouched. On a B200 with torchao installed, the encoder it loads is bit-identical to the one torchao's unflatten produces, and on gfx1151 Windows without torchao the three resolver tests that fail on the old base now pass.

Thanks again for the report and the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] AMD: on Windows, Qwen-Image-2.1 downloads the 16 GB text encoder because torchao can't load

4 participants