Skip to content

fix: detect Ming-Image vs Z-Image by pad-token presence - #2441

Merged
leejet merged 1 commit into
leejet:masterfrom
kuhnchris:ming-zimage-detection
Nov 27, 2026
Merged

leejet merged 1 commit into
leejet:masterfrom
kuhnchris:ming-zimage-detection

Conversation

@kuhnchris

@kuhnchris kuhnchris commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Ming-Image was detected as Z-Image after implementation of DGL.
!!! AI-DISCLOSURE NOTE: This change was created with the help of Qwen3.8-Flash-Next and tested by me !!!

Ming-Image shares the Lumina2 tensor shape with Z-Image but lacks the Z-Image x_pad_token tensors. Reject the Z-Image match when x_pad_token is absent so those checkpoints resolve to VERSION_MING_IMAGE.

Related Issue / Discussion

Should fix #2438

Additional Information

I am not a specialist in detection of different tensors within models, so please double check if the fix is valid.

Checklist

Test (before)

sd-cli --prompt "test" -m ./diffusion_models/Ming-Image-0.2-Design-Q5_K_M.gguf --llm ./text_encoders/Ming-Image-0.2-Ling-Mini-2.0-Q4_K_M.gguf  --vae vae.safetensors  --tokenizer tokenizer.json 
ggml_cuda_init: found 1 CUDA devices (Total VRAM: 81182 MiB):
  Device 0: NVIDIA A100 80GB PCIe, compute capability 8.0, VMM: yes, VRAM: 81182 MiB
[I] Detected model family: Z-Image (Ming-Image-0.2-Design-Q5_K_M.gguf) --- generation.cpp:124
[I] flash attention auto: CUDA0 -> on (probe: normal 0.270 ms, flash 0.203 ms) --- flash_attn.cpp:98
[I] conv2d direct auto: CUDA0 -> off (no implicit GEMM path) --- conv_direct.cpp:90
[I] conv3d direct auto: CUDA0 -> on (implicit GEMM) --- conv_direct.cpp:87
[E] Diffusion model tensor 'model.diffusion_model.cap_pad_token' not in model metadata --- model_manager.cpp:1085
[E] invalid tensor part 'model.diffusion_model.context_refiner.0.attention.qkv.weight.1' for 'model.diffusion_model.context_refiner.0.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.context_refiner.1.attention.qkv.weight.1' for 'model.diffusion_model.context_refiner.1.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.0.attention.qkv.weight.1' for 'model.diffusion_model.layers.0.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.1.attention.qkv.weight.1' for 'model.diffusion_model.layers.1.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.10.attention.qkv.weight.1' for 'model.diffusion_model.layers.10.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.11.attention.qkv.weight.1' for 'model.diffusion_model.layers.11.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.12.attention.qkv.weight.1' for 'model.diffusion_model.layers.12.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.13.attention.qkv.weight.1' for 'model.diffusion_model.layers.13.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.14.attention.qkv.weight.1' for 'model.diffusion_model.layers.14.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.15.attention.qkv.weight.1' for 'model.diffusion_model.layers.15.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.16.attention.qkv.weight.1' for 'model.diffusion_model.layers.16.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.17.attention.qkv.weight.1' for 'model.diffusion_model.layers.17.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.18.attention.qkv.weight.1' for 'model.diffusion_model.layers.18.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.19.attention.qkv.weight.1' for 'model.diffusion_model.layers.19.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.2.attention.qkv.weight.1' for 'model.diffusion_model.layers.2.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.20.attention.qkv.weight.1' for 'model.diffusion_model.layers.20.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.21.attention.qkv.weight.1' for 'model.diffusion_model.layers.21.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.22.attention.qkv.weight.1' for 'model.diffusion_model.layers.22.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.23.attention.qkv.weight.1' for 'model.diffusion_model.layers.23.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.24.attention.qkv.weight.1' for 'model.diffusion_model.layers.24.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.25.attention.qkv.weight.1' for 'model.diffusion_model.layers.25.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.26.attention.qkv.weight.1' for 'model.diffusion_model.layers.26.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.27.attention.qkv.weight.1' for 'model.diffusion_model.layers.27.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.28.attention.qkv.weight.1' for 'model.diffusion_model.layers.28.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.29.attention.qkv.weight.1' for 'model.diffusion_model.layers.29.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.3.attention.qkv.weight.1' for 'model.diffusion_model.layers.3.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.4.attention.qkv.weight.1' for 'model.diffusion_model.layers.4.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.5.attention.qkv.weight.1' for 'model.diffusion_model.layers.5.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.6.attention.qkv.weight.1' for 'model.diffusion_model.layers.6.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.7.attention.qkv.weight.1' for 'model.diffusion_model.layers.7.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.8.attention.qkv.weight.1' for 'model.diffusion_model.layers.8.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.layers.9.attention.qkv.weight.1' for 'model.diffusion_model.layers.9.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.noise_refiner.0.attention.qkv.weight.1' for 'model.diffusion_model.noise_refiner.0.attention.qkv.weight' --- model_manager.cpp:1099
[E] invalid tensor part 'model.diffusion_model.noise_refiner.1.attention.qkv.weight.1' for 'model.diffusion_model.noise_refiner.1.attention.qkv.weight' --- model_manager.cpp:1099
[E] Diffusion model tensor 'model.diffusion_model.x_pad_token' not in model metadata --- model_manager.cpp:1085
[E] model metadata validation failed --- model_runtime.cpp:474
[E] generate failed: line 38, column 18: cannot load component from '.../ming/diffusion_models/Ming-Image-0.2-Design-Q5_K_M.gguf' --- main.cpp:815

Test (after)

../stable-diffusion.cpp/build/bin/sd-cli --prompt "test" -m ./diffusion_models/Ming-Image-0.2-Design-Q5_K_M.gguf --llm ./text_encoders/Ming-Image-0.2-Ling-Mini-2.0-Q4_K_M.gguf  --vae vae.safetensors  --tokenizer tokenizers/tokenizer.json 
ggml_cuda_init: found 1 CUDA devices (Total VRAM: 40470 MiB):
  Device 0: NVIDIA A100-PCIE-40GB, compute capability 8.0, VMM: yes, VRAM: 40470 MiB
[I] Detected model family: Ming-Image (Ming-Image-0.2-Design-Q5_K_M.gguf) --- generation.cpp:124
[I] flash attention auto: CUDA0 -> on (CUDA MMA) --- flash_attn.cpp:74
[I] conv2d direct auto: CUDA0 -> on (implicit GEMM) --- conv_direct.cpp:87
[I] conv3d direct auto: CUDA0 -> on (implicit GEMM) --- conv_direct.cpp:87
[I] Diffusion model weights: 5339.28 MiB --- model_runtime.cpp:483
[I] using external tokenizer (main): .../ming/tokenizers/tokenizer.json --- tokenizer_config.cpp:65
[I] Conditioner model weights: 10017.22 MiB --- model_runtime.cpp:483
[I] using VAE for encoding / decoding --- component_builders.cpp:187
[I] VAE weights: 242.11 MiB --- model_runtime.cpp:483
[I] loading 641/1037 tensors from .../ming/text_encoders/Ming-Image-0.2-Ling-Mini-2.0-Q4_K_M.gguf --- model_loader.cpp:1188
  |##################################################| 641/641 -   6.89GB/s
[I] loading tensors completed, taking 1.41s (read: 0.15s, memcpy: 0.00s, convert: 0.00s, copy_to_backend: 1.04s) --- model_loader.cpp:1458
[I] running in Ming-Image FLOW mode --- denoising_parameterization.cpp:92
[I] sampling started: method=euler, steps=20 --- sampling.cpp:60
[I] loading 519/519 tensors from .../ming/diffusion_models/Ming-Image-0.2-Design-Q5_K_M.gguf --- model_loader.cpp:1188
  |##################################################| 519/519 -   6.29GB/s
[I] loading tensors completed, taking 0.83s (read: 0.05s, memcpy: 0.00s, convert: 0.00s, copy_to_backend: 0.60s) --- model_loader.cpp:1458
  |==================================================| 20/20 -   1.98it/s
[I] sampling completed, taking 11.04s --- sampling.cpp:99
[I] loading 104/194 tensors from .../ming/vae.safetensors --- model_loader.cpp:1188
  |##################################################| 104/104 - 659.07MB/s
[I] loading tensors completed, taking 0.21s (read: 0.00s, memcpy: 0.00s, convert: 0.02s, copy_to_backend: 0.00s) --- model_loader.cpp:1458
[I] computing vae decode graph completed, taking 0.40s --- vae.hpp:372
[I] save result image 0 to 'output.png' (success) --- main.cpp:451
[I] 1/1 images saved --- main.cpp:527

Summary by CodeRabbit

  • Bug Fixes
    • Improved model identification for Ming-Image checkpoints, so they are no longer classified as Z-Image when the checkpoint lacks a specific marker. Z-Image checkpoints continue to be identified as before. This helps ensure each checkpoint is recognized under the correct model type.

Ming-Image shares the Lumina2 tensor shape with Z-Image but lacks the
Z-Image x_pad_token tensors. Reject the Z-Image match when x_pad_token is
absent so those checkpoints resolve to VERSION_MING_IMAGE.
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Model version detection now identifies checkpoints with cap_embedder.0.weight and no x_pad_token as Ming-Image. Checkpoints with x_pad_token continue to be identified as Z-Image.

Changes: Model version detection

Layer / File(s) Summary
Checkpoint version branch
src/model_loader.cpp
When x_pad_token is absent, the cap_embedder.0.weight detection branch returns VERSION_MING_IMAGE. Otherwise, it continues to return VERSION_Z_IMAGE.

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: leejet, wbruna

Merge Risk: Minimal · up to 72fa1

Ming-Image checkpoints that share the Lumina2 shape with Z-Image are now detected as Ming-Image instead of failing validation. No concrete merge-blocking defect was established. Whether the issue's Ming-Image 0.1 GGUF loads remains untested by the author.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive Directly linked issue #2438 reports that Ming-Image 0.1 Design GGUFs fail metadata validation. The reported errors are missing cap_pad_token and x_pad_token, and invalid tensor parts for attention.qkv… Provide a load and generation test with a Ming-Image 0.1 Design checkpoint (the file named in #2438) on the reviewed head. The test log must show no 'not in model metadata' or 'invalid tensor part' errors. Also make the reviewed diff readab…
Passed Passed checks: 3 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: Ming-Image and Z-Image are now told apart by whether the x_pad_token tensor is present. The raw summary confirms that get_sd_version returns VERSION_MING_IMAGE when x_…
Out of Scope Changes check Passed The change, as described in the raw summary, is a small (+5/-0) model-family detection change in src/model_loader.cpp. It rejects the Z-Image match when model.diffusion_model.x_pad_token is absent. Th…
Full details: Title check

Explanation

The title names the main change: Ming-Image and Z-Image are now told apart by whether the x_pad_token tensor is present. The raw summary confirms that get_sd_version returns VERSION_MING_IMAGE when x_pad_token is absent. The title is specific and fits the changeset, and it uses the 'fix:' prefix that matches the bug-fix intent in the objectives.

Full details: Out of Scope Changes check

Explanation

The change, as described in the raw summary, is a small (+5/-0) model-family detection change in src/model_loader.cpp. It rejects the Z-Image match when model.diffusion_model.x_pad_token is absent. This change directly targets the Ming-Image misdetection described in #2438 and the PR summary. No unrelated files or features are listed in the summary. The diff itself could not be read, so this verdict relies on the summary's description of the changed files.

Full details: Linked Issues check

Explanation

Directly linked issue #2438 reports that Ming-Image 0.1 Design GGUFs fail metadata validation. The reported errors are missing cap_pad_token and x_pad_token, and invalid tensor parts for attention.qkv.weight.1. The raw summary says the PR changes only get_sd_version in src/model_loader.cpp (+5/-0). It adds a VERSION_MING_IMAGE result when model.diffusion_model.x_pad_token is absent. This addresses the version-detection part of the issue. The PR does not change MingImageConfig::detect_from_weights, which the issue suspects sets split_qkv incorrectly. The PR does not show that the qkv tensor-part errors are resolved. The only after-test uses Ming-Image 0.2, not the Ming-Image 0.1 checkpoint named in #2438. The issue's failing 0.1 files were not tested. The diff could not be read because changed blobs are missing from the checkout, so the code change was assessed from the summary only.

Resolution

Provide a load and generation test with a Ming-Image 0.1 Design checkpoint (the file named in #2438) on the reviewed head. The test log must show no 'not in model metadata' or 'invalid tensor part' errors. Also make the reviewed diff readable so the get_sd_version change and any QKV handling can be checked against the issue's suspected cause.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2a0004ce-c13c-4d37-9f3a-b4285afebb7b
Commits

Reviewing files that changed from the base of the PR and between e637c7b and 72fa10f.

Files selected for processing: 1

  • src/model_loader.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@kuhnchris

Copy link
Copy Markdown
Contributor Author

My bad, of course I also tested Ming-Image-0.1.

~/models$ stable-diffusion.cpp/build/bin/sd-cli --prompt "test" -m ./Ming-0.1/Ming-Image-0.1-Design-Q8_0.gguf --llm ./Ming-0.1/Ming-Image-0.1-Ling-Mini-2.0-Q4_K_M.gguf  --vae ./Ming-0.1/ming_image_vae_bf16.safetensors --tokenizer Ming-0.1/tokenizer.json 
ggml_cuda_init: found 1 CUDA devices (Total VRAM: 40470 MiB):
  Device 0: NVIDIA A100-PCIE-40GB, compute capability 8.0, VMM: yes, VRAM: 40470 MiB
[I] Detected model family: Ming-Image (Ming-Image-0.1-Design-Q8_0.gguf) --- generation.cpp:124
[I] flash attention auto: CUDA0 -> on (CUDA MMA) --- flash_attn.cpp:74
[I] conv2d direct auto: CUDA0 -> on (implicit GEMM) --- conv_direct.cpp:87
[I] conv3d direct auto: CUDA0 -> on (implicit GEMM) --- conv_direct.cpp:87
[I] Diffusion model weights: 6996.90 MiB --- model_runtime.cpp:483
[I] using external tokenizer (main): .../models/Ming-0.1/tokenizer.json --- tokenizer_config.cpp:65
[I] Conditioner model weights: 9464.39 MiB --- model_runtime.cpp:483
[I] using VAE for encoding / decoding --- component_builders.cpp:187
[I] VAE weights: 242.11 MiB --- model_runtime.cpp:483
[I] loading 641/1037 tensors from .../models/Ming-0.1/Ming-Image-0.1-Ling-Mini-2.0-Q4_K_M.gguf --- model_loader.cpp:1188
  |##################################################| 641/641 -   7.58GB/s
[I] loading tensors completed, taking 1.21s (read: 0.10s, memcpy: 0.00s, convert: 0.00s, copy_to_backend: 0.88s) --- model_loader.cpp:1458
[I] running in Ming-Image FLOW mode --- denoising_parameterization.cpp:92
[I] sampling started: method=euler, steps=20 --- sampling.cpp:60
[I] loading 519/519 tensors from .../models/Ming-0.1/Ming-Image-0.1-Design-Q8_0.gguf --- model_loader.cpp:1188
  |##################################################| 519/519 -   8.32GB/s
[I] loading tensors completed, taking 0.82s (read: 0.05s, memcpy: 0.00s, convert: 0.00s, copy_to_backend: 0.68s) --- model_loader.cpp:1458
  |==================================================| 20/20 -   2.12it/s
[I] sampling completed, taking 10.36s --- sampling.cpp:99
[I] loading 104/194 tensors from .../models/Ming-0.1/ming_image_vae_bf16.safetensors --- model_loader.cpp:1188
  |##################################################| 104/104 - 668.76MB/s
[I] loading tensors completed, taking 0.20s (read: 0.00s, memcpy: 0.00s, convert: 0.01s, copy_to_backend: 0.00s) --- model_loader.cpp:1458
[I] computing vae decode graph completed, taking 0.40s --- vae.hpp:372
[I] save result image 0 to 'output.png' (success) --- main.cpp:451
[I] 1/1 images saved --- main.cpp:527

@leejet
leejet merged commit 908965d into leejet:master Nov 27, 2026
2 checks passed
@leejet

leejet commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Thank you for your contribution.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ming-Image 0.1 Design no longer loads since #2396: "invalid tensor part ...attention.qkv.weight.1" and missing pad tokens

2 participants