API Reference [WIP]
September 1, 2026 · View on GitHub
Module
Class: LycorisBaseModule:
-
classmethod
parametrizealgo_checkextract_state_dictmake_module_from_state_dict
-
property
dtypedeviceorg_weight
-
methods
apply_torestoremerge_toget_diff_weightget_merged_weightapply_max_normbypass_forward_diffbypass_forwardparametrize_forwardforward
Subclasses
LoConModuleLohaModuleLokrModuleDyLoraModuleGLoRAModuleNormModuleFullModuleDiagOFTModule
Functions
get_module: determine the algorithm and extract corresponding weights from state dict.make_module: based on given algorithm and weights to construct modules.
Functional
For each modules, we have 3 basic methods:
weight_gen: Generate weights for corresponding algorithmweight_diff: calculatebypass_forward_diff: calculate
There are some other utilities:
factorization:- where , , and
- This method have been used in LoKr and Diag-OFT.
power2factorization:- where , , , , and
- This method have been used in BOFT.
tucker_weightandtucker_weight_from_conv: Reconstruct tucker decomposed weight from tensors or conv modules.
Usage
For all the functional API, you can directly use any kind of them with following example:
from lycoris.functional import xxx
weights = xxx.weight_gen(org_weight)
def forward_with_diff_weight(x, org_weight, weights):
return org_forward(x, org_weight + xxx.weight_diff(*weights))
def forward_with_diff_activation(x, org_weight, weights):
org_out = org_forward(x, org_weight)
return org_out + xxx.bypass_forward_diff(x, org_out, *weights)
Although different algorithm will have different extra arguments for weight_diff and bypass_forward_diff, the overall logic is same.
Backends
Every functional entry point keeps this signature and picks a backend for the
call underneath it — a fused Triton/TileLang kernel, a torch.compiled
version of the same op, or the eager body. Nothing about the call changes; see
kernels/README.md, and
kernels/backends.md for how to pin one.
lycoris.functional.general also exposes the two ops that are shared between
algorithms rather than owned by one:
weight_decompose: the DoRA epilogue,W · (m·(d/‖W‖ − 1) + 1), used by dora, doha and dokr alike.add_scaled:W_org + γ·ΔW, used by thefullandnormmodules.
Others
wrapper
LycorisNetwork: the wrapper class to patch any pytorch modules to apply LyCORIS algorithms.create_lycoris: see examplecreate_lycoris_from_weights: see example
LycorisNetwork.apply_to() can be invoked multiple times on the same module with different wrapper instances. Each wrapper is stacked on top of the previous one, and calling restore() on a wrapper removes only its own contribution while keeping earlier wrappers active.
See example/stacked_wrapper_demo.py for a script that showcases stacking and selective removal in practice.
kohya
- the specialized wrapper for kohya-ss/sd-scripts.