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

Method __init__

diffusers/src/diffusers/models/lora.py:258–284  ·  view source on GitHub ↗
(
        self,
        in_features: int,
        out_features: int,
        rank: int = 4,
        kernel_size: Union[int, Tuple[int, int]] = (1, 1),
        stride: Union[int, Tuple[int, int]] = (1, 1),
        padding: Union[int, Tuple[int, int], str] = 0,
        network_alpha: Optional[float] = None,
    )

Source from the content-addressed store, hash-verified

256 """
257
258 def __init__(
259 self,
260 in_features: int,
261 out_features: int,
262 rank: int = 4,
263 kernel_size: Union[int, Tuple[int, int]] = (1, 1),
264 stride: Union[int, Tuple[int, int]] = (1, 1),
265 padding: Union[int, Tuple[int, int], str] = 0,
266 network_alpha: Optional[float] = None,
267 ):
268 super().__init__()
269
270 deprecation_message = "Use of `LoRAConv2dLayer` is deprecated. Please switch to PEFT backend by installing PEFT: `pip install peft`."
271 deprecate("LoRAConv2dLayer", "1.0.0", deprecation_message)
272
273 self.down = nn.Conv2d(in_features, rank, kernel_size=kernel_size, stride=stride, padding=padding, bias=False)
274 # according to the official kohya_ss trainer kernel_size are always fixed for the up layer
275 # # see: https://github.com/bmaltais/kohya_ss/blob/2accb1305979ba62f5077a23aabac23b4c37e935/networks/lora_diffusers.py#L129
276 self.up = nn.Conv2d(rank, out_features, kernel_size=(1, 1), stride=(1, 1), bias=False)
277
278 # This value has the same meaning as the `--network_alpha` option in the kohya-ss trainer script.
279 # See https://github.com/darkstorm2150/sd-scripts/blob/main/docs/train_network_README-en.md#execute-learning
280 self.network_alpha = network_alpha
281 self.rank = rank
282
283 nn.init.normal_(self.down.weight, std=1 / rank)
284 nn.init.zeros_(self.up.weight)
285
286 def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
287 orig_dtype = hidden_states.dtype

Callers

nothing calls this directly

Calls 2

deprecateFunction · 0.85
__init__Method · 0.45

Tested by

no test coverage detected