Equimo 0.4.5__tar.gz → 0.4.6a2__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.
- {equimo-0.4.5/src/Equimo.egg-info → equimo-0.4.6a2}/PKG-INFO +1 -1
- {equimo-0.4.5 → equimo-0.4.6a2}/pyproject.toml +1 -1
- {equimo-0.4.5 → equimo-0.4.6a2/src/Equimo.egg-info}/PKG-INFO +1 -1
- {equimo-0.4.5 → equimo-0.4.6a2}/src/Equimo.egg-info/SOURCES.txt +1 -0
- equimo-0.4.6a2/src/equimo/__init__.py +1 -0
- equimo-0.4.6a2/src/equimo/layers/wavelet.py +127 -0
- equimo-0.4.5/src/equimo/__init__.py +0 -1
- {equimo-0.4.5 → equimo-0.4.6a2}/LICENSE.md +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/README.md +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/setup.cfg +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/Equimo.egg-info/dependency_links.txt +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/Equimo.egg-info/requires.txt +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/Equimo.egg-info/top_level.txt +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/conversion/__init__.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/conversion/utils.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/experimental/__init__.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/experimental/text.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/io.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/layers/__init__.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/layers/activation.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/layers/attention.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/layers/convolution.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/layers/downsample.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/layers/dropout.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/layers/ffn.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/layers/generic.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/layers/mamba.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/layers/norm.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/layers/patch.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/layers/posemb.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/layers/sharing.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/layers/squeeze_excite.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/models/__init__.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/models/emamodel.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/models/fastervit.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/models/lowformer.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/models/mlla.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/models/partialformer.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/models/reduceformer.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/models/shvit.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/models/vit.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/models/vssd.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/ops/scan.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/src/equimo/utils.py +0 -0
- {equimo-0.4.5 → equimo-0.4.6a2}/tests/test_models.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.4.6a2"
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
from typing import Callable, Literal, Optional, Tuple
|
|
2
|
+
|
|
3
|
+
import equinox as eqx
|
|
4
|
+
import jax
|
|
5
|
+
import jax.numpy as jnp
|
|
6
|
+
from jaxtyping import Array, PRNGKeyArray
|
|
7
|
+
|
|
8
|
+
from equimo.utils import nearest_power_of_2_divisor
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _haar_1d(dtype=jnp.float32) -> Tuple[Array, Array]:
|
|
12
|
+
s2 = jnp.sqrt(jnp.array(2.0, dtype=dtype))
|
|
13
|
+
h0 = jnp.array([1.0, 1.0], dtype=dtype) / s2
|
|
14
|
+
h1 = jnp.array([-1.0, 1.0], dtype=dtype) / s2
|
|
15
|
+
return h0, h1
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _haar_2d_kernels(dtype=jnp.float32) -> Tuple[Array, Array, Array, Array]:
|
|
19
|
+
h0, h1 = _haar_1d(dtype)
|
|
20
|
+
|
|
21
|
+
kLL = jnp.outer(h0, h0) # low-low
|
|
22
|
+
kLH = jnp.outer(h0, h1) # low-high (horizontal detail)
|
|
23
|
+
kHL = jnp.outer(h1, h0) # high-low (vertical detail)
|
|
24
|
+
kHH = jnp.outer(h1, h1) # high-high (diagonal)
|
|
25
|
+
|
|
26
|
+
return kLL, kHL, kLH, kHH
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _depthwise_conv2d_stride2(x_chw: Array, k2x2: Array) -> Array:
|
|
30
|
+
"""
|
|
31
|
+
x_chw: (C, H, W)
|
|
32
|
+
k2x2: (2, 2) Haar kernel for one subband
|
|
33
|
+
returns: (C, H/2, W/2), using SAME padding + stride 2 depthwise conv
|
|
34
|
+
"""
|
|
35
|
+
C, _, _ = x_chw.shape
|
|
36
|
+
|
|
37
|
+
x = x_chw[None, ...] # (1, C, H, W) for lax.conv
|
|
38
|
+
|
|
39
|
+
k = jnp.tile(k2x2[None, None, :, :], (C, 1, 1, 1))
|
|
40
|
+
y = jax.lax.conv_general_dilated(
|
|
41
|
+
lhs=x,
|
|
42
|
+
rhs=k,
|
|
43
|
+
window_strides=(2, 2),
|
|
44
|
+
padding="SAME",
|
|
45
|
+
dimension_numbers=("NCHW", "OIHW", "NCHW"),
|
|
46
|
+
feature_group_count=C,
|
|
47
|
+
)
|
|
48
|
+
return y[0] # (C, H/2, W/2)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def haar_dwt_split(
|
|
52
|
+
x_chw: Array, dtype=jnp.float32
|
|
53
|
+
) -> Tuple[Array, Array, Array, Array]:
|
|
54
|
+
"""
|
|
55
|
+
Return (LL, HL, LH, HH), each (C, H/2, W/2)
|
|
56
|
+
"""
|
|
57
|
+
kLL, kHL, kLH, kHH = _haar_2d_kernels(dtype)
|
|
58
|
+
LL = _depthwise_conv2d_stride2(x_chw, kLL)
|
|
59
|
+
HL = _depthwise_conv2d_stride2(x_chw, kHL)
|
|
60
|
+
LH = _depthwise_conv2d_stride2(x_chw, kLH)
|
|
61
|
+
HH = _depthwise_conv2d_stride2(x_chw, kHH)
|
|
62
|
+
return LL, HL, LH, HH
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class HWDConv(eqx.Module):
|
|
66
|
+
mode: Literal["h_discard", "accurate"] = eqx.field(static=True)
|
|
67
|
+
|
|
68
|
+
pre_norm: eqx.nn.GroupNorm
|
|
69
|
+
proj: eqx.nn.Conv2d
|
|
70
|
+
act: Callable
|
|
71
|
+
dropout: eqx.nn.Dropout
|
|
72
|
+
|
|
73
|
+
def __init__(
|
|
74
|
+
self,
|
|
75
|
+
in_channels: int,
|
|
76
|
+
out_channels: int,
|
|
77
|
+
*,
|
|
78
|
+
kernel_size: int = 1,
|
|
79
|
+
use_bias: bool = False,
|
|
80
|
+
act: Callable = jax.nn.relu,
|
|
81
|
+
mode: Literal["h_discard", "accurate"] = "accurate",
|
|
82
|
+
dropout: float = 0.0,
|
|
83
|
+
key: PRNGKeyArray,
|
|
84
|
+
):
|
|
85
|
+
self.mode = mode
|
|
86
|
+
|
|
87
|
+
# Channels entering the projection (and thus the pre-norm)
|
|
88
|
+
channels_in = in_channels if mode == "h_discard" else 4 * in_channels
|
|
89
|
+
|
|
90
|
+
# Choose groups so no group crosses sub-band boundaries.
|
|
91
|
+
# For accurate mode: total_groups = 4 * groups_per_band, each band has groups_per_band groups.
|
|
92
|
+
# For h_discard mode: total_groups = groups_per_band (single band).
|
|
93
|
+
groups_per_band = nearest_power_of_2_divisor(in_channels, 32)
|
|
94
|
+
total_groups = groups_per_band if mode == "h_discard" else 4 * groups_per_band
|
|
95
|
+
|
|
96
|
+
self.pre_norm = eqx.nn.GroupNorm(channels=channels_in, groups=total_groups)
|
|
97
|
+
|
|
98
|
+
self.proj = eqx.nn.Conv2d(
|
|
99
|
+
channels_in,
|
|
100
|
+
out_channels,
|
|
101
|
+
kernel_size=kernel_size,
|
|
102
|
+
use_bias=use_bias,
|
|
103
|
+
padding="SAME",
|
|
104
|
+
key=key,
|
|
105
|
+
)
|
|
106
|
+
self.act = act
|
|
107
|
+
|
|
108
|
+
self.dropout = eqx.nn.Dropout(dropout)
|
|
109
|
+
|
|
110
|
+
def __call__(
|
|
111
|
+
self, x: Array, *, key: PRNGKeyArray, inference: bool = False
|
|
112
|
+
) -> Array:
|
|
113
|
+
LL, HL, LH, HH = haar_dwt_split(x, dtype=x.dtype) # each (C, H/2, W/2)
|
|
114
|
+
|
|
115
|
+
if self.mode == "h_discard":
|
|
116
|
+
y = LL # (C, H/2, W/2)
|
|
117
|
+
else:
|
|
118
|
+
y = jnp.concatenate([LL, HL, LH, HH], axis=0) # (4*C, H/2, W/2)
|
|
119
|
+
|
|
120
|
+
y = self.pre_norm(y)
|
|
121
|
+
|
|
122
|
+
y = self.proj(y) # (out_ch, H/2, W/2)
|
|
123
|
+
y = self.act(y)
|
|
124
|
+
|
|
125
|
+
y = self.dropout(y, inference=inference, key=key)
|
|
126
|
+
|
|
127
|
+
return y
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.4.5"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|