[bug]: Anima kohya LoRAs: layers outside the DiT blocks are not applied

Cerrado Apto para principiantes
#10,028 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Ya se ha fusionado un pull request relacionado.

  • #10059 de @guishiw — fusionado

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
85/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python, pytorch

Línea de trabajo

Comienza en invokeai/backend/patches/lora_conversions/anima_lora_conversion_utils.py en _convert_kohya_unet_key (línea 80). Lee la función y el script repro proporcionado para ver qué claves permanecen aplanadas. Añade mapeo para final_layer_linear, final_layer_adaln_modulation_1, t_embedder_1_linear_1, x_embedder_proj_1 a sus formas punteadas. Ejecuta el snippet para confirmar que la lista de capas coincide con los nombres punteados esperados.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug
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

In an Anima kohya LoRA, the layers outside the DiT blocks are never applied. _convert_kohya_unet_key (invokeai/backend/patches/lora_conversions/anima_lora_conversion_utils.py:80) only un-flattens blocks_N_… (and the llm_adapter_ prefix). Every other key keeps its flattened name: final_layer_linear, final_layer_adaln_modulation_1/2, t_embedder_1_linear_1/2, x_embedder_proj_1. The resulting dotted patch never resolves them, and each one logs "Failed to find module for LoRA layer key".

The LoRA still loads and works, just without those layers. That makes it weaker than trained, and the only signal is the per-layer warnings.

What you expected to happen

Non-block kohya keys map to final_layer.linear, final_layer.adaln_modulation.1, t_embedder.1.linear_1, x_embedder.proj.1 and so on, as the block keys do. A kohya parsing tree like the Krea-2 one (kohya_key_utils) would cover them.

How to reproduce the problem
import torch

import invokeai.backend.model_manager.load  # noqa: F401
from invokeai.backend.patches.lora_conversions.anima_lora_conversion_utils import lora_model_from_anima_state_dict


def lora(prefix: str) -> dict:
    return {f"{prefix}.lora_down.weight": torch.randn(4, 64), f"{prefix}.lora_up.weight": torch.randn(64, 4)}


sd = {}
for k in ("blocks_0_self_attn_q_proj", "final_layer_linear", "final_layer_adaln_modulation_1", "t_embedder_1_linear_1", "x_embedder_proj_1"):
    sd |= lora(f"lora_unet_{k}")
print(list(lora_model_from_anima_state_dict(sd, alpha=None).layers))

Output on main:

['lora_transformer-blocks.0.self_attn.q_proj', 'lora_transformer-final_layer_linear', 'lora_transformer-final_layer_adaln_modulation_1', 'lora_transformer-t_embedder_1_linear_1', 'lora_transformer-x_embedder_proj_1']
Additional context

In a LoRA trained on every layer these are 6 of 454 layers (about 1 % of the trained weights).

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

Lenguaje dominante
TypeScript
Estrellas
28.9k
Forks
3.1k
Merge medio
4 d 2 h
PR fusionados (30 d)
220

Preparar el entorno

  • Sin Dockerfile ni archivo de Docker Compose
  • Tiene una plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de invoke-ai/InvokeAI

Todos los issues de invoke-ai/InvokeAI

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.