Skip to content

LoKr alpha scaling is ignored when both lokr_w1 and lokr_w2 are stored directly #15114

Description

@supermzc123

Custom Node Testing

Expected Behavior

A LyCORIS LoKr containing direct lokr_w1 and lokr_w2 tensors should apply the scaling defined by its alpha/rank convention.

For example, the affected checkpoint has:

ss_network_module: lycoris.kohya
ss_network_args: {"algo": "lokr", "factor": 8}
ss_network_dim: 32
ss_network_alpha: 1
per-layer alpha: 1

It works correctly in the training environment, but should also produce comparable results in ComfyUI at model strength 1.0.

Actual Behavior

Loading the LoKr at strength 1.0 causes the model output to collapse into an almost uniform-color image. Using approximately 0.03 strength avoids the collapse.
All 316 LoKr modules are mapped successfully, their shapes match the base model, and the checkpoint contains no NaN or Inf values.

Image

Steps to Reproduce

My workflow:

Anima_base.json

  1. Load the attached workflow in the latest ComfyUI.
  2. Select any LyCORIS LoKr that:
    • stores both lokr_w1 and lokr_w2 directly;
    • contains a per-layer alpha;
    • was trained with alpha < dim, for example alpha=1 and dim=32.
  3. Set strength_model to 1.0 in the built-in
    LoraLoaderModelOnly node.
  4. Run the workflow.

The model output becomes an almost uniform-color image or otherwise
shows an excessively strong LoKr effect.

  1. Change only strength_model to approximately alpha / dim.
    For an alpha=1, dim=32 checkpoint, use approximately 0.03.
  2. Run the workflow again with the same prompt, settings and seed.

The output no longer collapses.

  1. Bypass the LoKr loader and run the workflow again.

The base model also generates normally

Checkpoint used for reproduction

Its relevant metadata is:

{
  "ss_network_module": "lycoris.kohya",
  "ss_network_dim": "32",
  "ss_network_alpha": "1",
  "ss_network_args": "{\"algo\": \"lokr\", \"factor\": 8}"
}

Each affected layer stores:

<layer>.alpha
<layer>.lokr_w1
<layer>.lokr_w2

Example:

alpha: 1
lokr_w1 shape: [8, 8]
lokr_w2 shape: [256, 128]
target weight shape: [2048, 1024]

Debug Logs

H:\comfy\ComfyUI>H:\comfy\ComfyUI\venv\Scripts\python.exe -s main.py --disable-all-custom-nodes --enable-cors-header --highvram --fast --enable-manager --enable-triton-backend --use-sage-attention --disable-xformers
�[32m[INFO]�[0m setup plugin alembic.autogenerate.schemas
�[32m[INFO]�[0m setup plugin alembic.autogenerate.tables
�[32m[INFO]�[0m setup plugin alembic.autogenerate.types
�[32m[INFO]�[0m setup plugin alembic.autogenerate.constraints
�[32m[INFO]�[0m setup plugin alembic.autogenerate.defaults
�[32m[INFO]�[0m setup plugin alembic.autogenerate.comments
[INFO] Adding extra search path checkpoints H:\comfy\ComfyUI\models\checkpoints
[INFO] Adding extra search path text_encoders H:\comfy\ComfyUI\models\text_encoders
[INFO] Adding extra search path text_encoders H:\comfy\ComfyUI\models\clip\  # legacy location still supported
[INFO] Adding extra search path clip_vision H:\comfy\ComfyUI\models\clip_vision
[INFO] Adding extra search path configs H:\comfy\ComfyUI\models\configs
[INFO] Adding extra search path controlnet H:\comfy\ComfyUI\models\controlnet
[INFO] Adding extra search path diffusion_models H:\comfy\ComfyUI\models\diffusion_models
[INFO] Adding extra search path diffusion_models H:\comfy\ComfyUI\models\unet
[INFO] Adding extra search path embeddings H:\comfy\ComfyUI\models\embeddings
[INFO] Adding extra search path loras H:\comfy\ComfyUI\models\loras
[INFO] Adding extra search path upscale_models H:\comfy\ComfyUI\models\upscale_models
[INFO] Adding extra search path vae H:\comfy\ComfyUI\models\vae
[INFO] Adding extra search path audio_encoders H:\comfy\ComfyUI\models\audio_encoders
[INFO] Adding extra search path model_patches H:\comfy\ComfyUI\models\model_patches
[INFO] Adding extra search path checkpoints D:\sd-webui-aki-directml-v4.4\models\Stable-diffusion
[INFO] Adding extra search path configs D:\sd-webui-aki-directml-v4.4\models\Stable-diffusion
[INFO] Adding extra search path vae D:\sd-webui-aki-directml-v4.4\models\VAE
[INFO] Adding extra search path loras D:\sd-webui-aki-directml-v4.4\models\Lora
[INFO] Adding extra search path loras D:\sd-webui-aki-directml-v4.4\  models\LyCORIS
[INFO] Adding extra search path upscale_models D:\sd-webui-aki-directml-v4.4\models\ESRGAN
[INFO] Adding extra search path upscale_models D:\sd-webui-aki-directml-v4.4\models\RealESRGAN
[INFO] Adding extra search path upscale_models D:\sd-webui-aki-directml-v4.4\models\SwinIR
[INFO] Adding extra search path embeddings D:\sd-webui-aki-directml-v4.4\embeddings
[INFO] Adding extra search path hypernetworks D:\sd-webui-aki-directml-v4.4\models\hypernetworks
[INFO] Adding extra search path controlnet D:\sd-webui-aki-directml-v4.4\models\ControlNet
[START] Security scan
WARNING: Ignoring invalid distribution ~ (H:\comfy\ComfyUI\venv\Lib\site-packages)
WARNING: Ignoring invalid distribution ~ip (H:\comfy\ComfyUI\venv\Lib\site-packages)
WARNING: Ignoring invalid distribution ~umpy (H:\comfy\ComfyUI\venv\Lib\site-packages)
[DONE] Security scan
** ComfyUI startup time: 2026-07-28 13:08:28.563
** Platform: Windows
** Python version: 3.12.9 (tags/v3.12.9:fdb8142, Feb  4 2025, 15:27:58) [MSC v.1942 64 bit (AMD64)]
** Python executable: H:\comfy\ComfyUI\venv\Scripts\python.exe
** ComfyUI Path: H:\comfy\ComfyUI
** ComfyUI Base Folder Path: H:\comfy\ComfyUI
** User directory: H:\comfy\ComfyUI\user
** ComfyUI-Manager config path: H:\comfy\ComfyUI\user\__manager\config.ini
** Log path: H:\comfy\ComfyUI\user\comfyui.log
WARNING: Ignoring invalid distribution ~ (H:\comfy\ComfyUI\venv\Lib\site-packages)
WARNING: Ignoring invalid distribution ~ip (H:\comfy\ComfyUI\venv\Lib\site-packages)
WARNING: Ignoring invalid distribution ~umpy (H:\comfy\ComfyUI\venv\Lib\site-packages)
WARNING: Ignoring invalid distribution ~ (H:\comfy\ComfyUI\venv\Lib\site-packages)
WARNING: Ignoring invalid distribution ~ip (H:\comfy\ComfyUI\venv\Lib\site-packages)
WARNING: Ignoring invalid distribution ~umpy (H:\comfy\ComfyUI\venv\Lib\site-packages)
[INFO] [PRE] ComfyUI-Manager
[INFO] Found triton 3.6.0. Enabling comfy-kitchen triton backend.
[INFO] Found comfy_kitchen backend triton: {'available': True, 'disabled': False, 'unavailable_reason': None, 'capabilities': ['adaln', 'apply_rope', 'apply_rope1', 'apply_rope_split_half', 'apply_rope_split_half1', 'dequantize_nvfp4', 'dequantize_per_tensor_fp8', 'int8_linear', 'quantize_and_rotate_rowwise', 'quantize_int8_rowwise', 'quantize_mxfp8', 'quantize_nvfp4', 'quantize_per_tensor_fp8']}
[INFO] Found comfy_kitchen backend eager: {'available': True, 'disabled': False, 'unavailable_reason': None, 'capabilities': ['adaln', 'apply_rope', 'apply_rope1', 'apply_rope_split_half', 'apply_rope_split_half1', 'convrot_w4a4_linear', 'dequantize_convrot_w4a4_weight', 'dequantize_int8_convrot_weight', 'dequantize_int8_convrot_weight_dtype', 'dequantize_int8_simple', 'dequantize_int8_simple_dtype', 'dequantize_mxfp8', 'dequantize_nvfp4', 'dequantize_per_tensor_fp8', 'gemv_awq_w4a16', 'int8_linear', 'prepare_int4_weight_for_int8_linear', 'quantize_and_rotate_rowwise', 'quantize_convrot_w4a4_weight', 'quantize_int8_convrot_weight', 'quantize_int8_rowwise', 'quantize_int8_tensorwise', 'quantize_mxfp8', 'quantize_nvfp4', 'quantize_per_tensor_fp8', 'quantize_svdquant_w4a4', 'rms_rope', 'rms_rope1', 'rms_rope_split_half', 'rms_rope_split_half1', 'scaled_mm_mxfp8', 'scaled_mm_nvfp4', 'scaled_mm_svdquant_w4a4', 'stochastic_rounding_fp8']}
[INFO] Found comfy_kitchen backend cuda: {'available': True, 'disabled': False, 'unavailable_reason': None, 'capabilities': ['adaln', 'apply_rope', 'apply_rope1', 'apply_rope_split_half', 'apply_rope_split_half1', 'convrot_w4a4_linear', 'dequantize_convrot_w4a4_weight', 'dequantize_int8_convrot_weight', 'dequantize_int8_convrot_weight_dtype', 'dequantize_int8_simple', 'dequantize_int8_simple_dtype', 'dequantize_nvfp4', 'dequantize_per_tensor_fp8', 'gemv_awq_w4a16', 'int8_linear', 'prepare_int4_weight_for_int8_linear', 'quantize_and_rotate_rowwise', 'quantize_convrot_w4a4_weight', 'quantize_int8_convrot_weight', 'quantize_int8_rowwise', 'quantize_int8_tensorwise', 'quantize_mxfp8', 'quantize_nvfp4', 'quantize_per_tensor_fp8', 'quantize_svdquant_w4a4', 'rms_rope', 'rms_rope1', 'rms_rope_split_half', 'rms_rope_split_half1', 'scaled_mm_nvfp4', 'scaled_mm_svdquant_w4a4', 'stochastic_rounding_fp8']}
[INFO] Checkpoint files will always be loaded safely.
[INFO] Total VRAM 12287 MB, total RAM 32693 MB
[INFO] pytorch version: 2.11.0+cu130
[INFO] Enabled fp16 accumulation.
[INFO] Set vram state to: HIGH_VRAM
[INFO] Device: cuda:0 NVIDIA GeForce RTX 3080 Ti : native
[INFO] Using async weight offloading with 2 streams
[INFO] Enabled pinned memory 13077.0
[INFO] Using sage attention
[INFO] Python version: 3.12.9 (tags/v3.12.9:fdb8142, Feb  4 2025, 15:27:58) [MSC v.1942 64 bit (AMD64)]
[INFO] ComfyUI version: 0.28.0
[INFO] comfy-aimdo version: 0.4.10
[INFO] comfy-kitchen version: 0.2.22
[INFO] comfyui-frontend-package version: 1.47.10
[INFO] comfyui-workflow-templates version: 0.11.17
[INFO] comfyui-embedded-docs version: 0.5.9
[INFO] comfy-kitchen version: 0.2.22
[INFO] comfy-aimdo version: 0.4.10
[INFO] [Prompt Server] web root: H:\comfy\ComfyUI\venv\Lib\site-packages\comfyui_frontend_package\static
[INFO] Asset seeder disabled
[INFO] [START] ComfyUI-Manager
[ComfyUI-Manager] Using GitPython backend
[INFO] [ComfyUI-Manager] network_mode: public
[INFO] No OpenGL_accelerate module loaded: No module named 'OpenGL_accelerate'
[INFO] Skipping loading of custom nodes
[INFO] Context impl SQLiteImpl.
[INFO] Will assume non-transactional DDL.
[INFO] Using RAM pressure cache.
[INFO] Starting server

[INFO] To see the GUI go to: http://127.0.0.1:8188
[INFO] got prompt
[INFO] Using pytorch attention in VAE
[INFO] Using pytorch attention in VAE
[INFO] VAE load device: cuda:0, offload device: cpu, dtype: torch.bfloat16
[INFO] Requested to load AnimaTEModel_
[INFO] loaded completely;  1136.88 MB loaded, full load: True
[INFO] CLIP/text encoder model load device: cuda:0, offload device: cpu, current: cuda:0, dtype: torch.float16
[INFO] model weight dtype torch.float16, manual cast: None
[INFO] model_type FLOW
[INFO] got prompt
[INFO] [ComfyUI-Manager] The ComfyRegistry cache update is still in progress, so an outdated cache is being used.
FETCH DATA from: H:\comfy\ComfyUI\venv\Lib\site-packages\comfyui_manager\custom-node-list.json [DONE]
[INFO] Requested to load Anima
[INFO] Unloaded partially: 312.12 MB freed, 824.75 MB remains loaded, 20.00 MB buffer reserved, lowvram patches: 0
[INFO] loaded completely;  3988.40 MB loaded, full load: True
100%|██████████████████████████████████████████████████████████████████████████████████| 30/30 [00:19<00:00,  1.51it/s]
[INFO] Requested to load WanVAE
[INFO] Unloaded partially: 3988.40 MB freed, 0.00 MB remains loaded, 190.75 MB buffer reserved, lowvram patches: 316
[INFO] loaded completely;  242.03 MB loaded, full load: True
[INFO] Prompt executed in 30.83 seconds
[INFO] Prompt executed in 0.02 seconds

Other

Suspected cause
In LoKrAdapter.calculate_weight(), dim is initialized to None and is only assigned when either w1 or w2 must be reconstructed from decomposed tensors:
https://github.com/Comfy-Org/ComfyUI/blob/master/comfy/weight_adapter/lokr.py

dim = None

if w1 is None:
    dim = w1_b.shape[0]

if w2 is None:
    dim = w2_b.shape[0]

if v[2] is not None and dim is not None:
    alpha = v[2] / dim
else:
    alpha = 1.0

When both direct lokr_w1 and lokr_w2 tensors are present, dim remains None, so the stored alpha scaling is replaced with 1.0.
The bypass h() path appears to have equivalent behavior when both direct matrices are present.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Potential BugUser is reporting a bug. This should be tested.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions