hyper-connections 0.1.4__tar.gz → 0.1.6__tar.gz
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-0.1.4 → hyper_connections-0.1.6}/PKG-INFO +1 -1
- {hyper_connections-0.1.4 → hyper_connections-0.1.6}/hyper_connections/hyper_connections.py +5 -4
- {hyper_connections-0.1.4 → hyper_connections-0.1.6}/hyper_connections/hyper_connections_with_multi_branch_inputs.py +5 -4
- {hyper_connections-0.1.4 → hyper_connections-0.1.6}/hyper_connections/hyper_connections_with_multi_input_streams.py +7 -10
- {hyper_connections-0.1.4 → hyper_connections-0.1.6}/pyproject.toml +1 -1
- {hyper_connections-0.1.4 → hyper_connections-0.1.6}/.github/workflows/python-publish.yml +0 -0
- {hyper_connections-0.1.4 → hyper_connections-0.1.6}/.github/workflows/test.yml +0 -0
- {hyper_connections-0.1.4 → hyper_connections-0.1.6}/.gitignore +0 -0
- {hyper_connections-0.1.4 → hyper_connections-0.1.6}/LICENSE +0 -0
- {hyper_connections-0.1.4 → hyper_connections-0.1.6}/README.md +0 -0
- {hyper_connections-0.1.4 → hyper_connections-0.1.6}/hyper-connections.png +0 -0
- {hyper_connections-0.1.4 → hyper_connections-0.1.6}/hyper_connections/__init__.py +0 -0
- {hyper_connections-0.1.4 → hyper_connections-0.1.6}/tests/test_hyper_connections.py +0 -0
|
@@ -11,6 +11,7 @@ import torch.nn.functional as F
|
|
|
11
11
|
from torch.utils._pytree import tree_flatten, tree_unflatten
|
|
12
12
|
|
|
13
13
|
from einops import rearrange, repeat, reduce, einsum
|
|
14
|
+
from einops.layers.torch import Reduce
|
|
14
15
|
|
|
15
16
|
"""
|
|
16
17
|
ein notation:
|
|
@@ -35,11 +36,11 @@ def identity(t):
|
|
|
35
36
|
|
|
36
37
|
def get_expand_reduce_stream_functions(num_streams, disable = False):
|
|
37
38
|
|
|
38
|
-
if disable:
|
|
39
|
-
return (
|
|
39
|
+
if num_streams == 1 or disable:
|
|
40
|
+
return (nn.Identity(), nn.Identity())
|
|
40
41
|
|
|
41
|
-
expand_fn =
|
|
42
|
-
reduce_fn =
|
|
42
|
+
expand_fn = Reduce(pattern = 'b ... -> (b s) ...', reduction = 'repeat', s = num_streams)
|
|
43
|
+
reduce_fn = Reduce(pattern = '(b s) ... -> b ...', reduction = 'sum', s = num_streams)
|
|
43
44
|
|
|
44
45
|
return expand_fn, reduce_fn
|
|
45
46
|
|
|
@@ -11,6 +11,7 @@ from torch.nn import Module, ModuleList
|
|
|
11
11
|
from torch.utils._pytree import tree_flatten, tree_unflatten
|
|
12
12
|
|
|
13
13
|
from einops import rearrange, repeat, reduce, einsum
|
|
14
|
+
from einops.layers.torch import Reduce
|
|
14
15
|
|
|
15
16
|
"""
|
|
16
17
|
ein notation:
|
|
@@ -41,11 +42,11 @@ def identity(t):
|
|
|
41
42
|
# main functions
|
|
42
43
|
|
|
43
44
|
def get_expand_reduce_stream_functions(cls, num_streams, disable = False):
|
|
44
|
-
if disable:
|
|
45
|
-
return (
|
|
45
|
+
if num_streams == 1 or disable:
|
|
46
|
+
return (nn.Identity(), nn.Identity())
|
|
46
47
|
|
|
47
|
-
expand_fn =
|
|
48
|
-
reduce_fn =
|
|
48
|
+
expand_fn = Reduce(pattern = 'b ... -> (b s) ...', reduction = 'repeat', s = num_streams)
|
|
49
|
+
reduce_fn = Reduce(pattern = '(b s) ... -> b ...', reduction = 'sum', s = num_streams)
|
|
49
50
|
|
|
50
51
|
return expand_fn, reduce_fn
|
|
51
52
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
|
-
from typing import Callable
|
|
2
|
+
from typing import Callable, Union
|
|
3
3
|
|
|
4
4
|
from functools import partial
|
|
5
5
|
from random import randrange
|
|
@@ -11,7 +11,7 @@ from torch.nn import Module, ModuleList
|
|
|
11
11
|
from torch.utils._pytree import tree_flatten, tree_unflatten
|
|
12
12
|
|
|
13
13
|
from einops import rearrange, repeat, reduce, einsum
|
|
14
|
-
from einops.layers.torch import Rearrange
|
|
14
|
+
from einops.layers.torch import Rearrange, Reduce
|
|
15
15
|
|
|
16
16
|
"""
|
|
17
17
|
ein notation:
|
|
@@ -29,18 +29,15 @@ def exists(v):
|
|
|
29
29
|
def default(v, d):
|
|
30
30
|
return v if exists(v) else d
|
|
31
31
|
|
|
32
|
-
def identity(t):
|
|
33
|
-
return t
|
|
34
|
-
|
|
35
32
|
# main functions
|
|
36
33
|
|
|
37
34
|
def get_expand_reduce_stream_functions(num_streams, disable = False):
|
|
38
35
|
|
|
39
|
-
if disable:
|
|
40
|
-
return (
|
|
36
|
+
if num_streams == 1 or disable:
|
|
37
|
+
return (nn.Identity(), nn.Identity())
|
|
41
38
|
|
|
42
|
-
expand_fn =
|
|
43
|
-
reduce_fn =
|
|
39
|
+
expand_fn = Reduce(pattern = 'b ... -> (b s) ...', reduction = 'repeat', s = num_streams)
|
|
40
|
+
reduce_fn = Reduce(pattern = '(b s) ... -> b ...', reduction = 'sum', s = num_streams)
|
|
44
41
|
|
|
45
42
|
return expand_fn, reduce_fn
|
|
46
43
|
|
|
@@ -142,7 +139,7 @@ class Residual(Module):
|
|
|
142
139
|
|
|
143
140
|
# hyper connection with multiple input streams
|
|
144
141
|
|
|
145
|
-
InputPathType = int
|
|
142
|
+
InputPathType = Union[int, str] # the path to the second residual stream, where `int` points to *args[`int`] and `str` points to **kwargs[`str`] - `int` needs to be > 0, as 0 is the default input residual stream
|
|
146
143
|
|
|
147
144
|
class HyperConnections(Module):
|
|
148
145
|
def __init__(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|