-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #948 from bghira/main
merge
- Loading branch information
Showing
4 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import torch | ||
|
||
|
||
def approximate_normal_tensor(inp, target, scale=1.0): | ||
tensor = torch.randn_like(target) | ||
desired_norm = inp.norm() | ||
desired_mean = inp.mean() | ||
desired_std = inp.std() | ||
|
||
current_norm = tensor.norm() | ||
tensor = tensor * (desired_norm / current_norm) | ||
current_std = tensor.std() | ||
tensor = tensor * (desired_std / current_std) | ||
tensor = tensor - tensor.mean() + desired_mean | ||
tensor.mul_(scale) | ||
|
||
target.copy_(tensor) | ||
|
||
|
||
def init_lokr_network_with_perturbed_normal(lycoris, scale=1e-3): | ||
with torch.no_grad(): | ||
for lora in lycoris.loras: | ||
lora.lokr_w1.fill_(1.0) | ||
approximate_normal_tensor(lora.org_weight, lora.lokr_w2, scale=scale) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters