forked from AUTOMATIC1111/stable-diffusion-webui
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
233 changed files
with
8,015 additions
and
8,768 deletions.
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,31 @@ | ||
import torch | ||
|
||
import networks | ||
from modules import patches | ||
|
||
|
||
class LoraPatches: | ||
def __init__(self): | ||
self.Linear_forward = patches.patch(__name__, torch.nn.Linear, 'forward', networks.network_Linear_forward) | ||
self.Linear_load_state_dict = patches.patch(__name__, torch.nn.Linear, '_load_from_state_dict', networks.network_Linear_load_state_dict) | ||
self.Conv2d_forward = patches.patch(__name__, torch.nn.Conv2d, 'forward', networks.network_Conv2d_forward) | ||
self.Conv2d_load_state_dict = patches.patch(__name__, torch.nn.Conv2d, '_load_from_state_dict', networks.network_Conv2d_load_state_dict) | ||
self.GroupNorm_forward = patches.patch(__name__, torch.nn.GroupNorm, 'forward', networks.network_GroupNorm_forward) | ||
self.GroupNorm_load_state_dict = patches.patch(__name__, torch.nn.GroupNorm, '_load_from_state_dict', networks.network_GroupNorm_load_state_dict) | ||
self.LayerNorm_forward = patches.patch(__name__, torch.nn.LayerNorm, 'forward', networks.network_LayerNorm_forward) | ||
self.LayerNorm_load_state_dict = patches.patch(__name__, torch.nn.LayerNorm, '_load_from_state_dict', networks.network_LayerNorm_load_state_dict) | ||
self.MultiheadAttention_forward = patches.patch(__name__, torch.nn.MultiheadAttention, 'forward', networks.network_MultiheadAttention_forward) | ||
self.MultiheadAttention_load_state_dict = patches.patch(__name__, torch.nn.MultiheadAttention, '_load_from_state_dict', networks.network_MultiheadAttention_load_state_dict) | ||
|
||
def undo(self): | ||
self.Linear_forward = patches.undo(__name__, torch.nn.Linear, 'forward') | ||
self.Linear_load_state_dict = patches.undo(__name__, torch.nn.Linear, '_load_from_state_dict') | ||
self.Conv2d_forward = patches.undo(__name__, torch.nn.Conv2d, 'forward') | ||
self.Conv2d_load_state_dict = patches.undo(__name__, torch.nn.Conv2d, '_load_from_state_dict') | ||
self.GroupNorm_forward = patches.undo(__name__, torch.nn.GroupNorm, 'forward') | ||
self.GroupNorm_load_state_dict = patches.undo(__name__, torch.nn.GroupNorm, '_load_from_state_dict') | ||
self.LayerNorm_forward = patches.undo(__name__, torch.nn.LayerNorm, 'forward') | ||
self.LayerNorm_load_state_dict = patches.undo(__name__, torch.nn.LayerNorm, '_load_from_state_dict') | ||
self.MultiheadAttention_forward = patches.undo(__name__, torch.nn.MultiheadAttention, 'forward') | ||
self.MultiheadAttention_load_state_dict = patches.undo(__name__, torch.nn.MultiheadAttention, '_load_from_state_dict') | ||
|
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
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,28 @@ | ||
import network | ||
|
||
|
||
class ModuleTypeNorm(network.ModuleType): | ||
def create_module(self, net: network.Network, weights: network.NetworkWeights): | ||
if all(x in weights.w for x in ["w_norm", "b_norm"]): | ||
return NetworkModuleNorm(net, weights) | ||
|
||
return None | ||
|
||
|
||
class NetworkModuleNorm(network.NetworkModule): | ||
def __init__(self, net: network.Network, weights: network.NetworkWeights): | ||
super().__init__(net, weights) | ||
|
||
self.w_norm = weights.w.get("w_norm") | ||
self.b_norm = weights.w.get("b_norm") | ||
|
||
def calc_updown(self, orig_weight): | ||
output_shape = self.w_norm.shape | ||
updown = self.w_norm.to(orig_weight.device, dtype=orig_weight.dtype) | ||
|
||
if self.b_norm is not None: | ||
ex_bias = self.b_norm.to(orig_weight.device, dtype=orig_weight.dtype) | ||
else: | ||
ex_bias = None | ||
|
||
return self.finalize_updown(updown, orig_weight, output_shape, ex_bias) |
Oops, something went wrong.