broccoli-ml 0.1.37__tar.gz → 0.1.38__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: broccoli-ml
3
- Version: 0.1.37
3
+ Version: 0.1.38
4
4
  Summary: Some useful Pytorch models, circa 2025
5
5
  License: MIT
6
6
  Author: Nicholas Bailey
@@ -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):
@@ -110,7 +121,7 @@ class CCTEncoder(nn.Module):
110
121
  conv_out_channels = transformer_embedding_size
111
122
  elif conv_pooling_type == "concat":
112
123
  conv_out_channels = int(
113
- round(transformer_embedding_size / (conv_pooling_kernel_size**2))
124
+ math.floor(transformer_embedding_size / (conv_pooling_kernel_size**2))
114
125
  )
115
126
 
116
127
  # This if block rhymes:
@@ -144,11 +155,15 @@ class CCTEncoder(nn.Module):
144
155
  )
145
156
 
146
157
  elif conv_pooling_type == "concat":
147
- concatpool_activation_output_size = (
158
+ concatpool_activation_output_channels = (
148
159
  conv_pooling_kernel_size**2 * conv_out_channels
149
160
  )
150
161
  if cnn_activation.__name__.endswith("GLU"):
151
- concatpool_activation_output_size /= 2
162
+ concatpool_activation_output_channels /= 2
163
+
164
+ concatpool_padding = (
165
+ transformer_embedding_size - concatpool_activation_output_channels
166
+ )
152
167
 
153
168
  self.pool = nn.Sequential(
154
169
  *[
@@ -162,10 +177,7 @@ class CCTEncoder(nn.Module):
162
177
  ),
163
178
  self.cnn_activation,
164
179
  Rearrange("N H W C -> N (H W) C"),
165
- nn.Linear(
166
- concatpool_activation_output_size, transformer_embedding_size
167
- ),
168
- self.cnn_activation,
180
+ PadTensor((0, concatpool_padding)),
169
181
  ]
170
182
  )
171
183
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "broccoli-ml"
3
- version = "0.1.37"
3
+ version = "0.1.38"
4
4
  description = "Some useful Pytorch models, circa 2025"
5
5
  authors = [
6
6
  {name = "Nicholas Bailey"}
File without changes
File without changes