@@ -2643,8 +2643,8 @@ def _convert_to_ai_toolkit_cat(sds_sd, ait_sd, sds_key, ait_keys, dims=None):
26432643def _nearest_kronecker_product (matrix , m1 , n1 , m2 , n2 ):
26442644 """Find the nearest rank-1 Kronecker product approximation (Van Loan & Pitsianis).
26452645
2646- Given matrix M of shape (m1*m2, n1*n2), finds w1 (m1, n1) and w2 (m2, n2)
2647- minimizing ||M - kron(w1, w2)||_F via rank-1 SVD of a rearranged matrix.
2646+ Given matrix M of shape (m1*m2, n1*n2), finds w1 (m1, n1) and w2 (m2, n2) minimizing ||M - kron(w1, w2)||_F via
2647+ rank-1 SVD of a rearranged matrix.
26482648 """
26492649 # Rearrange M into R of shape (m1*n1, m2*n2)
26502650 # R[i*n1+j, k*n2+l] = M[i*m2+k, j*n2+l]
@@ -2661,8 +2661,8 @@ def _nearest_kronecker_product(matrix, m1, n1, m2, n2):
26612661def _split_lokr_qkv (w1 , w2 , target_keys , factor ):
26622662 """Split fused LoKR QKV factors into separate per-projection Kronecker factors.
26632663
2664- Materializes kron(w1, w2), chunks along dim=0, and re-factorizes each chunk
2665- as a rank-1 Kronecker product using the Van Loan algorithm.
2664+ Materializes kron(w1, w2), chunks along dim=0, and re-factorizes each chunk as a rank-1 Kronecker product using the
2665+ Van Loan algorithm.
26662666
26672667 Args:
26682668 w1: First Kronecker factor, shape (f, f) where f = decompose_factor.
@@ -2694,9 +2694,8 @@ def _convert_non_diffusers_flux2_lokr_to_diffusers(state_dict, fuse_qkv=False):
26942694 Args:
26952695 state_dict: BFL-format LoKR state dict with ``diffusion_model.`` prefix.
26962696 fuse_qkv: If True, map fused QKV directly to ``to_qkv``/``to_added_qkv`` targets
2697- (lossless, but requires the model's QKV to be fused before injection).
2698- If False (default), split fused QKV into separate Q/K/V via Kronecker
2699- re-factorization (slightly lossy, no model fusion needed).
2697+ (lossless, but requires the model's QKV to be fused before injection). If False (default), split fused QKV
2698+ into separate Q/K/V via Kronecker re-factorization (slightly lossy, no model fusion needed).
27002699 """
27012700 converted_state_dict = {}
27022701
@@ -2891,8 +2890,8 @@ def _bake_lokr_alpha(state_dict):
28912890def _convert_lycoris_flux2_lokr_to_diffusers (state_dict ):
28922891 """Convert LyCORIS underscore-format Flux2 LoKR state dict to peft-compatible diffusers format.
28932892
2894- LyCORIS keys use underscore-encoded paths (e.g., lycoris_transformer_blocks_0_attn_to_q.lokr_w1).
2895- Decodes these to dotted diffusers paths using a known sub-path lookup table.
2893+ LyCORIS keys use underscore-encoded paths (e.g., lycoris_transformer_blocks_0_attn_to_q.lokr_w1). Decodes these to
2894+ dotted diffusers paths using a known sub-path lookup table.
28962895 """
28972896 import re
28982897
@@ -2938,8 +2937,8 @@ def _convert_lycoris_flux2_lokr_to_diffusers(state_dict):
29382937def _convert_diffusers_flux2_lokr_to_peft (state_dict ):
29392938 """Convert diffusers-native Flux2 LoKR state dict by adding transformer. prefix and baking alpha.
29402939
2941- Diffusers-native keys already use dotted module paths matching the model structure.
2942- Only alpha baking and the transformer. prefix are needed.
2940+ Diffusers-native keys already use dotted module paths matching the model structure. Only alpha baking and the
2941+ transformer. prefix are needed.
29432942 """
29442943 original_state_dict = dict (state_dict )
29452944 _bake_lokr_alpha (original_state_dict )
0 commit comments