hyper-connections 0.1.4__py3-none-any.whl → 0.1.6__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.
@@ -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 (identity, identity)
39
+ if num_streams == 1 or disable:
40
+ return (nn.Identity(), nn.Identity())
40
41
 
41
- expand_fn = partial(repeat, pattern = 'b ... -> (b s) ...', s = num_streams)
42
- reduce_fn = partial(reduce, pattern = '(b s) ... -> b ...', reduction = 'sum', s = num_streams)
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 (identity, identity)
45
+ if num_streams == 1 or disable:
46
+ return (nn.Identity(), nn.Identity())
46
47
 
47
- expand_fn = partial(repeat, pattern = 'b ... -> (b s) ...', s = num_streams)
48
- reduce_fn = partial(reduce, pattern = '(b s) ... -> b ...', reduction = 'sum', s = num_streams)
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 (identity, identity)
36
+ if num_streams == 1 or disable:
37
+ return (nn.Identity(), nn.Identity())
41
38
 
42
- expand_fn = partial(repeat, pattern = 'b ... -> (b s) ...', s = num_streams)
43
- reduce_fn = partial(reduce, pattern = '(b s) ... -> b ...', reduction = 'sum', s = num_streams)
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 | 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
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__(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hyper-connections
3
- Version: 0.1.4
3
+ Version: 0.1.6
4
4
  Summary: Hyper-Connections
5
5
  Project-URL: Homepage, https://pypi.org/project/hyper-connections/
6
6
  Project-URL: Repository, https://github.com/lucidrains/hyper-connections
@@ -0,0 +1,8 @@
1
+ hyper_connections/__init__.py,sha256=d2zNTka0Gp9vINu4U-RhgTJFBhsVrs1fne_15Zl0oOs,224
2
+ hyper_connections/hyper_connections.py,sha256=KBf5xiblM53jbKp_IwAgWAKQetLYWKmK8-6qNn2fHoU,10007
3
+ hyper_connections/hyper_connections_with_multi_branch_inputs.py,sha256=2JABz1slrF5_XP33L1CMNTmmixfoD464FtQpUADqneU,7806
4
+ hyper_connections/hyper_connections_with_multi_input_streams.py,sha256=UIKceEZEBLKFL5VuP5tR1KTDeZNIJEKjFuPAwXkcp0I,11282
5
+ hyper_connections-0.1.6.dist-info/METADATA,sha256=3KIWntaZvm8k5BCCs_L1lOmmpB03jgEyVy8y9kYAZxI,5230
6
+ hyper_connections-0.1.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
+ hyper_connections-0.1.6.dist-info/licenses/LICENSE,sha256=E7RGS7kpJIStk5za_-4DVhWEAamf65EU0CNML25mq4c,1066
8
+ hyper_connections-0.1.6.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- hyper_connections/__init__.py,sha256=d2zNTka0Gp9vINu4U-RhgTJFBhsVrs1fne_15Zl0oOs,224
2
- hyper_connections/hyper_connections.py,sha256=uOSkFjpPECFiI_WUAXMxnsvYOYlEQXo_olzIL1Cc3sk,9934
3
- hyper_connections/hyper_connections_with_multi_branch_inputs.py,sha256=N89RSjkTbaVs46XDfPv4F770PF0kCzkMcpEuxaT5A5M,7733
4
- hyper_connections/hyper_connections_with_multi_input_streams.py,sha256=_IUkvbLdv6sj6Is2ayZ7APsMzW1DZS2mjAUznKAAVLU,11258
5
- hyper_connections-0.1.4.dist-info/METADATA,sha256=Yd38TnztrOxNHROCAJsxNFp1m7ogRkIHZuZ_MMjHPQY,5230
6
- hyper_connections-0.1.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
- hyper_connections-0.1.4.dist-info/licenses/LICENSE,sha256=E7RGS7kpJIStk5za_-4DVhWEAamf65EU0CNML25mq4c,1066
8
- hyper_connections-0.1.4.dist-info/RECORD,,