2023-07-16 21:12:18 +00:00
|
|
|
import network
|
|
|
|
|
|
|
|
|
|
|
|
class ModuleTypeIa3(network.ModuleType):
|
|
|
|
def create_module(self, net: network.Network, weights: network.NetworkWeights):
|
|
|
|
if all(x in weights.w for x in ["weight"]):
|
|
|
|
return NetworkModuleIa3(net, weights)
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2023-07-17 06:00:47 +00:00
|
|
|
class NetworkModuleIa3(network.NetworkModule):
|
2023-07-16 21:12:18 +00:00
|
|
|
def __init__(self, net: network.Network, weights: network.NetworkWeights):
|
|
|
|
super().__init__(net, weights)
|
|
|
|
|
|
|
|
self.w = weights.w["weight"]
|
|
|
|
self.on_input = weights.w["on_input"].item()
|
|
|
|
|
|
|
|
def calc_updown(self, orig_weight):
|
2023-10-19 05:56:17 +00:00
|
|
|
w = self.w.to(orig_weight.device)
|
2023-07-16 21:12:18 +00:00
|
|
|
|
|
|
|
output_shape = [w.size(0), orig_weight.size(1)]
|
|
|
|
if self.on_input:
|
|
|
|
output_shape.reverse()
|
|
|
|
else:
|
|
|
|
w = w.reshape(-1, 1)
|
|
|
|
|
|
|
|
updown = orig_weight * w
|
|
|
|
|
|
|
|
return self.finalize_updown(updown, orig_weight, output_shape)
|