broccoli-ml 0.3.0__py3-none-any.whl → 0.4.1__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.
- broccoli/vit.py +23 -22
- {broccoli_ml-0.3.0.dist-info → broccoli_ml-0.4.1.dist-info}/METADATA +1 -1
- {broccoli_ml-0.3.0.dist-info → broccoli_ml-0.4.1.dist-info}/RECORD +5 -5
- {broccoli_ml-0.3.0.dist-info → broccoli_ml-0.4.1.dist-info}/LICENSE +0 -0
- {broccoli_ml-0.3.0.dist-info → broccoli_ml-0.4.1.dist-info}/WHEEL +0 -0
broccoli/vit.py
CHANGED
@@ -49,7 +49,7 @@ class SequencePool(nn.Module):
|
|
49
49
|
return self.norm(projection)
|
50
50
|
|
51
51
|
|
52
|
-
class
|
52
|
+
class DCTEncoder(nn.Module):
|
53
53
|
"""
|
54
54
|
Based on the Compact Convolutional Transformer (CCT) of [Hasani et al. (2021)
|
55
55
|
*''Escaping the Big Data Paradigm with Compact Transformers''*](
|
@@ -66,23 +66,23 @@ class CCTEncoder(nn.Module):
|
|
66
66
|
minimum_cnn_out_channels=16,
|
67
67
|
cnn_kernel_size=3,
|
68
68
|
cnn_kernel_stride=1,
|
69
|
-
|
69
|
+
cnn_padding="same",
|
70
70
|
cnn_kernel_dilation=1,
|
71
71
|
cnn_kernel_groups=1,
|
72
|
-
cnn_activation: nn.Module =
|
72
|
+
cnn_activation: nn.Module = ReLU,
|
73
73
|
cnn_activation_kwargs: Optional[dict] = None,
|
74
74
|
cnn_dropout=0.0,
|
75
|
-
pooling_type="
|
75
|
+
pooling_type="concat", # maxpool or concat
|
76
76
|
pooling_kernel_size=3,
|
77
77
|
pooling_kernel_stride=2,
|
78
|
-
|
79
|
-
transformer_position_embedding="
|
78
|
+
pooling_padding=1,
|
79
|
+
transformer_position_embedding="relative", # absolute or relative
|
80
80
|
transformer_embedding_size=256,
|
81
81
|
transformer_layers=7,
|
82
82
|
transformer_heads=4,
|
83
83
|
transformer_mlp_ratio=2,
|
84
84
|
transformer_bos_tokens=4,
|
85
|
-
transformer_activation: nn.Module =
|
85
|
+
transformer_activation: nn.Module = SquaredReLU,
|
86
86
|
transformer_activation_kwargs: Optional[dict] = None,
|
87
87
|
mlp_dropout=0.0,
|
88
88
|
msa_dropout=0.1,
|
@@ -131,7 +131,7 @@ class CCTEncoder(nn.Module):
|
|
131
131
|
input_size,
|
132
132
|
kernel_size=cnn_kernel_size,
|
133
133
|
stride=cnn_kernel_stride,
|
134
|
-
padding=
|
134
|
+
padding=cnn_padding,
|
135
135
|
dilation=cnn_kernel_dilation,
|
136
136
|
)
|
137
137
|
|
@@ -142,7 +142,7 @@ class CCTEncoder(nn.Module):
|
|
142
142
|
cnn_output_size,
|
143
143
|
kernel_size=pooling_kernel_size,
|
144
144
|
stride=pooling_kernel_stride,
|
145
|
-
padding=
|
145
|
+
padding=pooling_padding,
|
146
146
|
dilation=1,
|
147
147
|
)
|
148
148
|
)
|
@@ -174,7 +174,7 @@ class CCTEncoder(nn.Module):
|
|
174
174
|
cnn_out_channels,
|
175
175
|
cnn_kernel_size,
|
176
176
|
stride=cnn_kernel_stride,
|
177
|
-
padding=
|
177
|
+
padding=cnn_padding,
|
178
178
|
dilation=cnn_kernel_dilation,
|
179
179
|
groups=cnn_kernel_groups,
|
180
180
|
bias=True,
|
@@ -212,7 +212,7 @@ class CCTEncoder(nn.Module):
|
|
212
212
|
maxpoolxd(
|
213
213
|
pooling_kernel_size,
|
214
214
|
stride=pooling_kernel_stride,
|
215
|
-
padding=
|
215
|
+
padding=pooling_padding,
|
216
216
|
),
|
217
217
|
Rearrange(
|
218
218
|
f"N C {spatial_dim_names} -> N ({spatial_dim_names}) C"
|
@@ -238,7 +238,7 @@ class CCTEncoder(nn.Module):
|
|
238
238
|
SpaceToDepth(
|
239
239
|
pooling_kernel_size,
|
240
240
|
stride=pooling_kernel_stride,
|
241
|
-
padding=
|
241
|
+
padding=pooling_padding,
|
242
242
|
spatial_dimensions=self.spatial_dimensions,
|
243
243
|
),
|
244
244
|
Rearrange( # for transformer
|
@@ -291,8 +291,9 @@ class CCTEncoder(nn.Module):
|
|
291
291
|
return self.encoder(x)
|
292
292
|
|
293
293
|
|
294
|
-
class
|
294
|
+
class DCT(nn.Module):
|
295
295
|
"""
|
296
|
+
Denoising convolutional transformer
|
296
297
|
Based on the Compact Convolutional Transformer (CCT) of [Hasani et al. (2021)
|
297
298
|
*''Escaping the Big Data Paradigm with Compact Transformers''*](
|
298
299
|
https://arxiv.org/abs/2104.05704). It's a convolutional neural network
|
@@ -306,23 +307,23 @@ class CCT(nn.Module):
|
|
306
307
|
minimum_cnn_out_channels=16,
|
307
308
|
cnn_kernel_size=3,
|
308
309
|
cnn_kernel_stride=1,
|
309
|
-
|
310
|
+
cnn_padding="same",
|
310
311
|
cnn_kernel_dilation=1,
|
311
312
|
cnn_kernel_groups=1,
|
312
|
-
cnn_activation: nn.Module =
|
313
|
+
cnn_activation: nn.Module = ReLU,
|
313
314
|
cnn_activation_kwargs: Optional[dict] = None,
|
314
315
|
cnn_dropout=0.0,
|
315
|
-
pooling_type="
|
316
|
+
pooling_type="concat", # maxpool or concat
|
316
317
|
pooling_kernel_size=3,
|
317
318
|
pooling_kernel_stride=2,
|
318
|
-
|
319
|
-
transformer_position_embedding="
|
319
|
+
pooling_padding=1,
|
320
|
+
transformer_position_embedding="relative", # absolute or relative
|
320
321
|
transformer_embedding_size=256,
|
321
322
|
transformer_layers=7,
|
322
323
|
transformer_heads=4,
|
323
324
|
transformer_mlp_ratio=2,
|
324
325
|
transformer_bos_tokens=4,
|
325
|
-
transformer_activation: nn.Module =
|
326
|
+
transformer_activation: nn.Module = SquaredReLU,
|
326
327
|
transformer_activation_kwargs: Optional[dict] = None,
|
327
328
|
mlp_dropout=0.0,
|
328
329
|
msa_dropout=0.1,
|
@@ -350,13 +351,13 @@ class CCT(nn.Module):
|
|
350
351
|
"SwiGLU": SwiGLU,
|
351
352
|
}[transformer_activation]
|
352
353
|
|
353
|
-
self.encoder =
|
354
|
+
self.encoder = DCTEncoder(
|
354
355
|
input_size=input_size,
|
355
356
|
cnn_in_channels=cnn_in_channels,
|
356
357
|
minimum_cnn_out_channels=minimum_cnn_out_channels,
|
357
358
|
cnn_kernel_size=cnn_kernel_size,
|
358
359
|
cnn_kernel_stride=cnn_kernel_stride,
|
359
|
-
|
360
|
+
cnn_padding=cnn_padding,
|
360
361
|
cnn_kernel_dilation=cnn_kernel_dilation,
|
361
362
|
cnn_kernel_groups=cnn_kernel_groups,
|
362
363
|
cnn_activation=cnn_activation,
|
@@ -365,7 +366,7 @@ class CCT(nn.Module):
|
|
365
366
|
pooling_type=pooling_type,
|
366
367
|
pooling_kernel_size=pooling_kernel_size,
|
367
368
|
pooling_kernel_stride=pooling_kernel_stride,
|
368
|
-
|
369
|
+
pooling_padding=pooling_padding,
|
369
370
|
transformer_position_embedding=transformer_position_embedding,
|
370
371
|
transformer_embedding_size=transformer_embedding_size,
|
371
372
|
transformer_layers=transformer_layers,
|
@@ -10,8 +10,8 @@ broccoli/rope.py,sha256=hw7kBPNR9GQXj4GxyIAffsGKPfcTPOFh8Bc7oEHtaZY,12108
|
|
10
10
|
broccoli/tensor.py,sha256=E2JK5mQwJf75e23-JGcDoT7QxQf89DJReUo2et1LhRY,1716
|
11
11
|
broccoli/transformer.py,sha256=23R58t3TLZMb9ulhCtQ3gXu0mPlfyPvLM8TaGOpaz58,16310
|
12
12
|
broccoli/utils.py,sha256=htq_hOsdhUhL0nJi9WkKiEYOjEoWqFpK5X49PtgTf-0,299
|
13
|
-
broccoli/vit.py,sha256=
|
14
|
-
broccoli_ml-0.
|
15
|
-
broccoli_ml-0.
|
16
|
-
broccoli_ml-0.
|
17
|
-
broccoli_ml-0.
|
13
|
+
broccoli/vit.py,sha256=d9nKhohlxpFbu3wzhNi53bYBNMUuShPfF6NXUAyDVA0,13778
|
14
|
+
broccoli_ml-0.4.1.dist-info/LICENSE,sha256=0BAzJE5BqQ7Iixp_AFdB2W1uO-HCRX-Qfun8PHt6yVM,1073
|
15
|
+
broccoli_ml-0.4.1.dist-info/METADATA,sha256=qwzzby85q__wYdKBEYBgyW5D7q3GMPoRwzeHPY6Mf6s,1256
|
16
|
+
broccoli_ml-0.4.1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
17
|
+
broccoli_ml-0.4.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|