Files
Hearmeman24-ComfyUI-LoRABlo…/__init__.py
Hearmeman24 49e5be766b feat: LoRA block profiler + in-memory block filter
Two ComfyUI nodes. Measure the Frobenius norm of the effective weight delta per
transformer block, then apply only the blocks you choose. The .safetensors is
opened read-only and never rewritten.

Measures up@down (or kron(w1,w2) for LoKr), not the stored factors: LoRA has a
free scale, so factor norms alone carry no information. Both fast paths are exact
and avoid materialising the delta, and both are checked against explicitly
materialised products in the tests.

Unsupported formats are reported as NOT MEASURED, never folded into a zero -- a
silent zero would make a block look prunable when it was merely not understood.

39 tests, no network, no GPU, no ComfyUI import.
2026-08-17 12:27:10 +03:00

25 lines
983 B
Python

"""ComfyUI-LoRABlockSurgeon — measure and filter a LoRA per transformer block.
Read-only against the .safetensors on disk. Nothing is ever written or rewritten.
"""
import logging
logger = logging.getLogger("LoRABlockSurgeon")
if __package__:
# Normal path: ComfyUI imports this directory as a package.
from .nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
logger.info("[LoRABlockSurgeon] registered %d nodes: %s",
len(NODE_CLASS_MAPPINGS), ", ".join(sorted(NODE_CLASS_MAPPINGS)))
else:
# Imported as a top-level module with no parent package — which is what pytest
# does when it treats this directory as the tests' parent. `comfy.sd` is not
# importable there. Checking __package__ rather than catching ImportError keeps
# a genuinely broken import inside nodes.py loud under ComfyUI.
NODE_CLASS_MAPPINGS = {}
NODE_DISPLAY_NAME_MAPPINGS = {}
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"]