broccoli-ml 0.13.0__tar.gz → 0.13.1__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.13.0 → broccoli_ml-0.13.1}/PKG-INFO +1 -1
- {broccoli_ml-0.13.0 → broccoli_ml-0.13.1}/broccoli/linear.py +2 -1
- {broccoli_ml-0.13.0 → broccoli_ml-0.13.1}/broccoli/transformer.py +2 -2
- {broccoli_ml-0.13.0 → broccoli_ml-0.13.1}/broccoli/vit.py +8 -7
- {broccoli_ml-0.13.0 → broccoli_ml-0.13.1}/pyproject.toml +1 -1
- {broccoli_ml-0.13.0 → broccoli_ml-0.13.1}/LICENSE +0 -0
- {broccoli_ml-0.13.0 → broccoli_ml-0.13.1}/README.md +0 -0
- {broccoli_ml-0.13.0 → broccoli_ml-0.13.1}/broccoli/__init__.py +0 -0
- {broccoli_ml-0.13.0 → broccoli_ml-0.13.1}/broccoli/activation.py +0 -0
- {broccoli_ml-0.13.0 → broccoli_ml-0.13.1}/broccoli/assets/2025_resnet_imagenet_1k_pretrained_state_dict.pkl +0 -0
- {broccoli_ml-0.13.0 → broccoli_ml-0.13.1}/broccoli/assets/cifar100_eigenvectors_size_2.pt +0 -0
- {broccoli_ml-0.13.0 → broccoli_ml-0.13.1}/broccoli/assets/cifar100_eigenvectors_size_3.pt +0 -0
- {broccoli_ml-0.13.0 → broccoli_ml-0.13.1}/broccoli/cnn.py +0 -0
- {broccoli_ml-0.13.0 → broccoli_ml-0.13.1}/broccoli/eigenpatches.py +0 -0
- {broccoli_ml-0.13.0 → broccoli_ml-0.13.1}/broccoli/rope.py +0 -0
- {broccoli_ml-0.13.0 → broccoli_ml-0.13.1}/broccoli/tensor.py +0 -0
- {broccoli_ml-0.13.0 → broccoli_ml-0.13.1}/broccoli/utils.py +0 -0
@@ -10,7 +10,8 @@ from .tensor import SigmaReparamTensor
|
|
10
10
|
|
11
11
|
class SpectralNormLinear(nn.Module):
|
12
12
|
"""
|
13
|
-
|
13
|
+
Inspired by Apple's Spectral Normed Linear Layers
|
14
|
+
(https://github.com/apple/ml-sigma-reparam)
|
14
15
|
"""
|
15
16
|
|
16
17
|
def __init__(self, in_features: int, out_features: int, bias: bool = True):
|
@@ -222,7 +222,7 @@ class MHAttention(nn.Module):
|
|
222
222
|
return self.out_proj(output_without_heads)
|
223
223
|
|
224
224
|
|
225
|
-
class
|
225
|
+
class FeedforwardBlock(nn.Module):
|
226
226
|
"""
|
227
227
|
...
|
228
228
|
"""
|
@@ -324,7 +324,7 @@ class TransformerBlock(nn.Module):
|
|
324
324
|
)
|
325
325
|
|
326
326
|
# Submodules for the feedforward process
|
327
|
-
self.ff =
|
327
|
+
self.ff = FeedforwardBlock(
|
328
328
|
d_model,
|
329
329
|
mlp_ratio,
|
330
330
|
d_model,
|
@@ -1,9 +1,10 @@
|
|
1
1
|
import math
|
2
2
|
from typing import Optional
|
3
3
|
|
4
|
-
from .transformer import TransformerEncoder,
|
4
|
+
from .transformer import TransformerEncoder, FeedforwardBlock
|
5
5
|
from .cnn import SpaceToDepth, calculate_output_spatial_size, spatial_tuple
|
6
6
|
from .activation import ReLU, SquaredReLU, GELU, SwiGLU
|
7
|
+
from .linear import SpectralNormLinear
|
7
8
|
from einops import einsum
|
8
9
|
from einops.layers.torch import Rearrange
|
9
10
|
import torch.nn as nn
|
@@ -103,6 +104,7 @@ class ViTEncoder(nn.Module):
|
|
103
104
|
def __init__(
|
104
105
|
self,
|
105
106
|
input_size=(32, 32),
|
107
|
+
initial_batch_norm=True,
|
106
108
|
cnn=True,
|
107
109
|
cnn_in_channels=3,
|
108
110
|
cnn_out_channels=16,
|
@@ -132,7 +134,6 @@ class ViTEncoder(nn.Module):
|
|
132
134
|
transformer_msa_dropout=0.1,
|
133
135
|
transformer_stochastic_depth=0.1,
|
134
136
|
linear_module=nn.Linear,
|
135
|
-
initial_batch_norm=True,
|
136
137
|
):
|
137
138
|
super().__init__()
|
138
139
|
|
@@ -294,7 +295,7 @@ class ViTEncoder(nn.Module):
|
|
294
295
|
|
295
296
|
if intermediate_feedforward_layer:
|
296
297
|
self.pooling_channels_padding = nn.Identity()
|
297
|
-
self.intermediate_feedforward_layer =
|
298
|
+
self.intermediate_feedforward_layer = FeedforwardBlock(
|
298
299
|
pooling_out_channels,
|
299
300
|
transformer_mlp_ratio,
|
300
301
|
transformer_embedding_size,
|
@@ -349,6 +350,8 @@ class ViT(nn.Module):
|
|
349
350
|
def __init__(
|
350
351
|
self,
|
351
352
|
input_size=(32, 32),
|
353
|
+
image_classes=100,
|
354
|
+
initial_batch_norm=True,
|
352
355
|
cnn=True,
|
353
356
|
cnn_in_channels=3,
|
354
357
|
cnn_out_channels=16,
|
@@ -378,9 +381,7 @@ class ViT(nn.Module):
|
|
378
381
|
transformer_msa_dropout=0.1,
|
379
382
|
transformer_stochastic_depth=0.1,
|
380
383
|
batch_norm_outputs=True,
|
381
|
-
|
382
|
-
linear_module=nn.Linear,
|
383
|
-
image_classes=100,
|
384
|
+
linear_module=SpectralNormLinear,
|
384
385
|
head=SequencePoolClassificationHead,
|
385
386
|
):
|
386
387
|
|
@@ -404,6 +405,7 @@ class ViT(nn.Module):
|
|
404
405
|
|
405
406
|
self.encoder = ViTEncoder(
|
406
407
|
input_size=input_size,
|
408
|
+
initial_batch_norm=initial_batch_norm,
|
407
409
|
cnn=cnn,
|
408
410
|
cnn_in_channels=cnn_in_channels,
|
409
411
|
cnn_out_channels=cnn_out_channels,
|
@@ -433,7 +435,6 @@ class ViT(nn.Module):
|
|
433
435
|
transformer_msa_dropout=transformer_msa_dropout,
|
434
436
|
transformer_stochastic_depth=transformer_stochastic_depth,
|
435
437
|
linear_module=linear_module,
|
436
|
-
initial_batch_norm=initial_batch_norm,
|
437
438
|
)
|
438
439
|
|
439
440
|
self.pool = head(
|
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
|