From 5b321d2071faeacfb2c78b606a7794dab6627ab9 Mon Sep 17 00:00:00 2001 From: CalamitousFelicitousness Date: Mon, 25 May 2026 05:47:56 +0100 Subject: [PATCH] refactor(lora): update importers for native_adapter rename 5 pipeline files + 2 test files. Mechanical substitution. 141/141 adapter tests pass. --- modules/lora/lora_load.py | 2 +- pipelines/anima/anima_lora.py | 74 ++++++++++++++-------------- pipelines/chroma/chroma_lora.py | 48 +++++++++--------- pipelines/ernie/ernie_lora.py | 46 +++++++++--------- pipelines/flux/flux2_lora.py | 78 +++++++++++++++--------------- pipelines/z_image/zimage_lora.py | 48 +++++++++--------- test/test-anima-native-adapters.py | 4 +- test/test-flux2-native-adapters.py | 2 +- 8 files changed, 151 insertions(+), 151 deletions(-) diff --git a/modules/lora/lora_load.py b/modules/lora/lora_load.py index a454eff91..d87654c95 100644 --- a/modules/lora/lora_load.py +++ b/modules/lora/lora_load.py @@ -19,7 +19,7 @@ exclude_errors = [ # shared.sd_model_type -> dotted module path of a pipeline native loader # exposing ``try_load(name, network_on_disk, lora_scale)``. New archs add an -# entry here and ship a per-arch ``try_load`` (either binding native_loader's +# entry here and ship a per-arch ``try_load`` (either binding native_adapter's # generic helpers via try_load_chain, or rolling their own). _NATIVE_DISPATCH = { 'zimage': 'pipelines.z_image.zimage_lora', diff --git a/pipelines/anima/anima_lora.py b/pipelines/anima/anima_lora.py index 39530c243..cc9c01dbf 100644 --- a/pipelines/anima/anima_lora.py +++ b/pipelines/anima/anima_lora.py @@ -25,23 +25,23 @@ already stamped on the network_layer_mapping. Adapter and TE paths bypass the rename and are flattened verbatim. Network-key construction (transformer vs llm_adapter vs te) is parameterized -in :mod:`modules.lora.native_loader` via the ``network_prefix`` kwarg; this +in :mod:`modules.lora.native_adapter` via the ``network_prefix`` kwarg; this module supplies :func:`network_prefix_for` to pick per ``prefix_used``. Family-specific dispatch (LoRA, LoHA, LoKR, OFT, IA3, GLoRA, Norm, Full) is -inherited from native_loader's generics; alpha / scale / DoRA flow through +inherited from native_adapter's generics; alpha / scale / DoRA flow through the standard ``NetworkWeights.w`` slots rather than being baked into the factor weights at load time. """ from collections import OrderedDict -from modules.lora import native_loader +from modules.lora import native_adapter # === Arch-specific prefix configuration === # # Order matters: longer / more-specific prefixes must precede shorter ones, -# because :func:`native_loader.parse_key` returns the first match. Both +# because :func:`native_adapter.parse_key` returns the first match. Both # ``diffusion_model.llm_adapter.`` and ``text_encoders.qwen3_06b.transformer.model.`` # start with ``diffusion_model.`` / ``text_encoders.`` so they must be listed first. @@ -58,37 +58,37 @@ ANIMA_PREFIXES = ( # Tests address these through the anima_lora module surface; sibling pipelines # do the same (see flux2_lora / zimage_lora / ernie_lora). -LORA_SUFFIXES = native_loader.LORA_SUFFIXES -LOKR_SUFFIXES = native_loader.LOKR_SUFFIXES -LOHA_SUFFIXES = native_loader.LOHA_SUFFIXES -OFT_SUFFIXES = native_loader.OFT_SUFFIXES -IA3_SUFFIXES = native_loader.IA3_SUFFIXES -GLORA_SUFFIXES = native_loader.GLORA_SUFFIXES -NORM_SUFFIXES = native_loader.NORM_SUFFIXES -FULL_SUFFIXES = native_loader.FULL_SUFFIXES +LORA_SUFFIXES = native_adapter.LORA_SUFFIXES +LOKR_SUFFIXES = native_adapter.LOKR_SUFFIXES +LOHA_SUFFIXES = native_adapter.LOHA_SUFFIXES +OFT_SUFFIXES = native_adapter.OFT_SUFFIXES +IA3_SUFFIXES = native_adapter.IA3_SUFFIXES +GLORA_SUFFIXES = native_adapter.GLORA_SUFFIXES +NORM_SUFFIXES = native_adapter.NORM_SUFFIXES +FULL_SUFFIXES = native_adapter.FULL_SUFFIXES -LORA_MARKERS = native_loader.LORA_MARKERS -LOKR_MARKERS = native_loader.LOKR_MARKERS -LOHA_MARKERS = native_loader.LOHA_MARKERS -OFT_MARKERS = native_loader.OFT_MARKERS -IA3_MARKERS = native_loader.IA3_MARKERS -GLORA_MARKERS = native_loader.GLORA_MARKERS -NORM_MARKERS = native_loader.NORM_MARKERS -FULL_MARKERS = native_loader.FULL_MARKERS +LORA_MARKERS = native_adapter.LORA_MARKERS +LOKR_MARKERS = native_adapter.LOKR_MARKERS +LOHA_MARKERS = native_adapter.LOHA_MARKERS +OFT_MARKERS = native_adapter.OFT_MARKERS +IA3_MARKERS = native_adapter.IA3_MARKERS +GLORA_MARKERS = native_adapter.GLORA_MARKERS +NORM_MARKERS = native_adapter.NORM_MARKERS +FULL_MARKERS = native_adapter.FULL_MARKERS -SUFFIX_NORMALIZE = native_loader.SUFFIX_NORMALIZE -BARE_DIFFUSERS_PREFIX_USED = native_loader.BARE_DIFFUSERS_PREFIX_USED -has_marker = native_loader.has_marker +SUFFIX_NORMALIZE = native_adapter.SUFFIX_NORMALIZE +BARE_DIFFUSERS_PREFIX_USED = native_adapter.BARE_DIFFUSERS_PREFIX_USED +has_marker = native_adapter.has_marker def parse_key(key, suffixes): - """Anima-bound :func:`native_loader.parse_key`.""" - return native_loader.parse_key(key, suffixes, prefixes=ANIMA_PREFIXES) + """Anima-bound :func:`native_adapter.parse_key`.""" + return native_adapter.parse_key(key, suffixes, prefixes=ANIMA_PREFIXES) def group_by_suffixes(state_dict, suffixes): - """Anima-bound :func:`native_loader.group_by_suffixes`.""" - return native_loader.group_by_suffixes(state_dict, suffixes, prefixes=ANIMA_PREFIXES) + """Anima-bound :func:`native_adapter.group_by_suffixes`.""" + return native_adapter.group_by_suffixes(state_dict, suffixes, prefixes=ANIMA_PREFIXES) # === Cosmos 2.0 path rename (transformer only) === @@ -174,7 +174,7 @@ def network_prefix_for(prefix_used): return "lora_transformer_" -# === Native loaders (thin wrappers over native_loader generics) === +# === Native loaders (thin wrappers over native_adapter generics) === _BIND_KWARGS = dict( resolve_targets=resolve_targets, @@ -185,40 +185,40 @@ _BIND_KWARGS = dict( def try_load_lora(name, network_on_disk, lora_scale): - return native_loader.try_load_lora(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_lora(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load_lokr(name, network_on_disk, lora_scale): - return native_loader.try_load_lokr(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_lokr(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load_loha(name, network_on_disk, lora_scale): - return native_loader.try_load_loha(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_loha(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load_oft(name, network_on_disk, lora_scale): - return native_loader.try_load_oft(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_oft(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load_ia3(name, network_on_disk, lora_scale): - return native_loader.try_load_ia3(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_ia3(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load_glora(name, network_on_disk, lora_scale): - return native_loader.try_load_glora(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_glora(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load_norm(name, network_on_disk, lora_scale): - return native_loader.try_load_norm(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_norm(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load_full(name, network_on_disk, lora_scale): - return native_loader.try_load_full(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_full(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load(name, network_on_disk, lora_scale): """Run every Anima family loader, merge any that match.""" - return native_loader.try_load_chain( + return native_adapter.try_load_chain( name, network_on_disk, lora_scale, family_loaders=( try_load_lora, try_load_lokr, try_load_loha, try_load_oft, diff --git a/pipelines/chroma/chroma_lora.py b/pipelines/chroma/chroma_lora.py index 8354a98b5..965d5bf52 100644 --- a/pipelines/chroma/chroma_lora.py +++ b/pipelines/chroma/chroma_lora.py @@ -30,13 +30,13 @@ any ``_mod_lin`` / ``_modulation_lin`` keys land in ``unmapped``. LoRAs targeting the approximator pass through unchanged. """ -from modules.lora import native_loader -from modules.lora.native_loader import ChunkSpec +from modules.lora import native_adapter +from modules.lora.native_adapter import ChunkSpec # === Arch-specific prefix configuration === -KNOWN_PREFIXES = native_loader.KNOWN_PREFIXES_DEFAULT +KNOWN_PREFIXES = native_adapter.KNOWN_PREFIXES_DEFAULT BARE_FLUX_PREFIXES = ("double_blocks.", "single_blocks.") @@ -57,24 +57,24 @@ LINEAR1_DIMS = [3072, 3072, 3072, 12288] # === Re-exports for test/back-compat === -LORA_SUFFIXES = native_loader.LORA_SUFFIXES -LOKR_SUFFIXES = native_loader.LOKR_SUFFIXES -LOHA_SUFFIXES = native_loader.LOHA_SUFFIXES -OFT_SUFFIXES = native_loader.OFT_SUFFIXES +LORA_SUFFIXES = native_adapter.LORA_SUFFIXES +LOKR_SUFFIXES = native_adapter.LOKR_SUFFIXES +LOHA_SUFFIXES = native_adapter.LOHA_SUFFIXES +OFT_SUFFIXES = native_adapter.OFT_SUFFIXES -LORA_MARKERS = native_loader.LORA_MARKERS -LOKR_MARKERS = native_loader.LOKR_MARKERS -LOHA_MARKERS = native_loader.LOHA_MARKERS -OFT_MARKERS = native_loader.OFT_MARKERS +LORA_MARKERS = native_adapter.LORA_MARKERS +LOKR_MARKERS = native_adapter.LOKR_MARKERS +LOHA_MARKERS = native_adapter.LOHA_MARKERS +OFT_MARKERS = native_adapter.OFT_MARKERS -SUFFIX_NORMALIZE = native_loader.SUFFIX_NORMALIZE -BARE_DIFFUSERS_PREFIX_USED = native_loader.BARE_DIFFUSERS_PREFIX_USED -has_marker = native_loader.has_marker +SUFFIX_NORMALIZE = native_adapter.SUFFIX_NORMALIZE +BARE_DIFFUSERS_PREFIX_USED = native_adapter.BARE_DIFFUSERS_PREFIX_USED +has_marker = native_adapter.has_marker def parse_key(key, suffixes): - """Chroma-bound :func:`native_loader.parse_key`.""" - return native_loader.parse_key( + """Chroma-bound :func:`native_adapter.parse_key`.""" + return native_adapter.parse_key( key, suffixes, prefixes=KNOWN_PREFIXES, bare_prefixes=BARE_FLUX_PREFIXES, @@ -83,8 +83,8 @@ def parse_key(key, suffixes): def group_by_suffixes(state_dict, suffixes): - """Chroma-bound :func:`native_loader.group_by_suffixes`.""" - return native_loader.group_by_suffixes( + """Chroma-bound :func:`native_adapter.group_by_suffixes`.""" + return native_adapter.group_by_suffixes( state_dict, suffixes, prefixes=KNOWN_PREFIXES, bare_prefixes=BARE_FLUX_PREFIXES, @@ -202,7 +202,7 @@ def _split_single_linear1(block_idx): return targets -# === Native loaders (thin wrappers over native_loader generics) === +# === Native loaders (thin wrappers over native_adapter generics) === _BIND_KWARGS = dict( @@ -215,24 +215,24 @@ _BIND_KWARGS = dict( def try_load_lora(name, network_on_disk, lora_scale): - return native_loader.try_load_lora(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_lora(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load_lokr(name, network_on_disk, lora_scale): - return native_loader.try_load_lokr(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_lokr(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load_loha(name, network_on_disk, lora_scale): - return native_loader.try_load_loha(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_loha(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load_oft(name, network_on_disk, lora_scale): - return native_loader.try_load_oft(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_oft(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load(name, network_on_disk, lora_scale): """Run every Chroma family loader, merge any that match.""" - return native_loader.try_load_chain( + return native_adapter.try_load_chain( name, network_on_disk, lora_scale, family_loaders=(try_load_lora, try_load_lokr, try_load_loha, try_load_oft), ) diff --git a/pipelines/ernie/ernie_lora.py b/pipelines/ernie/ernie_lora.py index c7ad8d497..e76d716aa 100644 --- a/pipelines/ernie/ernie_lora.py +++ b/pipelines/ernie/ernie_lora.py @@ -16,12 +16,12 @@ modules (no fused QKV) and ``ErnieImageFeedForward`` exposes ``gate_proj``, straight passthrough; no chunking, no renames, no dispatch table. """ -from modules.lora import native_loader +from modules.lora import native_adapter # === Arch-specific prefix configuration === -KNOWN_PREFIXES = native_loader.KNOWN_PREFIXES_DEFAULT +KNOWN_PREFIXES = native_adapter.KNOWN_PREFIXES_DEFAULT BARE_DIFFUSERS_PREFIXES = ( "layers.", "adaLN_modulation.", "final_norm.", "final_linear.", @@ -30,24 +30,24 @@ BARE_DIFFUSERS_PREFIXES = ( # === Re-exports for test/back-compat === -LORA_SUFFIXES = native_loader.LORA_SUFFIXES -LOKR_SUFFIXES = native_loader.LOKR_SUFFIXES -LOHA_SUFFIXES = native_loader.LOHA_SUFFIXES -OFT_SUFFIXES = native_loader.OFT_SUFFIXES +LORA_SUFFIXES = native_adapter.LORA_SUFFIXES +LOKR_SUFFIXES = native_adapter.LOKR_SUFFIXES +LOHA_SUFFIXES = native_adapter.LOHA_SUFFIXES +OFT_SUFFIXES = native_adapter.OFT_SUFFIXES -LORA_MARKERS = native_loader.LORA_MARKERS -LOKR_MARKERS = native_loader.LOKR_MARKERS -LOHA_MARKERS = native_loader.LOHA_MARKERS -OFT_MARKERS = native_loader.OFT_MARKERS +LORA_MARKERS = native_adapter.LORA_MARKERS +LOKR_MARKERS = native_adapter.LOKR_MARKERS +LOHA_MARKERS = native_adapter.LOHA_MARKERS +OFT_MARKERS = native_adapter.OFT_MARKERS -SUFFIX_NORMALIZE = native_loader.SUFFIX_NORMALIZE -BARE_DIFFUSERS_PREFIX_USED = native_loader.BARE_DIFFUSERS_PREFIX_USED -has_marker = native_loader.has_marker +SUFFIX_NORMALIZE = native_adapter.SUFFIX_NORMALIZE +BARE_DIFFUSERS_PREFIX_USED = native_adapter.BARE_DIFFUSERS_PREFIX_USED +has_marker = native_adapter.has_marker def parse_key(key, suffixes): - """ERNIE-bound :func:`native_loader.parse_key`.""" - return native_loader.parse_key( + """ERNIE-bound :func:`native_adapter.parse_key`.""" + return native_adapter.parse_key( key, suffixes, prefixes=KNOWN_PREFIXES, bare_diffusers_prefixes=BARE_DIFFUSERS_PREFIXES, @@ -55,8 +55,8 @@ def parse_key(key, suffixes): def group_by_suffixes(state_dict, suffixes): - """ERNIE-bound :func:`native_loader.group_by_suffixes`.""" - return native_loader.group_by_suffixes( + """ERNIE-bound :func:`native_adapter.group_by_suffixes`.""" + return native_adapter.group_by_suffixes( state_dict, suffixes, prefixes=KNOWN_PREFIXES, bare_diffusers_prefixes=BARE_DIFFUSERS_PREFIXES, @@ -75,7 +75,7 @@ def resolve_targets(prefix_used, base): return [] -# === Native loaders (thin wrappers over native_loader generics) === +# === Native loaders (thin wrappers over native_adapter generics) === _BIND_KWARGS = dict( @@ -87,24 +87,24 @@ _BIND_KWARGS = dict( def try_load_lora(name, network_on_disk, lora_scale): - return native_loader.try_load_lora(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_lora(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load_lokr(name, network_on_disk, lora_scale): - return native_loader.try_load_lokr(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_lokr(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load_loha(name, network_on_disk, lora_scale): - return native_loader.try_load_loha(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_loha(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load_oft(name, network_on_disk, lora_scale): - return native_loader.try_load_oft(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_oft(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load(name, network_on_disk, lora_scale): """Run every ERNIE family loader, merge any that match.""" - return native_loader.try_load_chain( + return native_adapter.try_load_chain( name, network_on_disk, lora_scale, family_loaders=(try_load_lora, try_load_lokr, try_load_loha, try_load_oft), ) diff --git a/pipelines/flux/flux2_lora.py b/pipelines/flux/flux2_lora.py index 81994cf82..1c69a66b4 100644 --- a/pipelines/flux/flux2_lora.py +++ b/pipelines/flux/flux2_lora.py @@ -16,12 +16,12 @@ produced by ``Flux2Transformer2DModel.save_lora_adapter()``). Diffusers-PEFT BFL/kohya keys are mapped to diffusers paths via ``F2_SINGLE_MAP`` / ``F2_DOUBLE_MAP`` / ``F2_QKV_MAP``. Fused QKV in double_blocks emits three -Q/K/V targets each carrying a :class:`modules.lora.native_loader.ChunkSpec` +Q/K/V targets each carrying a :class:`modules.lora.native_adapter.ChunkSpec` that the generic loaders use to chunk the up-weight or instantiate the appropriate ``NetworkModule*Chunk`` variant. Per-family fused-QKV handling is inherited from -:mod:`modules.lora.native_loader`; see the loader-by-loader notes there. +:mod:`modules.lora.native_adapter`; see the loader-by-loader notes there. LyCORIS algorithm coverage relative to upstream ``KohakuBlueleaf/LyCORIS/lycoris/modules/``: @@ -49,13 +49,13 @@ to inject the ``diffusion_model.`` prefix for bare-BFL keys and bake kohya import os from modules.logger import log -from modules.lora import native_loader -from modules.lora.native_loader import ChunkSpec +from modules.lora import native_adapter +from modules.lora.native_adapter import ChunkSpec # === Arch-specific prefix configuration === -KNOWN_PREFIXES = native_loader.KNOWN_PREFIXES_DEFAULT + ("lycoris_",) +KNOWN_PREFIXES = native_adapter.KNOWN_PREFIXES_DEFAULT + ("lycoris_",) BARE_FLUX_PREFIXES = ( "single_blocks.", "double_blocks.", "img_in.", "txt_in.", @@ -108,34 +108,34 @@ KOHYA_SUFFIX_MAP = { # === Re-exports for backward compatibility === # The offline test suite addresses these via the flux2_lora module surface. -# Re-export rather than asking tests to import native_loader directly. +# Re-export rather than asking tests to import native_adapter directly. -LORA_SUFFIXES = native_loader.LORA_SUFFIXES -LOKR_SUFFIXES = native_loader.LOKR_SUFFIXES -LOHA_SUFFIXES = native_loader.LOHA_SUFFIXES -OFT_SUFFIXES = native_loader.OFT_SUFFIXES -IA3_SUFFIXES = native_loader.IA3_SUFFIXES -GLORA_SUFFIXES = native_loader.GLORA_SUFFIXES -NORM_SUFFIXES = native_loader.NORM_SUFFIXES -FULL_SUFFIXES = native_loader.FULL_SUFFIXES +LORA_SUFFIXES = native_adapter.LORA_SUFFIXES +LOKR_SUFFIXES = native_adapter.LOKR_SUFFIXES +LOHA_SUFFIXES = native_adapter.LOHA_SUFFIXES +OFT_SUFFIXES = native_adapter.OFT_SUFFIXES +IA3_SUFFIXES = native_adapter.IA3_SUFFIXES +GLORA_SUFFIXES = native_adapter.GLORA_SUFFIXES +NORM_SUFFIXES = native_adapter.NORM_SUFFIXES +FULL_SUFFIXES = native_adapter.FULL_SUFFIXES -LORA_MARKERS = native_loader.LORA_MARKERS -LOKR_MARKERS = native_loader.LOKR_MARKERS -LOHA_MARKERS = native_loader.LOHA_MARKERS -OFT_MARKERS = native_loader.OFT_MARKERS -IA3_MARKERS = native_loader.IA3_MARKERS -GLORA_MARKERS = native_loader.GLORA_MARKERS -NORM_MARKERS = native_loader.NORM_MARKERS -FULL_MARKERS = native_loader.FULL_MARKERS +LORA_MARKERS = native_adapter.LORA_MARKERS +LOKR_MARKERS = native_adapter.LOKR_MARKERS +LOHA_MARKERS = native_adapter.LOHA_MARKERS +OFT_MARKERS = native_adapter.OFT_MARKERS +IA3_MARKERS = native_adapter.IA3_MARKERS +GLORA_MARKERS = native_adapter.GLORA_MARKERS +NORM_MARKERS = native_adapter.NORM_MARKERS +FULL_MARKERS = native_adapter.FULL_MARKERS -SUFFIX_NORMALIZE = native_loader.SUFFIX_NORMALIZE -BARE_DIFFUSERS_PREFIX_USED = native_loader.BARE_DIFFUSERS_PREFIX_USED -has_marker = native_loader.has_marker +SUFFIX_NORMALIZE = native_adapter.SUFFIX_NORMALIZE +BARE_DIFFUSERS_PREFIX_USED = native_adapter.BARE_DIFFUSERS_PREFIX_USED +has_marker = native_adapter.has_marker def parse_key(key, suffixes): - """Flux2-bound :func:`native_loader.parse_key`. Returns ``(prefix_used, base, suffix)`` or ``None``.""" - return native_loader.parse_key( + """Flux2-bound :func:`native_adapter.parse_key`. Returns ``(prefix_used, base, suffix)`` or ``None``.""" + return native_adapter.parse_key( key, suffixes, prefixes=KNOWN_PREFIXES, bare_prefixes=BARE_FLUX_PREFIXES, @@ -144,8 +144,8 @@ def parse_key(key, suffixes): def group_by_suffixes(state_dict, suffixes): - """Flux2-bound :func:`native_loader.group_by_suffixes`.""" - return native_loader.group_by_suffixes( + """Flux2-bound :func:`native_adapter.group_by_suffixes`.""" + return native_adapter.group_by_suffixes( state_dict, suffixes, prefixes=KNOWN_PREFIXES, bare_prefixes=BARE_FLUX_PREFIXES, @@ -231,7 +231,7 @@ def _bfl_to_diffusers_targets(base): return targets -# === Native loaders (thin wrappers over native_loader generics) === +# === Native loaders (thin wrappers over native_adapter generics) === _BIND_KWARGS = dict( @@ -244,40 +244,40 @@ _BIND_KWARGS = dict( def try_load_lora(name, network_on_disk, lora_scale): - return native_loader.try_load_lora(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_lora(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load_lokr(name, network_on_disk, lora_scale): - return native_loader.try_load_lokr(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_lokr(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load_loha(name, network_on_disk, lora_scale): - return native_loader.try_load_loha(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_loha(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load_oft(name, network_on_disk, lora_scale): - return native_loader.try_load_oft(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_oft(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load_ia3(name, network_on_disk, lora_scale): - return native_loader.try_load_ia3(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_ia3(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load_glora(name, network_on_disk, lora_scale): - return native_loader.try_load_glora(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_glora(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load_norm(name, network_on_disk, lora_scale): - return native_loader.try_load_norm(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_norm(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load_full(name, network_on_disk, lora_scale): - return native_loader.try_load_full(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_full(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load(name, network_on_disk, lora_scale): """Single dispatcher entry point: run every family loader, merge any that match.""" - return native_loader.try_load_chain( + return native_adapter.try_load_chain( name, network_on_disk, lora_scale, family_loaders=( try_load_lora, try_load_lokr, try_load_loha, try_load_oft, diff --git a/pipelines/z_image/zimage_lora.py b/pipelines/z_image/zimage_lora.py index 49c35f9d8..f3d39e536 100644 --- a/pipelines/z_image/zimage_lora.py +++ b/pipelines/z_image/zimage_lora.py @@ -22,37 +22,37 @@ OFT block structure is tied to the target module's ``out_features`` so a Q/K/V split is not a drop-in. """ -from modules.lora import native_loader -from modules.lora.native_loader import ChunkSpec +from modules.lora import native_adapter +from modules.lora.native_adapter import ChunkSpec # === Arch-specific prefix configuration === -KNOWN_PREFIXES = native_loader.KNOWN_PREFIXES_DEFAULT +KNOWN_PREFIXES = native_adapter.KNOWN_PREFIXES_DEFAULT BARE_DIFFUSERS_PREFIXES = ("layers.", "noise_refiner.", "context_refiner.") # === Re-exports for test/back-compat === -LORA_SUFFIXES = native_loader.LORA_SUFFIXES -LOKR_SUFFIXES = native_loader.LOKR_SUFFIXES -LOHA_SUFFIXES = native_loader.LOHA_SUFFIXES -OFT_SUFFIXES = native_loader.OFT_SUFFIXES +LORA_SUFFIXES = native_adapter.LORA_SUFFIXES +LOKR_SUFFIXES = native_adapter.LOKR_SUFFIXES +LOHA_SUFFIXES = native_adapter.LOHA_SUFFIXES +OFT_SUFFIXES = native_adapter.OFT_SUFFIXES -LORA_MARKERS = native_loader.LORA_MARKERS -LOKR_MARKERS = native_loader.LOKR_MARKERS -LOHA_MARKERS = native_loader.LOHA_MARKERS -OFT_MARKERS = native_loader.OFT_MARKERS +LORA_MARKERS = native_adapter.LORA_MARKERS +LOKR_MARKERS = native_adapter.LOKR_MARKERS +LOHA_MARKERS = native_adapter.LOHA_MARKERS +OFT_MARKERS = native_adapter.OFT_MARKERS -SUFFIX_NORMALIZE = native_loader.SUFFIX_NORMALIZE -BARE_DIFFUSERS_PREFIX_USED = native_loader.BARE_DIFFUSERS_PREFIX_USED -has_marker = native_loader.has_marker +SUFFIX_NORMALIZE = native_adapter.SUFFIX_NORMALIZE +BARE_DIFFUSERS_PREFIX_USED = native_adapter.BARE_DIFFUSERS_PREFIX_USED +has_marker = native_adapter.has_marker def parse_key(key, suffixes): - """Z-Image-bound :func:`native_loader.parse_key`.""" - return native_loader.parse_key( + """Z-Image-bound :func:`native_adapter.parse_key`.""" + return native_adapter.parse_key( key, suffixes, prefixes=KNOWN_PREFIXES, bare_diffusers_prefixes=BARE_DIFFUSERS_PREFIXES, @@ -60,8 +60,8 @@ def parse_key(key, suffixes): def group_by_suffixes(state_dict, suffixes): - """Z-Image-bound :func:`native_loader.group_by_suffixes`.""" - return native_loader.group_by_suffixes( + """Z-Image-bound :func:`native_adapter.group_by_suffixes`.""" + return native_adapter.group_by_suffixes( state_dict, suffixes, prefixes=KNOWN_PREFIXES, bare_diffusers_prefixes=BARE_DIFFUSERS_PREFIXES, @@ -127,7 +127,7 @@ def _underscore_to_diffusers_targets(base): return [(base, None)] -# === Native loaders (thin wrappers over native_loader generics) === +# === Native loaders (thin wrappers over native_adapter generics) === _BIND_KWARGS = dict( @@ -139,24 +139,24 @@ _BIND_KWARGS = dict( def try_load_lora(name, network_on_disk, lora_scale): - return native_loader.try_load_lora(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_lora(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load_lokr(name, network_on_disk, lora_scale): - return native_loader.try_load_lokr(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_lokr(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load_loha(name, network_on_disk, lora_scale): - return native_loader.try_load_loha(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_loha(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load_oft(name, network_on_disk, lora_scale): - return native_loader.try_load_oft(name, network_on_disk, lora_scale, **_BIND_KWARGS) + return native_adapter.try_load_oft(name, network_on_disk, lora_scale, **_BIND_KWARGS) def try_load(name, network_on_disk, lora_scale): """Run every Z-Image family loader, merge any that match.""" - return native_loader.try_load_chain( + return native_adapter.try_load_chain( name, network_on_disk, lora_scale, family_loaders=(try_load_lora, try_load_lokr, try_load_loha, try_load_oft), ) diff --git a/test/test-anima-native-adapters.py b/test/test-anima-native-adapters.py index ad77366a1..f017512e4 100644 --- a/test/test-anima-native-adapters.py +++ b/test/test-anima-native-adapters.py @@ -5,10 +5,10 @@ Offline unit tests for Anima native adapter loaders. Anima is the only native arch with a multi-component network namespace: keys route into ``lora_transformer_*`` (Cosmos 2.0 DiT), ``lora_llm_adapter_*`` (a custom Qwen3-projection MLP), or ``lora_te_*`` (Qwen3 text encoder). Routing -is parameterized in ``modules.lora.native_loader`` via the ``network_prefix`` +is parameterized in ``modules.lora.native_adapter`` via the ``network_prefix`` callable that ``pipelines.anima.anima_lora`` supplies. -Covers the eight families exposed through native_loader's generics (LoRA, +Covers the eight families exposed through native_adapter's generics (LoRA, LoKR, LoHA, OFT, IA3, GLoRA, Norm, Full), focused on: - LoRA across all five recognized prefixes (BFL transformer / BFL llm_adapter / diff --git a/test/test-flux2-native-adapters.py b/test/test-flux2-native-adapters.py index 9400033a8..f7bd043b0 100644 --- a/test/test-flux2-native-adapters.py +++ b/test/test-flux2-native-adapters.py @@ -580,7 +580,7 @@ def test_parse_key_all_prefixes(): def test_resolve_targets_qkv_chunking(): - from modules.lora.native_loader import ChunkSpec + from modules.lora.native_adapter import ChunkSpec # Kohya double_blocks fused QKV → three chunks targeting Q/K/V. targets = F.resolve_targets('lora_unet_', 'double_blocks_0_img_attn_qkv') assert targets == [