MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / handle_qkv

Function handle_qkv

diffusers/src/diffusers/loaders/lora_conversion_utils.py:571–590  ·  view source on GitHub ↗
(sds_sd, ait_sd, sds_key, ait_keys, dims=None)

Source from the content-addressed store, hash-verified

569 orig_keys = list(old_state_dict.keys())
570
571 def handle_qkv(sds_sd, ait_sd, sds_key, ait_keys, dims=None):
572 down_weight = sds_sd.pop(sds_key)
573 up_weight = sds_sd.pop(sds_key.replace(".down.weight", ".up.weight"))
574
575 # calculate dims if not provided
576 num_splits = len(ait_keys)
577 if dims is None:
578 dims = [up_weight.shape[0] // num_splits] * num_splits
579 else:
580 assert sum(dims) == up_weight.shape[0]
581
582 # make ai-toolkit weight
583 ait_down_keys = [k + ".lora_A.weight" for k in ait_keys]
584 ait_up_keys = [k + ".lora_B.weight" for k in ait_keys]
585
586 # down_weight is copied to each split
587 ait_sd.update({k: down_weight for k in ait_down_keys})
588
589 # up_weight is split to each split
590 ait_sd.update({k: v for k, v in zip(ait_up_keys, torch.split(up_weight, dims, dim=0))}) # noqa: C416
591
592 for old_key in orig_keys:
593 # Handle double_blocks

Callers 1

Calls 2

popMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected