broccoli-ml 10.1.1__py3-none-any.whl → 10.2.0__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/transformer.py +17 -7
- {broccoli_ml-10.1.1.dist-info → broccoli_ml-10.2.0.dist-info}/METADATA +1 -1
- {broccoli_ml-10.1.1.dist-info → broccoli_ml-10.2.0.dist-info}/RECORD +5 -5
- {broccoli_ml-10.1.1.dist-info → broccoli_ml-10.2.0.dist-info}/LICENSE +0 -0
- {broccoli_ml-10.1.1.dist-info → broccoli_ml-10.2.0.dist-info}/WHEEL +0 -0
broccoli/transformer.py
CHANGED
|
@@ -22,12 +22,21 @@ except ImportError:
|
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
class LayerScale(nn.Module):
|
|
25
|
-
def __init__(self, dim, init_values=1e-4):
|
|
25
|
+
def __init__(self, dim, decay=False, init_values=1e-4):
|
|
26
26
|
super().__init__()
|
|
27
|
-
self.
|
|
27
|
+
self.decay = decay
|
|
28
|
+
if decay:
|
|
29
|
+
self.scale = nn.Parameter(init_values * torch.ones(dim))
|
|
30
|
+
self.nondecay_scale = None
|
|
31
|
+
else:
|
|
32
|
+
self.nondecay_scale = nn.Parameter(init_values * torch.ones(dim))
|
|
33
|
+
self.scale = None
|
|
28
34
|
|
|
29
35
|
def forward(self, x):
|
|
30
|
-
|
|
36
|
+
if self.decay:
|
|
37
|
+
return x * self.scale
|
|
38
|
+
else:
|
|
39
|
+
return x * self.nondecay_scale
|
|
31
40
|
|
|
32
41
|
|
|
33
42
|
def drop_path(
|
|
@@ -711,9 +720,10 @@ class TransformerEncoder(nn.Module):
|
|
|
711
720
|
self.return_utility_tokens = return_utility_tokens
|
|
712
721
|
|
|
713
722
|
if layerscale:
|
|
714
|
-
|
|
723
|
+
rope_and_ape = absolute_position_embedding and relative_position_embedding
|
|
724
|
+
self.position_layerscale = LayerScale(d_model, decay=rope_and_ape)
|
|
715
725
|
else:
|
|
716
|
-
self.
|
|
726
|
+
self.position_layerscale = None
|
|
717
727
|
|
|
718
728
|
# Initialise utility tokens with normal init, like usual Pytorch embeddings
|
|
719
729
|
if self._utility_tokens:
|
|
@@ -807,8 +817,8 @@ class TransformerEncoder(nn.Module):
|
|
|
807
817
|
0
|
|
808
818
|
) # to shape (1, seq_len) to broadcast over batch
|
|
809
819
|
)
|
|
810
|
-
if self.
|
|
811
|
-
position_embedding = self.
|
|
820
|
+
if self.position_layerscale is not None:
|
|
821
|
+
position_embedding = self.position_layerscale(position_embedding)
|
|
812
822
|
x += position_embedding
|
|
813
823
|
|
|
814
824
|
return x
|
|
@@ -4,10 +4,10 @@ broccoli/cnn.py,sha256=WjoPDSpe3ttwxCBNfCVRdaCHvbeZ7G-a5_i8fUsK_d8,4889
|
|
|
4
4
|
broccoli/linear.py,sha256=W-3aNpBjd_0xRyzbCKkmg4H1qmslQOIQhB-WDDay2nM,13125
|
|
5
5
|
broccoli/rope.py,sha256=GRqApBNmYCFaDak0WL1xE_BC5CTTYKQU_PBdeTcQcjc,12557
|
|
6
6
|
broccoli/tensor.py,sha256=um8mrxkYbvNDo-QvHlmJm8Aw6qcngOlUZPoAk_PMReA,4480
|
|
7
|
-
broccoli/transformer.py,sha256=
|
|
7
|
+
broccoli/transformer.py,sha256=8Zxz_4iElP42uMeUNdh3hNTMPO-T095A9UF0w5zzBVc,28414
|
|
8
8
|
broccoli/utils.py,sha256=oOWzn6dJ5nC_9r4zq0emmfmaYACJXJNFS48AOpW2jqc,358
|
|
9
9
|
broccoli/vit.py,sha256=EGbQb-atuzG3JAx7kdTaJEbWvQR-4XgyYvwjKkN5C38,22612
|
|
10
|
-
broccoli_ml-10.
|
|
11
|
-
broccoli_ml-10.
|
|
12
|
-
broccoli_ml-10.
|
|
13
|
-
broccoli_ml-10.
|
|
10
|
+
broccoli_ml-10.2.0.dist-info/LICENSE,sha256=0BAzJE5BqQ7Iixp_AFdB2W1uO-HCRX-Qfun8PHt6yVM,1073
|
|
11
|
+
broccoli_ml-10.2.0.dist-info/METADATA,sha256=u6kO1kOyY9spuimYO-dWlHLJLaPJjnVBG7GpJ4gc7Xk,1369
|
|
12
|
+
broccoli_ml-10.2.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
13
|
+
broccoli_ml-10.2.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|