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

Method apply_max_norm

lycoris/modules/locon.py:274–284  ·  view source on GitHub ↗
(self, max_norm, device=None)

Source from the content-addressed store, hash-verified

272 if self.module_type == "linear":
273 mid = F.linear(x, self.lora_down.weight.to(x))
274 elif self.tucker:
275 mid = self.lora_mid(self.lora_down(x))
276 else:
277 mid = self.lora_down(x)
278 drop = (
279 torch.rand(self.lora_dim, device=mid.device) > self.rank_dropout
280 ).to(mid.dtype)
281 if self.rank_dropout_scale:
282 drop /= drop.mean()
283 if (dims := len(x.shape)) == 4:
284 drop = drop.view(1, -1, 1, 1)
285 else:
286 drop = drop.view(*[1] * (dims - 1), -1)
287 mid = mid * drop

Callers

nothing calls this directly

Calls 1

make_weightMethod · 0.95

Tested by

no test coverage detected