Anima 2.9B/3.8B insert blocks between the original 28, so old LoRA keys land on the wrong layers and ComfyUI emits no missing-key warning. Add a model-family adapter that rewrites block indices in memory before the generic LoRA loader runs. - 28->40, 40->52 and composed 28->52 mappings, with anchored kohya/generic key patterns - Anima detection from image_model/llm_adapter and block count from blocks/num_blocks - skip text encoder, llm_adapter and semantic connector keys; collision and newer-LoRA errors - ComfyUI setting (default on) synced to the LM settings API; no base-model-specific node toggle - docs, unit and loader integration tests Reuses the manifest data from PR #1104; supersedes its node-level toggle design.
36 lines
943 B
Python
36 lines
943 B
Python
"""Model-family adapters that prepare LoRA state dicts before ComfyUI loads them.
|
|
|
|
The generic LoRA loader only calls :func:`prepare_lora`; model-specific
|
|
knowledge (block layouts, compatibility rules) lives in the adapter modules so
|
|
the loader UI stays generic.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Mapping
|
|
from typing import Any
|
|
|
|
from . import anima
|
|
from .errors import LoraCompatibilityError
|
|
|
|
_ADAPTERS = (anima,)
|
|
|
|
|
|
def prepare_lora(
|
|
lora_sd: Mapping[str, Any],
|
|
model: Any,
|
|
name: str | None = None,
|
|
) -> tuple[dict[str, Any], str | None]:
|
|
"""Run the matching model-family adapter for ``model``.
|
|
|
|
Returns the state dict to load and an optional human-readable report.
|
|
"""
|
|
|
|
for adapter in _ADAPTERS:
|
|
if adapter.matches(model):
|
|
return adapter.prepare(lora_sd, model, name=name)
|
|
return dict(lora_sd), None
|
|
|
|
|
|
__all__ = ["LoraCompatibilityError", "prepare_lora"]
|