broccoli-ml 0.1.37__tar.gz → 0.1.39__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.
- {broccoli_ml-0.1.37 → broccoli_ml-0.1.39}/PKG-INFO +1 -1
- {broccoli_ml-0.1.37 → broccoli_ml-0.1.39}/broccoli/vit.py +37 -7
- {broccoli_ml-0.1.37 → broccoli_ml-0.1.39}/pyproject.toml +1 -1
- {broccoli_ml-0.1.37 → broccoli_ml-0.1.39}/LICENSE +0 -0
- {broccoli_ml-0.1.37 → broccoli_ml-0.1.39}/README.md +0 -0
- {broccoli_ml-0.1.37 → broccoli_ml-0.1.39}/broccoli/__init__.py +0 -0
- {broccoli_ml-0.1.37 → broccoli_ml-0.1.39}/broccoli/activation.py +0 -0
- {broccoli_ml-0.1.37 → broccoli_ml-0.1.39}/broccoli/assets/2025_resnet_imagenet_1k_pretrained_state_dict.pkl +0 -0
- {broccoli_ml-0.1.37 → broccoli_ml-0.1.39}/broccoli/assets/cifar100_eigenvectors_size_2.pt +0 -0
- {broccoli_ml-0.1.37 → broccoli_ml-0.1.39}/broccoli/assets/cifar100_eigenvectors_size_3.pt +0 -0
- {broccoli_ml-0.1.37 → broccoli_ml-0.1.39}/broccoli/cnn.py +0 -0
- {broccoli_ml-0.1.37 → broccoli_ml-0.1.39}/broccoli/eigenpatches.py +0 -0
- {broccoli_ml-0.1.37 → broccoli_ml-0.1.39}/broccoli/linear.py +0 -0
- {broccoli_ml-0.1.37 → broccoli_ml-0.1.39}/broccoli/rope.py +0 -0
- {broccoli_ml-0.1.37 → broccoli_ml-0.1.39}/broccoli/tensor.py +0 -0
- {broccoli_ml-0.1.37 → broccoli_ml-0.1.39}/broccoli/transformer.py +0 -0
- {broccoli_ml-0.1.37 → broccoli_ml-0.1.39}/broccoli/utils.py +0 -0
@@ -7,6 +7,17 @@ from .activation import ReLU, SquaredReLU, GELU, SwiGLU
|
|
7
7
|
from einops import einsum
|
8
8
|
from einops.layers.torch import Rearrange
|
9
9
|
import torch.nn as nn
|
10
|
+
import torch.nn.functional as F
|
11
|
+
|
12
|
+
|
13
|
+
class PadTensor(nn.Module):
|
14
|
+
def __init__(self, *args, **kwargs):
|
15
|
+
super().__init__()
|
16
|
+
self.args = args
|
17
|
+
self.kwargs = kwargs
|
18
|
+
|
19
|
+
def forward(self, x):
|
20
|
+
return F.pad(x, *self.args, **self.kwargs)
|
10
21
|
|
11
22
|
|
12
23
|
class SequencePool(nn.Module):
|
@@ -56,6 +67,7 @@ class CCTEncoder(nn.Module):
|
|
56
67
|
conv_pooling_kernel_size=3,
|
57
68
|
conv_pooling_kernel_stride=2,
|
58
69
|
conv_pooling_kernel_padding=1,
|
70
|
+
conv_dropout=0.0,
|
59
71
|
transformer_position_embedding="absolute", # absolute or relative
|
60
72
|
transformer_embedding_size=256,
|
61
73
|
transformer_layers=7,
|
@@ -110,7 +122,7 @@ class CCTEncoder(nn.Module):
|
|
110
122
|
conv_out_channels = transformer_embedding_size
|
111
123
|
elif conv_pooling_type == "concat":
|
112
124
|
conv_out_channels = int(
|
113
|
-
|
125
|
+
math.floor(transformer_embedding_size / (conv_pooling_kernel_size**2))
|
114
126
|
)
|
115
127
|
|
116
128
|
# This if block rhymes:
|
@@ -144,11 +156,16 @@ class CCTEncoder(nn.Module):
|
|
144
156
|
)
|
145
157
|
|
146
158
|
elif conv_pooling_type == "concat":
|
147
|
-
|
148
|
-
|
159
|
+
self.concatpool_activation = transformer_activation(
|
160
|
+
**transformer_activation_kwargs
|
149
161
|
)
|
162
|
+
|
163
|
+
concatpool_out_channels = conv_pooling_kernel_size**2 * conv_out_channels
|
164
|
+
|
150
165
|
if cnn_activation.__name__.endswith("GLU"):
|
151
|
-
|
166
|
+
cnn_activation_output_channels = concatpool_out_channels / 2
|
167
|
+
else:
|
168
|
+
cnn_activation_output_channels = concatpool_out_channels
|
152
169
|
|
153
170
|
self.pool = nn.Sequential(
|
154
171
|
*[
|
@@ -161,11 +178,24 @@ class CCTEncoder(nn.Module):
|
|
161
178
|
"N C H W -> N H W C"
|
162
179
|
),
|
163
180
|
self.cnn_activation,
|
164
|
-
|
181
|
+
nn.Dropout(conv_dropout),
|
182
|
+
Rearrange( # rearrange in case we're using XGLU activation
|
183
|
+
"N H W C -> N C H W"
|
184
|
+
),
|
185
|
+
nn.BatchNorm2d(cnn_activation_output_channels),
|
186
|
+
Rearrange( # rearrange in case we're using XGLU activation
|
187
|
+
"N C H W -> N (H W) C"
|
188
|
+
),
|
165
189
|
nn.Linear(
|
166
|
-
|
190
|
+
cnn_activation_output_channels,
|
191
|
+
(
|
192
|
+
2 * transformer_embedding_size * transformer_mlp_ratio
|
193
|
+
if transformer_activation.__name__.endswith("GLU")
|
194
|
+
else transformer_embedding_size * transformer_mlp_ratio
|
195
|
+
),
|
167
196
|
),
|
168
|
-
self.
|
197
|
+
self.concatpool_activation,
|
198
|
+
nn.Linear(transformer_embedding_size * transformer_mlp_ratio),
|
169
199
|
]
|
170
200
|
)
|
171
201
|
|
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
|