set_ip_adapter_scale(float) raises "Cannot assign 1 scale_configs to 2 IP-Adapter" when several IP-Adapters are loaded

Aperta Adatta ai principianti
#15,210 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, pytorch

Direzione di ricerca

Leggi set_ip_adapter_scale in IPAdapterMixin e ModularIPAdapterMixin, insieme a FluxIPAdapterMixin.set_ip_adapter_scale, per conoscere il comportamento di diffusione esistente. L’issue identifica l’ordine del controllo della lunghezza e fornisce una piccola riproduzione con una pipeline; aggiungi test per il passaggio di un float con due adapter di test caricati e conferma che la scala venga applicata a entrambi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug

With more than one IP-Adapter loaded, set_ip_adapter_scale(0.6) raises ValueError: Cannot assign 1 scale_configs to 2 IP-Adapter. instead of applying the scale to every adapter. A list with one value per adapter works.

set_ip_adapter_scale already has a branch meant to repeat a single config for every adapter (elif len(scale_configs) == 1: scale_configs = scale_configs * len(attn_processor.scale)), but it comes after the length check, so it never runs. A single float was broadcast before #7668, and the Flux version (FluxIPAdapterMixin.set_ip_adapter_scale) still broadcasts it. The same code is in ModularIPAdapterMixin.set_ip_adapter_scale.

I'd like to send a PR that checks the single-config case first (a two-line swap in both mixins) plus a test.

Reproduction

Shown with the tiny test pipeline and two test IP-Adapters so it runs in seconds; it goes through the same set_ip_adapter_scale code as load_ip_adapter("h94/IP-Adapter", ...) with two weight_names on SD1.5.

# Run from the root of a diffusers checkout (uses the test helpers for a tiny pipeline and IP-Adapter weights).
from tests.models.unets.test_models_unet_2d_condition import create_ip_adapter_state_dict
from tests.pipelines.stable_diffusion.test_stable_diffusion import StableDiffusionPipelineTesterConfig

cfg = StableDiffusionPipelineTesterConfig()
pipe = cfg.pipeline_class(**cfg.get_dummy_components())
state_dicts = [create_ip_adapter_state_dict(pipe.unet) for _ in range(2)]
pipe.load_ip_adapter(state_dicts, subfolder=["", ""], weight_name=["", ""], image_encoder_folder=None)

pipe.set_ip_adapter_scale([0.6, 0.6])  # works
pipe.set_ip_adapter_scale(0.6)  # ValueError
Context

I found this while testing set_ip_adapter_scale with two IP-Adapters loaded.

Logs
ValueError: Cannot assign 1 scale_configs to 2 IP-Adapter.
System Info
- 🤗 Diffusers version: 0.42.0.dev0 (main @ 84532a058)
- Platform: macOS-26.6.2-arm64-arm-64bit
- Running on Google Colab?: No
- Python version: 3.12.11
- PyTorch version (GPU?): 2.15.0 (False)
- Huggingface_hub version: 2.4.0
- Transformers version: 5.22.2
- Accelerate version: 1.15.0
- PEFT version: 0.21.2
- Safetensors version: 0.8.0
- xFormers version: not installed
- Accelerator: Apple M5 Pro
- Using GPU in script?: No
- Using distributed or parallel set-up in script?: No
Who can help?

@asomoza @yiyixuxu

Lingua principale
Python
Stelle
34.9k
Fork
7.5k
Merge medio
2g 16h
PR unite (30g)
57

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di huggingface/diffusers

Tutte le issue di huggingface/diffusers

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.