diffusers icon indicating copy to clipboard operation
diffusers copied to clipboard

MiniMaxH3ImageTransformer2DModel does not inherit PeftAdapterMixin

Open NancyFyong opened this issue 2 weeks ago • 2 comments

Describe the bug

MiniMaxH3ImageTransformer2DModel does not inherit PeftAdapterMixin, so the standard PEFT/LoRA adapter API is unavailable on the MiniMax-H3 image transformer. The video transformer, MiniMaxH3Transformer3DModel, already inherits the mixin.

On current main (c215605) and v0.43.0:

This blocks the native add_adapter, load_lora_adapter, set_adapter(s), enable_adapters, disable_adapters, and delete_adapters workflow on H3-Image. I found this while integrating the model into verl-omni's FlowGRPO and DiffusionNFT training actors:

  • https://github.com/verl-project/verl-omni/blob/6481dab6/verl_omni/pipelines/minimax_h3_image_flow_grpo/diffusers_training_adapter.py#L35
  • https://github.com/verl-project/verl-omni/blob/6481dab6/verl_omni/pipelines/minimax_h3_image_diffusion_nft/diffusers_training_adapter.py#L55

Both currently need a local compatibility subclass:

from diffusers import MiniMaxH3ImageTransformer2DModel
from diffusers.loaders import PeftAdapterMixin


class H3ImageActor(MiniMaxH3ImageTransformer2DModel, PeftAdapterMixin):
    pass

A matching fix plus the standard model-level LoraTesterMixin coverage is ready in #15366. Comparing with the 3D integration also showed that PEFT support needs @apply_lora_scale("attention_kwargs"), the attention_kwargs forward argument, and pipeline plumbing; those are included in the PR as well.

Reproduction

from diffusers import MiniMaxH3ImageTransformer2DModel
from diffusers.loaders import PeftAdapterMixin
from peft import LoraConfig

print(issubclass(MiniMaxH3ImageTransformer2DModel, PeftAdapterMixin))
# False

model = MiniMaxH3ImageTransformer2DModel(
    num_attention_heads=2,
    attention_head_dim=16,
    hidden_size=24,
    num_layers=1,
    num_refiner_layers=1,
    ffn_dim=32,
    in_channels=4,
    patch_size=(1, 2, 2),
    text_dim=8,
    freq_dim=8,
    time_embed_hidden_dim=24,
    time_embed_dim=16,
    rope_freq_dim=2,
    num_pdd_heads=3,
)
model.add_adapter(LoraConfig(r=4, target_modules=["to_q"]))

Output:

False
AttributeError: 'MiniMaxH3ImageTransformer2DModel' object has no attribute 'add_adapter'

Context

This is needed for PEFT/LoRA training and adapter loading on MiniMax-H3-Image, including the verl-omni FlowGRPO and DiffusionNFT pipelines linked above. The proposed fix is to inherit PeftAdapterMixin the same way MiniMaxH3Transformer3DModel does; packed attention and PDD head selection are unaffected.

Logs

False
AttributeError: 'MiniMaxH3ImageTransformer2DModel' object has no attribute 'add_adapter'

System Info

- 🤗 Diffusers version: 0.44.0.dev0 (current main c215605); also affected: 0.43.0
- Platform: macOS-15.6-arm64-arm-64bit
- Running on Google Colab?: No
- Python version: 3.11.18
- PyTorch version (GPU?): 2.15.0 (False)
- Huggingface_hub version: 2.4.0
- Transformers version: 5.23.0
- Accelerate version: 1.16.0
- PEFT version: 0.22.0
- Safetensors version: 0.8.0
- xFormers version: not installed
- Accelerator: Apple M3 Pro
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: No

Who can help?

LoRA/PEFT-related model support: @sayakpaul

NancyFyong avatar Nov 21 '26 02:11 NancyFyong

Opened #15366 with the fix. It adds PeftAdapterMixin to MiniMaxH3ImageTransformer2DModel and the standard model-level LoraTesterMixin coverage; the H3-Image model test file now passes with 45 passed, 39 skipped, 1 xpassed on CPU.

NancyFyong avatar Nov 21 '26 02:11 NancyFyong

Updated #15366 after checking the MiniMaxH3Transformer3DModel integration more closely. The 3D support is not only the mixin: it also wires attention_kwargs and @apply_lora_scale through forward, and the modular pipeline forwards attention_kwargs into the denoiser. The PR now includes those pieces, plus explicit tests for LoRA scale semantics, a backward pass, and end-to-end pipeline scale routing. Pipeline-level load_lora_weights and checkpoint conversion remain separate work.

NancyFyong avatar Nov 21 '26 02:11 NancyFyong