hyper-connections 0.1.12__py3-none-any.whl → 0.1.14__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/residuals.py +22 -6
- {hyper_connections-0.1.12.dist-info → hyper_connections-0.1.14.dist-info}/METADATA +1 -1
- {hyper_connections-0.1.12.dist-info → hyper_connections-0.1.14.dist-info}/RECORD +5 -5
- {hyper_connections-0.1.12.dist-info → hyper_connections-0.1.14.dist-info}/WHEEL +0 -0
- {hyper_connections-0.1.12.dist-info → hyper_connections-0.1.14.dist-info}/licenses/LICENSE +0 -0
hyper_connections/residuals.py
CHANGED
|
@@ -2,7 +2,7 @@ import torch
|
|
|
2
2
|
from torch import nn
|
|
3
3
|
from torch.nn import Module
|
|
4
4
|
|
|
5
|
-
from einops import rearrange
|
|
5
|
+
from einops import rearrange, pack, unpack
|
|
6
6
|
|
|
7
7
|
class GRUGatedResidual(Module):
|
|
8
8
|
def __init__(
|
|
@@ -13,10 +13,26 @@ class GRUGatedResidual(Module):
|
|
|
13
13
|
self.gru = nn.GRUCell(dim, dim)
|
|
14
14
|
|
|
15
15
|
def forward(self, x, residual):
|
|
16
|
+
x, ps = pack([x], '* d')
|
|
17
|
+
residual, _ = pack([residual], '* d')
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
rearrange(x, 'b n d -> (b n) d'),
|
|
19
|
-
rearrange(residual, 'b n d -> (b n) d')
|
|
20
|
-
)
|
|
19
|
+
output = self.gru(x, residual)
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
output, = unpack(output, ps, '* d')
|
|
22
|
+
return output
|
|
23
|
+
|
|
24
|
+
class GatedResidual(Module):
|
|
25
|
+
def __init__(
|
|
26
|
+
self,
|
|
27
|
+
dim
|
|
28
|
+
):
|
|
29
|
+
super().__init__()
|
|
30
|
+
self.to_learned_mix = nn.Linear(dim * 2, dim)
|
|
31
|
+
|
|
32
|
+
def forward(self, x, residual):
|
|
33
|
+
x_and_residual, _ = pack([x, residual], 'b n *')
|
|
34
|
+
|
|
35
|
+
mix = self.to_learned_mix(x_and_residual)
|
|
36
|
+
|
|
37
|
+
out = x.lerp(residual, mix.sigmoid())
|
|
38
|
+
return out
|
|
@@ -3,8 +3,8 @@ hyper_connections/hyper_connections.py,sha256=vpipBRUGgYQ2qLBtT4Ws-myJYVdkQDkN3I
|
|
|
3
3
|
hyper_connections/hyper_connections_channel_first.py,sha256=BojfO2dcT4jX1rlcU3kr0B6B_CjrkkS2AZU4ZXeWvh8,6769
|
|
4
4
|
hyper_connections/hyper_connections_with_multi_branch_inputs.py,sha256=2JABz1slrF5_XP33L1CMNTmmixfoD464FtQpUADqneU,7806
|
|
5
5
|
hyper_connections/hyper_connections_with_multi_input_streams.py,sha256=UIKceEZEBLKFL5VuP5tR1KTDeZNIJEKjFuPAwXkcp0I,11282
|
|
6
|
-
hyper_connections/residuals.py,sha256=
|
|
7
|
-
hyper_connections-0.1.
|
|
8
|
-
hyper_connections-0.1.
|
|
9
|
-
hyper_connections-0.1.
|
|
10
|
-
hyper_connections-0.1.
|
|
6
|
+
hyper_connections/residuals.py,sha256=qapN4lt51qNWKa5nX7whN4xcNORxMdr3bdUwIMQPdpQ,853
|
|
7
|
+
hyper_connections-0.1.14.dist-info/METADATA,sha256=7Agg3rGvMYkZEyX3n9yJPO4cNm8-9a33afV4Yc8r7WA,5231
|
|
8
|
+
hyper_connections-0.1.14.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
9
|
+
hyper_connections-0.1.14.dist-info/licenses/LICENSE,sha256=E7RGS7kpJIStk5za_-4DVhWEAamf65EU0CNML25mq4c,1066
|
|
10
|
+
hyper_connections-0.1.14.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|