Skip to content

Add Kandinsky ImageSR 2.0 - #15451

Open
sweetdream779 wants to merge 1 commit into
huggingface:mainfrom
sweetdream779:add-kandinsky-imagesr
Open

sweetdream779 wants to merge 1 commit into
huggingface:mainfrom
sweetdream779:add-kandinsky-imagesr

Conversation

@sweetdream779

Copy link
Copy Markdown

What does this PR do?

Coordination: #15450 (opened just before this PR, waiting for maintainer feedback)

Adds Kandinsky ImageSR 2.0, an image
super-resolution model from Kandinsky Lab. A single text-free Kandinsky 5 transformer enhances an image at its
original resolution (×1) or upscales it ×2 or ×4 in one flow step, with calibrated creativity levels 0–8.

New public API:

  • KandinskyImageSRTransformer3DModel
  • KandinskyImageSRPipeline and KandinskyImageSRPipelineOutput
  • single-file loading of the released GGUF Q8_0 transformer through the existing GGUFQuantizationConfig

Checkpoints:

import torch
from diffusers import KandinskyImageSRPipeline
from diffusers.utils import load_image

pipe = KandinskyImageSRPipeline.from_pretrained(
    "kandinskylab/Kandinsky-ImageSR-2.0-Diffusers", dtype=torch.bfloat16
).to("cuda")
image = pipe(load_image("input.png"), upscale_factor=4, creativity=4).images[0]

Design notes

Things that differ from other pipelines:

  • Baked transformer. The model is conditioned on empty text only. The time embedding, the per-block
    modulation and the zero-text cross-attention contribution are stored as tables with one row per supported
    timestep (26 values in baked_timesteps). There are no text encoders, text blocks or cross-attention layers.
    Only the baked timesteps are valid. The pipeline validates one_step_t; the model selects its table row with
    an argmin instead of raising, so forward stays free of host syncs and compiles with fullgraph=True.
  • One flow step through the scheduler. The pipeline uses FlowMatchEulerDiscreteScheduler(shift=1.0) with
    sigmas=[t], which gives exactly x_0 = x_t - t * v. set_timesteps is called once per tile.
  • Deterministic pipeline. There is no noise and no generator argument. PipelineTesterMixin always passes
    a generator to its two batch tests, so the pipeline test file overrides them with generator-free versions.

Open questions:

  • Should the creativity presets stay a module-level constant in the pipeline, or move into a config?
  • Should GGUF quantization tests (GGUFTesterMixin) be added here or in a follow-up PR?

Tests

CPU (macOS):

DIFFUSERS_TEST_DEVICE=cpu python -m pytest tests/models/transformers/test_models_transformer_kandinsky_imagesr.py tests/pipelines/kandinsky_imagesr -q
# 52 passed, 50 skipped, 7 warnings

GPU (H100 80GB, torch 2.13.0+cu129):

python -m pytest tests/models/transformers/test_models_transformer_kandinsky_imagesr.py tests/pipelines/kandinsky_imagesr -q
# 1 failed, 91 passed, 10 skipped
# FAILED ...TestKandinskyImageSRTransformerTorchCompile::test_compile_works_with_aot

test_compile_works_with_aot needs the CUDA toolkit headers to compile AOTInductor's C++ wrapper, and the test
machine only has the CUDA runtime (fatal error: crt/host_defines.h: No such file or directory). The same test
fails the same way for Flux there.

make quality, utils/check_copies.py, utils/check_dummies.py, utils/check_forward_call_docstrings.py and
utils/check_return_annotations.py pass.

Self-review notes: see the comment below.

Before submitting

Who can review?

Pipelines and models: yiyixuxu sayakpaul

@sweetdream779

Copy link
Copy Markdown
Author

Self-review notes

Commit Add Kandinsky ImageSR 2.0 against upstream/main, reviewed with .ai/skills/self-review and
.ai/references/review-rules.md (plus code_style.md, models.md, pipelines.md, testing.md, pitfalls.md).
I read the whole diff, including the docs and tests, and compared it with the Kandinsky 6 VSR integration.

Blocking issues

None.

Non-blocking issues (left for review)

  1. visual_modulation_table loads in the requested dtype, not float32. transformer_kandinsky_imagesr.py:304.
    _keep_in_fp32_modules matches whole dotted name segments, so "modulation" keeps only out_layer.modulation
    in float32. This is intended: the released checkpoint stores this table in BF16 (it was baked in BF16), while
    time_embed_table and xattn_bias_table are F32 and stay F32.
  2. test_compile_works_with_aot could not pass on my GPU machine. AOTInductor compiles C++ against the CUDA
    toolkit headers, and the host has only the CUDA runtime (fatal error: crt/host_defines.h: No such file or directory). The same test fails the same way for Flux on that machine. Every other compile and offload tester
    passes on H100.

Dead code

None found. I traced __call__ into forward and every block. Every config argument is used, and every
forward/__call__ parameter is passed or documented. All classes and helpers (_tile_positions,
_boundary_aware_window, ROPE_MAX_POSITIONS, DEFAULT_CREATIVITY) are reached. set_timesteps is called once per
tile on purpose, because the scheduler's step index advances after every step.

Checks run

  • Shared files contain only additions. git diff --numstat upstream/main...HEAD shows 0 deletions in all 16
    files, including _toctree.yml, the __init__.py files, single_file_model.py and dummy_pt_objects.py.
  • Released config matches the model. All 10 __init__ arguments appear in
    kandinskylab/Kandinsky-ImageSR-2.0-Diffusers/transformer/config.json, with no extra keys. The model built on the
    meta device from that config has 707/707 state-dict keys with matching shapes against the safetensors header.
  • GGUF doc example. from_single_file(config=..., subfolder="transformer", GGUFQuantizationConfig(bf16)) loads
    the released Kandinsky-ImageSR-2.0-x1-Q8_0.gguf, the table dtypes match the checkpoint, and
    KandinskyImageSRPipeline.from_pretrained(..., transformer=transformer) loads the VAE and scheduler with
    tile_size == 1024. On H100 the GGUF pipeline upscales a 360×360 image ×4 at 48.1 dB PSNR against BF16.
  • Behaviour. A tiny model compiles with torch.compile(fullgraph=True) and matches eager output
    (max diff 3.6e-7). With the released scheduler config, set_timesteps(sigmas=[t]) followed by step gives
    lq - t * v for t = 0.005, 0.244 and 0.38. All 27 creativity presets are rows in baked_timesteps.
  • make quality: All checks passed! / 2284 files already formatted; doc-builder style, check_doc_toc.py and
    check_ai.py pass.
  • python utils/check_copies.py, python utils/check_dummies.py: no output, exit 0.
  • python utils/check_forward_call_docstrings.py: All forward/__call__ arguments are documented.
  • python utils/check_return_annotations.py: All forward/__call__ methods have return type annotations.
  • CPU (macOS): DIFFUSERS_TEST_DEVICE=cpu python -m pytest tests/models/transformers/test_models_transformer_kandinsky_imagesr.py tests/pipelines/kandinsky_imagesr -q
    → 52 passed, 50 skipped, 7 warnings. The skips need an accelerator, or cover features this pipeline does not
    have (callback_on_step_end, num_images_per_prompt, guidance_scale, encode_prompt, _optional_components)
    and QKV fusion.
  • GPU (H100 80GB, torch 2.13.0+cu129): python -m pytest tests/models/transformers/test_models_transformer_kandinsky_imagesr.py tests/pipelines/kandinsky_imagesr -q
    → 1 failed, 91 passed, 10 skipped. The failure is test_compile_works_with_aot (non-blocking 2). The skips are
    the features listed above and one multi-GPU test.

Verdict

READY. There are no blocking issues or dead code, the released config and checkpoint match the model, and both
documented loading paths work.

@github-actions github-actions Bot added documentation Improvements or additions to documentation models tests utils pipelines single-file size/L PR with diff > 200 LOC labels Dec 1, 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

documentation Improvements or additions to documentation models pipelines single-file size/L PR with diff > 200 LOC tests utils

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant