MCPcopy Create free account
hub / github.com/KohakuBlueleaf/LyCORIS / __init__

Method __init__

lycoris/modules/base.py:90–225  ·  view source on GitHub ↗

if alpha == 0 or None, alpha is rank (no scaling).

(
        self,
        lora_name,
        org_module: nn.Module,
        multiplier=1.0,
        dropout=0.0,
        rank_dropout=0.0,
        module_dropout=0.0,
        rank_dropout_scale=False,
        bypass_mode=None,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

88 destination = OrderedDict()
89 destination._metadata = OrderedDict()
90
91 local_metadata = dict(version=self._version)
92 if hasattr(destination, "_metadata"):
93 destination._metadata[prefix[:-1]] = local_metadata
94
95 if (custom_sd := self.custom_state_dict()) is not None:
96 for k, v in custom_sd.items():
97 destination[f"{prefix}{k}"] = v
98 return destination
99 else:
100 return super().state_dict(
101 *args, destination=destination, prefix=prefix, keep_vars=keep_vars
102 )
103
104
105@dataclass
106class _MergeContext:
107 precise: bool
108 target_device: torch.device
109 target_dtype: torch.dtype
110 compute_dtype: torch.dtype
111 param_device: torch.device | None
112 param_dtype: torch.dtype | None
113 module: nn.Module
114 weight_param: torch.Tensor
115 bias_param: torch.Tensor | None
116
117
118class LycorisBaseModule(ModuleCustomSD):
119 name: str
120 dtype_tensor: torch.Tensor
121 support_module = {}
122 weight_list = []
123 weight_list_det = []
124
125 def __init__(
126 self,
127 lora_name,
128 org_module: nn.Module,
129 multiplier=1.0,
130 dropout=0.0,
131 rank_dropout=0.0,
132 module_dropout=0.0,
133 rank_dropout_scale=False,
134 bypass_mode=None,
135 **kwargs,
136 ):
137 """if alpha == 0 or None, alpha is rank (no scaling)."""
138 super().__init__()
139 self.lora_name = lora_name
140 self.not_supported = False
141
142 self.peft_wrapper = None
143 if BaseTunerLayer is not None and isinstance(org_module, BaseTunerLayer):
144 self.peft_wrapper = org_module
145 base_layer = getattr(org_module, "base_layer", None)
146 if base_layer is None and hasattr(org_module, "get_base_layer"):
147 base_layer = org_module.get_base_layer()

Callers

nothing calls this directly

Calls 3

log_bypassFunction · 0.85
log_suspectFunction · 0.85
__init__Method · 0.45

Tested by

no test coverage detected