Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
AUTOMATIC1111
GitHub Repository: AUTOMATIC1111/stable-diffusion-webui
Path: blob/master/extensions-builtin/Lora/network_full.py
2447 views
1
import network
2
3
4
class ModuleTypeFull(network.ModuleType):
5
def create_module(self, net: network.Network, weights: network.NetworkWeights):
6
if all(x in weights.w for x in ["diff"]):
7
return NetworkModuleFull(net, weights)
8
9
return None
10
11
12
class NetworkModuleFull(network.NetworkModule):
13
def __init__(self, net: network.Network, weights: network.NetworkWeights):
14
super().__init__(net, weights)
15
16
self.weight = weights.w.get("diff")
17
self.ex_bias = weights.w.get("diff_b")
18
19
def calc_updown(self, orig_weight):
20
output_shape = self.weight.shape
21
updown = self.weight.to(orig_weight.device)
22
if self.ex_bias is not None:
23
ex_bias = self.ex_bias.to(orig_weight.device)
24
else:
25
ex_bias = None
26
27
return self.finalize_updown(updown, orig_weight, output_shape, ex_bias)
28
29