[bug]: LoHa on Conv2d layers with conv-shaped factors fails at generation time
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 78/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- python, pytorch
- Ambito
- backend, machine-learning
Direzione di ricerca
Il bug è in invokeai/backend/patches/layers/loha_layer.py in get_weight (riga 80) e get_parameters. Leggi LoRALayer.get_weight nello stesso modulo per vedere come appiattisce i fattori conv da dim 1 prima di moltiplicare. Esegui lo snippet di riproduzione dell'issue per provocare il RuntimeError, poi appiattisci ogni fattore da dim 1 e ridimensiona il prodotto in get_parameters. Fatto quando lo snippet gira senza disallineamento di dimensione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Is there an existing issue for this problem?
- I have searched the existing issues
Install method
Manual (dev checkout)
Operating system
Windows
GPU vendor
Not GPU-specific (reproduced on CPU)
GPU model
No response
GPU VRAM
No response
Version number
main at 0ddc9df91b
What happened
A LoHa layer on a Conv2d whose factors keep their conv shapes fails when it is patched. The LoRA installs and loads, then generation fails:
File "invokeai/backend/patches/layers/loha_layer.py", line 80, in get_weight
weight: torch.Tensor = (self.w1_a @ self.w1_b) * (self.w2_a @ self.w2_b)
RuntimeError: The size of tensor a (2) must match the size of tensor b (4) at non-singleton dimension 1
OneTrainer builds each LoHa factor pair from a down/up conv pair. It saves hada_w*_b as [rank, in, kh, kw] and hada_w*_a as [out, rank, 1, 1]. LoHALayer.get_weight multiplies the factors as stored, so a 4D pair turns into a batched matmul with mismatched batch dimensions. LyCORIS stores non-Tucker conv factors flattened to 2D, which works.
In practice this hits:
- SD1.x LoHa even with attention-only training, because
proj_in/proj_outare 1x1 convs. - SD2.x/SDXL LoHa that train the ResNet convs.
- The patch-embedding convs of ERNIE-Image and SD3 when all layers are trained.
What you expected to happen
get_weight flattens each factor from dim 1 before multiplying, as LoRALayer.get_weight already does for conv up/down, and get_parameters reshapes the product to the conv weight.
How to reproduce the problem
import torch
import invokeai.backend.model_manager.load # noqa: F401
from invokeai.backend.patches.layers.utils import any_lora_layer_from_state_dict
# Conv2d(4, 8, 3x3), rank 2, factors stored with their conv shapes:
# hada_w*_b is the "down" conv weight [rank, in, kh, kw], hada_w*_a the 1x1 "up" conv weight [out, rank, 1, 1].
layer = any_lora_layer_from_state_dict(
{
"hada_w1_a": torch.randn(8, 2, 1, 1), "hada_w1_b": torch.randn(2, 4, 3, 3),
"hada_w2_a": torch.randn(8, 2, 1, 1), "hada_w2_b": torch.randn(2, 4, 3, 3),
"alpha": torch.tensor(2.0),
}
)
layer.get_parameters({"weight": torch.zeros(8, 4, 3, 3)}, weight=1.0)
Additional context
Linear LoHa layers from the same files apply correctly.
Found while checking every LoRA layout OneTrainer writes (b08db37) against main: OneTrainer's own savers run on meta-device models of the real architectures, then identification, LoRALoader and LayerPatcher module resolution on the InvokeAI model.
Discord username
No response
- Lingua principale
- TypeScript
- Stelle
- 28.8k
- Fork
- 3.1k
- Merge medio
- 3g 2h
- PR unite (30g)
- 159
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di invoke-ai/InvokeAI
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 2 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 2 giorni
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
I maintainer di solito rispondono entro 2 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 2 giorni
-
[enhancement]: Bump PyPatchMatch to latestForse già presa @dunkeroni l’ha presa 10 giorni fa. Apertaenhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
invoke-ai/InvokeAI#9826 · 2 reazioni · 1 assegnatario ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di invoke-ai/InvokeAI
Issue simili
-
type: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
I maintainer di solito rispondono entro 1 giorno
-
0️⃣ phase/new
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 70/100
microsoft/playwright#43640 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100