Repository navigation
Studio: load ComfyUI Krea-2 and HunyuanImage-2.1 single-file DiTs - #12885
Merged
Merged
Conversation
Register original-layout converters for Krea2Transformer2DModel and HunyuanImageTransformer2DModel, which diffusers ships without a single-file mapping. Every rule is a rename, a row split or a whole-row reorder, so the ComfyUI int8 / fp8 loader keeps codes and scales exact. Krea 2 has no from_single_file at all, so a plain bf16 file loads through a small strict loader that casts like from_pretrained. HunyuanImage takes both the reference-repo and ComfyUI namings, and the guidance-distilled MeanFlow files get their config, shift 4 schedule and no CFG guiders.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ComfyUI's Krea 2 and HunyuanImage 2.1
diffusion_modelsfiles did not load in Studio at all:Krea2Transformer2DModel has no single-file converter; the bf16 file failed earlier, becauseKrea2Transformer2DModelhas nofrom_single_file.FromOriginalModelMixin is currently only compatible with ....diffusers ships both transformers without a single-file mapping. This PR registers one for each in the same table that already covers Qwen-Image-2.1 (
_UNREGISTERED_SINGLE_FILE_CLASSES, never overriding an upstream entry), so both the plain path and the ComfyUI int8 / fp8 loader pick them up.What changed
core/inference/diffusion_single_file_converters.py(new)krea2_checkpoint_to_diffusers: renames, plusblocks.N.mod.lin[6 * hidden]viewed asscale_shift_table[6, hidden](a 1-D, never-quantized tensor).hunyuanimage_checkpoint_to_diffusers: takes both original namings, the reference repo's (img_attn_qkv,mlp.fc1,mod.linear; Comfy-Org's bf16 file) and ComfyUI's (img_attn.qkv,mlp.0,mod.linundermodel.model.; its fp8 and distilled files). Fusedqkvand single-blocklinear1are split by rows; the finaladaLN_modulationholds (shift, scale) and diffusers reads (scale, shift), so its two row halves swap.load_original_layout_transformer: a strict loader for plain files of a class with nofrom_single_file(Krea 2). It casts likefrom_pretrained(_keep_in_fp32_modulesstay fp32), so the bf16 file builds the same tensors as the base repo.diffusion_families.py,diffusion.py*distilled*) getguidance_embeds+use_meanflowthroughtransformer_config_variants, the shift 4 schedule throughcomfy_flow_shift_variants, and the base repo's two CFG guiders are dropped for a guidance-distilled transformer (otherwise every step would run twice).Verification
Converted headers of the real Comfy-Org files, strict against the diffusers model (no missing, no unexpected, all shapes equal):
The distilled file against the base config leaves 8 keys unused, which is why it needs the config variant.
Bit identity, dense files vs the diffusers repos: krea2_turbo_bf16 converts to 430/430 tensors equal to
krea/Krea-2-Turbo(same dtype,torch.equal), hunyuanimage2.1_bf16 to 1264/1264 equal tohunyuanvideo-community/HunyuanImage-2.1-Diffusers.Renders, B200, 1024x1024, 4 prompts with fixed seeds. Base = this PR's merge base. LPIPS is against Studio's own bf16 render of the diffusers repo (eager, no quant). Peak is torch allocated.
For context, from the same harness and reference:
Compile (Speed default): 0 graph breaks on every cell. Krea 2: 0 recompiles. HunyuanImage: 1 recompile per load (a
hidden_statesstride guard), the same as Studio's own HunyuanImage loads on the diffusers repo, so not new here.Tests
tests/test_diffusion_single_file_krea2_hunyuanimage.py:strict=True(Krea 2, plus HunyuanImage reference and ComfyUI namings, base and distilled);load_comfy_quant_transformerwith the real converter, codes and scales exact;UNSLOTH_TEST_REAL_HF_HUB_CACHEpoints at a hub cache holding them.Related suites, base vs head, compared by failing test ID:
test_media_family_assembler_offline.py);test_diffusion_h3_trainer.pyx3,test_diffusion_native_quant.pyx1,test_diffusion_offline_source.pyx1). Head adds 24 passing tests.Not covered