hyper-connections 0.0.14__py3-none-any.whl → 0.0.16__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hyper_connections/hyper_connections.py +6 -2
- hyper_connections/hyper_connections_with_multi_branch_inputs.py +16 -6
- {hyper_connections-0.0.14.dist-info → hyper_connections-0.0.16.dist-info}/METADATA +1 -1
- hyper_connections-0.0.16.dist-info/RECORD +7 -0
- hyper_connections-0.0.14.dist-info/RECORD +0 -7
- {hyper_connections-0.0.14.dist-info → hyper_connections-0.0.16.dist-info}/WHEEL +0 -0
- {hyper_connections-0.0.14.dist-info → hyper_connections-0.0.16.dist-info}/licenses/LICENSE +0 -0
|
@@ -121,7 +121,11 @@ class HyperConnections(Module):
|
|
|
121
121
|
self.channel_first = channel_first
|
|
122
122
|
|
|
123
123
|
@classmethod
|
|
124
|
-
def get_expand_reduce_stream_functions(cls, num_streams):
|
|
124
|
+
def get_expand_reduce_stream_functions(cls, num_streams, disable = False):
|
|
125
|
+
|
|
126
|
+
if disable:
|
|
127
|
+
return (identity, identity)
|
|
128
|
+
|
|
125
129
|
expand_fn = partial(repeat, pattern = 'b ... -> (b s) ...', s = num_streams)
|
|
126
130
|
reduce_fn = partial(reduce, pattern = '(b s) ... -> b ...', reduction = 'sum', s = num_streams)
|
|
127
131
|
|
|
@@ -133,7 +137,7 @@ class HyperConnections(Module):
|
|
|
133
137
|
hyper_conn_klass = cls if not disable else Residual
|
|
134
138
|
|
|
135
139
|
init_hyper_conn_fn = partial(hyper_conn_klass, num_streams)
|
|
136
|
-
expand_reduce_fns = cls.get_expand_reduce_stream_functions(num_streams
|
|
140
|
+
expand_reduce_fns = cls.get_expand_reduce_stream_functions(num_streams, disable = disable)
|
|
137
141
|
|
|
138
142
|
return (init_hyper_conn_fn, *expand_reduce_fns)
|
|
139
143
|
|
|
@@ -57,12 +57,19 @@ class HyperConnections(Module):
|
|
|
57
57
|
self.num_residual_streams = num_residual_streams
|
|
58
58
|
self.num_branch_inputs = num_branch_inputs
|
|
59
59
|
|
|
60
|
-
init_residual_index = default(layer_index, randrange(num_residual_streams)) % num_residual_streams # just choose one random residual stream if layer index not given
|
|
61
|
-
|
|
62
60
|
self.static_beta = nn.Parameter(torch.ones(num_residual_streams, num_branch_inputs))
|
|
63
61
|
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
# make sure each branch input receives from different residual stream on init
|
|
63
|
+
|
|
64
|
+
stream_branches = num_residual_streams * num_branch_inputs
|
|
65
|
+
layer_index = default(layer_index, randrange(stream_branches))
|
|
66
|
+
layer_offset = layer_index % stream_branches * num_branch_inputs
|
|
67
|
+
|
|
68
|
+
stream_seq = torch.arange(num_residual_streams)
|
|
69
|
+
branch_input_seq = torch.arange(num_branch_inputs)
|
|
70
|
+
|
|
71
|
+
init_alpha0 = rearrange(stream_seq, 's -> s 1') + rearrange(branch_input_seq, 'bi -> 1 bi') + layer_offset
|
|
72
|
+
init_alpha0 = ((init_alpha0 % num_residual_streams) == 0).float()
|
|
66
73
|
|
|
67
74
|
self.static_alpha = nn.Parameter(torch.cat([init_alpha0, torch.eye(num_residual_streams)], dim = 1))
|
|
68
75
|
|
|
@@ -76,7 +83,10 @@ class HyperConnections(Module):
|
|
|
76
83
|
self.channel_first = channel_first
|
|
77
84
|
|
|
78
85
|
@classmethod
|
|
79
|
-
def get_expand_reduce_stream_functions(cls, num_streams):
|
|
86
|
+
def get_expand_reduce_stream_functions(cls, num_streams, disable = False):
|
|
87
|
+
if disable:
|
|
88
|
+
return (identity, identity)
|
|
89
|
+
|
|
80
90
|
expand_fn = partial(repeat, pattern = 'b ... -> (b s) ...', s = num_streams)
|
|
81
91
|
reduce_fn = partial(reduce, pattern = '(b s) ... -> b ...', reduction = 'sum', s = num_streams)
|
|
82
92
|
|
|
@@ -88,7 +98,7 @@ class HyperConnections(Module):
|
|
|
88
98
|
hyper_conn_klass = cls if not disable else Residual
|
|
89
99
|
|
|
90
100
|
init_hyper_conn_fn = partial(hyper_conn_klass, num_streams)
|
|
91
|
-
expand_reduce_fns = cls.get_expand_reduce_stream_functions(num_streams
|
|
101
|
+
expand_reduce_fns = cls.get_expand_reduce_stream_functions(num_streams, disable = disable)
|
|
92
102
|
|
|
93
103
|
return (init_hyper_conn_fn, *expand_reduce_fns)
|
|
94
104
|
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
hyper_connections/__init__.py,sha256=mAy66IuHqXM4XOyOZGt5mo2B2hfHdUk8jW31YnWNQTg,104
|
|
2
|
+
hyper_connections/hyper_connections.py,sha256=LoyiGGDH81MLUcF9WKT39lA9Y1CXUAd-SYM9tJGQ61A,8099
|
|
3
|
+
hyper_connections/hyper_connections_with_multi_branch_inputs.py,sha256=cdYND9EdrZp1Kircrdaxd0-d8KV6VWPQeBce0k3q7Vo,6451
|
|
4
|
+
hyper_connections-0.0.16.dist-info/METADATA,sha256=4n5JPHvfqf3IMsDCkw4h3uTGm4WRTnWVz3sMRwQFHTI,5076
|
|
5
|
+
hyper_connections-0.0.16.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
6
|
+
hyper_connections-0.0.16.dist-info/licenses/LICENSE,sha256=E7RGS7kpJIStk5za_-4DVhWEAamf65EU0CNML25mq4c,1066
|
|
7
|
+
hyper_connections-0.0.16.dist-info/RECORD,,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
hyper_connections/__init__.py,sha256=mAy66IuHqXM4XOyOZGt5mo2B2hfHdUk8jW31YnWNQTg,104
|
|
2
|
-
hyper_connections/hyper_connections.py,sha256=-cqKAGkvSf9NKP-S5cmZU9h59qyPbDq27CSDTmZ5fm8,8042
|
|
3
|
-
hyper_connections/hyper_connections_with_multi_branch_inputs.py,sha256=jn-wxAgECVUpiyf1elTtwcr-wvzCQQVS32rxted7XqU,6091
|
|
4
|
-
hyper_connections-0.0.14.dist-info/METADATA,sha256=mM6YzyPTNDYZqR-l8cwqxnZfYngaNf0LunycWmIoP4Y,5076
|
|
5
|
-
hyper_connections-0.0.14.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
6
|
-
hyper_connections-0.0.14.dist-info/licenses/LICENSE,sha256=E7RGS7kpJIStk5za_-4DVhWEAamf65EU0CNML25mq4c,1066
|
|
7
|
-
hyper_connections-0.0.14.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|