Commit Graph

293 Commits

Author SHA1 Message Date
Disty0 297ab4bb60 SDNQ Lora fix dtype 2026-05-16 13:13:41 +03:00
Disty0 8e11971572 Fix SDNQ Lora 2026-05-15 21:25:08 +03:00
Vladimir Mandic c8d6fd5cf8 Revert "much stricter ruff linting"
This reverts commit 310dbf1574.
2026-05-11 08:13:57 +02:00
Vladimir Mandic 310dbf1574 much stricter ruff linting
Co-authored-by: Copilot <copilot@github.com>
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2026-05-11 07:15:37 +02:00
CalamitousFelicitousness 0c44b93b25 refactor(flux2): expose single try_load entry point for dispatcher
Move the family-iteration loop into pipelines/flux/flux2_lora.try_load
so the f2 branch in lora_load.load_safetensors becomes a one-line call.

Per-family try_load_* entry points stay public for direct testing.

Addresses review feedback on PR #4841.
2026-05-10 16:33:18 +01:00
CalamitousFelicitousness 69506551a7 feat(lora): surface method-selection reason in load logs
get_method now returns (method, reason). The reason distinguishes
user opt-in (lora_force_diffusers), class-forced, hash-forced, and
arch-unsupported routes from the default native path; surfaced in
the info-level "Network load: type=LoRA load=<method>(<reason>)"
line so users can tell why a given load took a particular path.
2026-05-10 00:05:37 +01:00
CalamitousFelicitousness dda7bb7bbc feat(flux2): native BOFT (butterfly-OFT) support
Discriminated from OFT by 4-D oft_blocks shape (boft_m, block_num,
block_size, block_size), mirroring LyCORIS algo_check. The cascade
of log_2(block_num)+1 Cayley rotations is applied via the
unflatten/transpose/flatten reshape sequence in NetworkModuleBOFT,
porting LyCORIS make_weight verbatim.
2026-05-10 00:05:37 +01:00
CalamitousFelicitousness 4d3699bab6 refactor(flux2): align dispatcher with z-image/chroma native pattern
Adds 'f2' to allow_native and dispatches all eight native loaders
through load_safetensors. lora_force_diffusers continues to route
through lora_diffusers.load_diffusers as the explicit PEFT escape
hatch.
2026-05-09 23:16:09 +01:00
CalamitousFelicitousness 7983c8ec72 feat(lora): add NetworkModuleHadaChunk for fused-weight LoHA targets
Slices w1a/w2a at the assigned chunk's row range and computes the
partial Hadamard product, mirroring NetworkModuleLokrChunk. Used
when LoHA targets a fused weight (e.g. img_attn.qkv) on models
that expose split Q/K/V modules.
2026-05-09 23:16:09 +01:00
CalamitousFelicitousness 1750a2881e fix(lora): use is-not-none check for ex_bias accumulation
Truthiness on a tensor raises when stacking multiple Norm/Full
adapters. Match the updown accumulation pattern five lines above.
2026-05-09 22:04:42 +01:00
CalamitousFelicitousness db4a345a1b fix(lora): set GLora dim so alpha scaling is applied
Without self.dim, NetworkModule.calc_scale returns 1.0 even when
alpha is present, silently dropping the trained scaling. Use
w1b.shape[0] as the rank, matching the network_lora and
network_hada conventions.
2026-05-09 22:04:42 +01:00
CalamitousFelicitousness 4aca63e841 fix(lora): guard OFT constraint for LyCORIS oft_diag files
LyCORIS files have self.constraint=None (only the kohya path
uses it). Wrap the .to() call to avoid the NoneType AttributeError.
2026-05-09 22:04:17 +01:00
Vladimir Mandic 4747ca2fc0 lora change detection improvements
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2026-05-09 09:38:54 +02:00
CalamitousFelicitousness 92df94a227 feat(chroma): native loader for chroma lora
Add a per-model native LoRA path for Chroma that handles both PEFT-style
(diffusion_model.<dotted>.lora_A.weight, no alpha) and kohya-flat
(lora_unet_<flat> with .alpha) layouts, plus LoKR/LoHA/OFT/DoRA.

Resolves issue #4169 (ostris ai-toolkit Chroma LoRAs failed to load).

- new pipelines/chroma/chroma_lora.py with try_load_lora/lokr/loha/oft
- fused-QKV expansion: 3-way equal for img/txt qkv, 4-way unequal
  [3072, 3072, 3072, 12288] for single linear1 (Q+K+V+proj_mlp)
- NetworkModuleLokrSliceChunk for unequal-row LoKR slicing
- path rewrite from Flux-source to ChromaTransformer2DModel naming
- lora_load.py: dispatch chroma to the native loader and narrow the
  kohya-Flux convert gate to f1 only
2026-05-04 21:17:14 +01:00
CalamitousFelicitousness b37e275212 feat(lora): native loader for ernie-image
Adds pipelines/ernie/ernie_lora.py with try_load_lora/lokr/loha/oft
entry points modeled on the z-image native loader, wires it into
lora_load.load_safetensors, and adds 'ernieimage' to allow_native.

ERNIE attention is not fused (separate to_q/to_k/to_v/to_out.0), so
the loader skips the qkv-split machinery the z-image loader needs and
supports all four families uniformly. Recognized prefixes are
diffusion_model., transformer., and lora_unet_; PEFT lora_A/lora_B
keys are normalized to lora_down/lora_up. Verified against PEFT, LoKR,
and Kohya/AIT files in the wild with zero unmapped or shape-mismatched
modules.
2026-05-04 16:43:36 +01:00
CalamitousFelicitousness 450bf977e8 fix(lora): use native_active flag instead of applied_layers for restore trigger
applied_layers is cleared and re-populated on every network_activate call.
With lora_apply_te=True the second activate (TE-only pass) finds all
modules already at the target state and skips them all, leaving
applied_layers empty and breaking the restore trigger on the next gen.

native_active is set from loaded_networks at the end of activate, so it
survives idempotent re-runs and only flips false after the restore call
clears loaded_networks.
2026-05-01 01:38:56 +01:00
Vladimir Mandic ebc875d224 reorg control type
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2026-04-29 11:20:22 +02:00
CalamitousFelicitousness a028b56687 fix(lora): restore native weights when LoRA removed on diffusers-path models
Flux2/Klein loads LoRAs as native modules through the diffusers method
path. network_activate() was only called when new native modules existed,
so removing a LoRA from the prompt left backed-up weights unrestored.

Check applied_layers to detect previously active native modules and
trigger network_activate() for the restore path.
2026-04-29 02:00:33 +01:00
CalamitousFelicitousness 4af3a57741 feat(anima): native lora across transformer, llm_adapter, text encoder
Dispatch anima loras through a dedicated native loader covering kohya,
bfl/ai-toolkit, and hybrid (bfl with alpha plus qwen3 text encoder)
formats. Cosmos 2.0 path rename is mirrored from diffusers in flat
(underscore) form so rewritten paths match network_layer_mapping keys
without further conversion.

Split model_type from cosmos to anima so a future base-cosmos2 lora
path stays separable. Update flow_models, taesd supported list, and the
taesd wanvideo bucket so samplers and preview decoding keep working
after the split.

Extend assign_network_names_to_compvis_modules to walk pipe.llm_adapter
under the lora_llm_adapter_ prefix, and add llm_adapter to
default_components so activate and deactivate include it for anima
models while staying inert elsewhere via the existing getattr guards.
2026-04-25 03:16:03 +01:00
awsr 09f5fc6e03 Update concurrent.futures imports
Python 3.14 adds `concurrent.interpreters` and we don't need to import that here.
2026-04-23 16:49:31 -07:00
vladmandic ab7fd5b5e6 cleanup
Signed-off-by: vladmandic <mandic00@live.com>
2026-04-21 19:45:51 +02:00
vladmandic db670b8bca fix sdnq-lora
Signed-off-by: vladmandic <mandic00@live.com>
2026-04-21 19:44:18 +02:00
Vladimir Mandic f1304b3ba0 Merge pull request #4762 from awsr/hashcache
Update hash cache
2026-04-15 09:42:35 +02:00
CalamitousFelicitousness 65e59e7224 feat(lora): z-image native lokr, loha and oft loaders
Add three adapter families to the z-image native loader and chain them
with the existing lora path through load_safetensors. Mixed-family
files (for example gta6_amateur_photography_zimagebase_v2.safetensors,
which carries lora and lokr groups in the same file) now load
completely instead of having one family silently dropped.

Shared helpers in pipelines/z_image/zimage_lora.py parse keys by
suffix list, rename legacy attention.out and attention.wo to
attention.to_out.0, and split fused attention.qkv into to_q/k/v. For
lora the split chunks the up weight along dim 0. For lokr the split
emits three NetworkModuleLokrChunk entries that share the tensors and
slice the kronecker product at apply time.

Fused attention.qkv for loha and oft is skipped with a warning. No
NetworkModuleHadaChunk exists, oft rotations are tied to out_features
and cannot be cleanly split across q/k/v, and no real z-image adapter
in that layout exists today.

load_safetensors for zimage chains try_load_lora, try_load_lokr,
try_load_loha and try_load_oft and merges their module dicts into a
single Network so mixed files load every module.
2026-04-14 21:48:19 +01:00
CalamitousFelicitousness c35adc4d0d feat(lora): native z-image lora loader
Add zimage to allow_native so lora_force_diffusers picks between
native and diffusers. Before this, zimage always took the diffusers
path regardless of the setting.

pipelines/z_image/zimage_lora.py reads the safetensors and writes
directly into network_layer_mapping, so Z-Image LoRAs no longer go
through the diffusers PEFT converter that raised KeyError on
state dicts with partial alpha keys.

Key formats handled: ai-toolkit, kohya lora_unet_, bare transformer.
and no-prefix. Pre-refactor fused attention.qkv is split into
to_q/k/v; attention.out and attention.wo are renamed to
attention.to_out.0. Alpha and dora_scale are preserved.
2026-04-14 21:13:23 +01:00
awsr 6aff795985 Improve extensibility 2026-04-14 02:59:19 -07:00
vladmandic 456d17fcd3 cleanup bnb references
Signed-off-by: vladmandic <mandic00@live.com>
2026-04-12 19:06:08 +02:00
vladmandic 91bba59c0d fix lint
Signed-off-by: vladmandic <mandic00@live.com>
2026-04-12 19:06:08 +02:00
CalamitousFelicitousness f1d2888f10 fix(lora): case-insensitive stage detection for two-stage LoRA names 2026-04-09 09:11:51 +01:00
CalamitousFelicitousness 18568db41c Add native LoRA loading for Flux2/Klein models
Load Flux2/Klein LoRAs as native NetworkModuleLora objects, bypassing
diffusers PEFT. Handles kohya (lora_unet_), AI toolkit (diffusion_model.),
diffusers PEFT (transformer.), and bare BFL key formats with automatic
QKV splitting for double block fused attention weights.

Includes shape validation to reject architecture-mismatched LoRAs early.
Respects lora_force_diffusers setting to fall back to PEFT when needed.
2026-03-25 04:24:49 +00:00
awsr ff247d8fd2 Merge branch 'dev' into RUF013 2026-03-24 07:12:51 -07:00
awsr 92960de8d6 RUF013 updates 2026-03-24 04:27:30 -07:00
vladmandic 57990fd8c0 add FireRed-Image-Edit-1.1
Signed-off-by: vladmandic <mandic00@live.com>
2026-03-23 06:41:46 +01:00
CalamitousFelicitousness 091f31d4bf add Flux2/Klein LoRA support
- detect f2 model type for LoRAs via metadata, architecture, and filename/folder
- preprocess bare BFL-format keys with diffusion_model prefix for Flux2LoraLoaderMixin
- handle LoKR format via native NetworkModuleLokr with on-the-fly kron(w1, w2)
- add NetworkModuleLokrChunk for fused QKV split into separate Q/K/V modules
- activate native modules loaded via diffusers path
- improve error message for Flux1/Flux2 architecture mismatch
2026-03-23 02:14:07 +00:00
vladmandic afe3786f5f add unet/dir to networks
Signed-off-by: vladmandic <mandic00@live.com>
2026-03-22 11:09:45 +01:00
Vladimir Mandic f86b0e69ef Merge pull request #4691 from awsr/errorlimiter-update
Update Errorlimiter to be thread-safe
2026-03-20 10:02:28 +01:00
vladmandic f83e9e7943 deregister rembg submodule
Signed-off-by: vladmandic <mandic00@live.com>
2026-03-20 08:14:01 +01:00
awsr d34896028d Make elimit kwarg optional 2026-03-19 04:41:37 -07:00
awsr 6e3c187b3f Rework to only use contextmanager system 2026-03-19 04:28:11 -07:00
vladmandic 121c51289b patch lora
Signed-off-by: vladmandic <mandic00@live.com>
2026-03-13 12:02:27 +01:00
Vladimir Mandic 47543663f9 cleanup references to p.sd_model
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2026-02-19 20:48:42 +01:00
Vladimir Mandic f78f0eb4a5 refactor imports 2026-02-19 15:28:24 +01:00
Vladimir Mandic 216558185b update installer usage 2026-02-19 12:21:46 +01:00
Vladimir Mandic d65a2d1ebc ruff lint 2026-02-19 11:13:44 +01:00
Vladimir Mandic e5c494f999 cleanup logger 2026-02-19 11:09:13 +01:00
Vladimir Mandic a3074baf8b unified logger 2026-02-19 09:46:42 +01:00
Vladimir Mandic bfe014f5da modernize typing 2026-02-19 09:15:37 +01:00
Vladimir Mandic a0f9447d04 add --remote cmd opt
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2026-02-07 10:17:32 +00:00
Vladimir Mandic e8ff09a2d2 fix lora unload and improve preview error handler
Signed-off-by: Vladimir Mandic <mandic00@live.com>
2026-02-07 09:07:34 +00:00
vladmandic 947dd7b2b3 support lora inside prompt selector
Signed-off-by: vladmandic <mandic00@live.com>
2026-01-25 09:49:36 +01:00