Skip to content

from_single_file fails to load Qwen-Image and MotifVideo weights with the model.diffusion_model. prefix #15447

Backlog

Description

@Jackmeson1

Describe the bug

With an explicit local config, from_single_file loads Qwen-Image and MotifVideo weights correctly. Adding model.diffusion_model. to every key makes the same call fail. Removing just that prefix restores every tensor exactly. #14931 handled this prefix in the Cosmos converter after #14929.

Model Evidence at facc812ea
Qwen-Image (QwenImageTransformer2DModel), MotifVideo Reproduced with the public loader on tiny local .safetensors files. Both checkpoint mappings return the keys unchanged.
Lumina2 Verified with an original-format key. The converter moves model.diffusion_model.cap_embedder.0.weight to cap_embedder.0.weight, then calls pop with the old name and raises KeyError.
AuraFlow Verified with an original-format block key. For model.diffusion_model.double_layers.0.…, the layer counter tries to parse diffusion_model as an integer.
Stable Cascade, HunyuanVideo By source reading, both retain the prefix in converted names. Stable Cascade also misses its bare clip_txt_mapper.weight Stage C marker.
FLUX.2, FLUX.3 By source reading, FLUX.2 reads block indices at fixed positions. FLUX.3 matches exact keys and module prefixes. The outer prefix breaks those lookups.
MiniMax-H3 By source reading, the unpruned converter expects keys starting with blocks. and retains the outer prefix.

The last seven entries describe what happens if an otherwise supported original checkpoint carries the prefix. We haven’t verified it in a published file for these families.

Would you prefer converter-local handling, as in #14931, or a shared step that affected denoisers opt into after config selection and before key comparison and conversion? The legacy LDM UNet loader uses the original namespace to extract UNet and EMA weights. I can prepare a PR once we agree on scope.

Reproduction

This CPU script writes the same tensors twice and changes only the key prefix. It checks the loaded weights against the source, including on systems where the call returns a model.

import tempfile
from pathlib import Path

import torch
from safetensors.torch import save_file
from diffusers import QwenImageTransformer2DModel, MotifVideoTransformer3DModel
from diffusers.utils import logging

logging.set_verbosity_error()
torch.manual_seed(0)
models = [
    QwenImageTransformer2DModel(
        patch_size=2, in_channels=16, out_channels=4, num_layers=2,
        attention_head_dim=8, num_attention_heads=2,
        joint_attention_dim=16, axes_dims_rope=(2, 2, 4),
    ),
    MotifVideoTransformer3DModel(
        in_channels=33, out_channels=16, num_attention_heads=2,
        attention_head_dim=12, num_layers=1, num_single_layers=1,
        num_decoder_layers=0, text_embed_dim=32, image_embed_dim=4,
        rope_axes_dim=(4, 4, 4),
        enable_text_cross_attention_dual=False,
        enable_text_cross_attention_single=False,
    ),
]
for source in models:
    cls = type(source)
    state = {k: v.contiguous() for k, v in source.state_dict().items()}
    with tempfile.TemporaryDirectory() as directory:
        source.save_config(directory)
        for label, prefix in [("plain", ""), ("prefixed", "model.diffusion_model.")]:
            checkpoint = {prefix + k: v for k, v in state.items()}
            path = str(Path(directory) / f"{label}.safetensors")
            save_file(checkpoint, path)
            try:
                loaded = cls.from_single_file(path, config=directory, local_files_only=True)
                actual = loaded.state_dict()
                meta = sum(v.is_meta for v in actual.values())
                equal = not meta and actual.keys() == state.keys() and all(
                    torch.equal(actual[k], v) for k, v in state.items()
                )
                print(cls.__name__, label, f"meta={meta}", f"equal={equal}")
            except Exception as error:
                print(cls.__name__, label, type(error).__name__, str(error).split(";")[0])
        stripped = {k.removeprefix("model.diffusion_model."): v for k, v in checkpoint.items()}
        loaded = cls.from_single_file(stripped, config=directory, local_files_only=True)
        assert all(torch.equal(loaded.state_dict()[k], v) for k, v in state.items())
        print(cls.__name__, "stripped: all tensors equal")

Logs

QwenImageTransformer2DModel plain meta=0 equal=True
QwenImageTransformer2DModel prefixed NotImplementedError Cannot copy out of meta tensor
QwenImageTransformer2DModel stripped: all tensors equal
MotifVideoTransformer3DModel plain meta=0 equal=True
MotifVideoTransformer3DModel prefixed NotImplementedError Cannot copy out of meta tensor
MotifVideoTransformer3DModel stripped: all tensors equal

System Info

Linux CPU (Colab), Python 3.12.3, Diffusers editable at facc812ea, PyTorch 2.15.0+cpu, Transformers 5.24.1.

Who can help?

@DN6

AI-assisted: prepared with Claude Code and OpenAI Codex; the log above is from running the script on a Colab CPU runtime.

Activity

  1. outerheaven199X commented on Dec 1, 2026

    @outerheaven199X

    Hey Jack, how's it going.

    I checked single_file_model.py and single_file_utils.py, and an opt-in shared strip in from_single_file looks cleaner than patching each converter separately (since QwenImageTransformer2DModel and MotifVideoTransformer3DModel both use a pass-through lambda checkpoint, **kwargs: checkpoint in SINGLE_FILE_LOADABLE_CLASSES).

    One edge case comes up if you place the strip after config selection and a caller omits config. Because fetch_diffusers_config(checkpoint) calls infer_diffusers_model_type before conversion, flux2, flux3, and lumina2 already list both unprefixed and model.diffusion_model. keys in CHECKPOINT_KEY_NAMES, whereas auraflow, hunyuan-video, minimax-h3, and stable_cascade_stage_c only list unprefixed markers (and Qwen-Image and MotifVideo don't have entries there yet). So a post-config shared strip will handle explicit-config loads across those denoisers without touching the legacy LDM UNet/EMA namespace logic, while config=None auto-detection for prefixed checkpoints would still need CHECKPOINT_KEY_NAMES entries or a prefixed lookup fallback.

  2. Jackmeson1 commented on Dec 1, 2026

    @Jackmeson1
    Author

    Thanks, that matches what I found. With an explicit config, a shared strip would cover these denoisers. For config=None, AuraFlow, HunyuanVideo, MiniMax-H3 and Stable Cascade would also need prefixed markers in CHECKPOINT_KEY_NAMES (or a prefixed fallback in infer_diffusers_model_type), and Qwen-Image and MotifVideo would need entries. I'll wait for a maintainer to choose the shape before opening a PR.

  3. outerheaven199X commented on Dec 1, 2026

    @outerheaven199X

    Awesome. Let me know if I can help further?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions