x-transformers 2.11.2__tar.gz → 2.11.4__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.
Potentially problematic release.
This version of x-transformers might be problematic. Click here for more details.
- {x_transformers-2.11.2 → x_transformers-2.11.4}/PKG-INFO +1 -1
- {x_transformers-2.11.2 → x_transformers-2.11.4}/pyproject.toml +1 -1
- {x_transformers-2.11.2 → x_transformers-2.11.4}/tests/test_x_transformers.py +32 -6
- {x_transformers-2.11.2 → x_transformers-2.11.4}/train_free.py +1 -1
- {x_transformers-2.11.2 → x_transformers-2.11.4}/x_transformers/free_transformer.py +41 -21
- {x_transformers-2.11.2 → x_transformers-2.11.4}/.github/FUNDING.yml +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/.github/workflows/python-publish.yml +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/.github/workflows/python-test.yaml +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/.gitignore +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/LICENSE +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/README.md +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/data/README.md +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/data/enwik8.gz +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/all-attention.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/attention-on-attention.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/cosine-sim-attention.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/deepnorm.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/dynamic-pos-bias-linear.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/dynamic-pos-bias-log.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/dynamic-pos-bias-sinusoidal.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/dynamic-pos-bias.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/enhanced-recurrence.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/fcm.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/ffglu.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/flash-attention.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/gate_values.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/gating.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/length-extrapolation-scale.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/macaron-1.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/macaron-2.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/memory-transformer.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/normformer.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/pia.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/qknorm-analysis.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/resi_dual.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/residual_attn.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/rezero.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/rotary.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/sandwich-2.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/sandwich.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/sandwich_norm.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/scalenorm.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/talking-heads.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/topk-attention.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/images/xval.png +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/train_belief_state.py +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/train_copy.py +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/train_entropy_tokenizer.py +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/train_enwik8.py +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/train_gpt_vae.py +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/train_length_extrapolate.py +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/train_parity.py +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/train_with_muon.py +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/x_transformers/__init__.py +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/x_transformers/attend.py +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/x_transformers/autoregressive_wrapper.py +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/x_transformers/belief_state_wrapper.py +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/x_transformers/continuous.py +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/x_transformers/dpo.py +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/x_transformers/entropy_based_tokenizer.py +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/x_transformers/gpt_vae.py +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/x_transformers/multi_input.py +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/x_transformers/neo_mlp.py +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/x_transformers/nonautoregressive_wrapper.py +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/x_transformers/up_wrapper.py +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/x_transformers/x_transformers.py +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/x_transformers/xl_autoregressive_wrapper.py +0 -0
- {x_transformers-2.11.2 → x_transformers-2.11.4}/x_transformers/xval.py +0 -0
|
@@ -586,12 +586,12 @@ def test_cross_attn_rotary(
|
|
|
586
586
|
context_pos = torch.arange(128) if cross_attn_rotary else None
|
|
587
587
|
|
|
588
588
|
embed = model(
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
589
|
+
x = x,
|
|
590
|
+
mask = mask,
|
|
591
|
+
context = context,
|
|
592
|
+
pos = pos,
|
|
593
|
+
context_pos = context_pos,
|
|
594
|
+
context_mask = context_mask
|
|
595
595
|
)
|
|
596
596
|
|
|
597
597
|
@param('tanh', (True, False))
|
|
@@ -1408,3 +1408,29 @@ def test_attn_negative_weights(
|
|
|
1408
1408
|
x = torch.randint(0, 256, (1, 10))
|
|
1409
1409
|
|
|
1410
1410
|
logits = model(x)
|
|
1411
|
+
|
|
1412
|
+
@param('per_token_latents', (False, True))
|
|
1413
|
+
def test_free(
|
|
1414
|
+
per_token_latents
|
|
1415
|
+
):
|
|
1416
|
+
from x_transformers.free_transformer import FreeTransformer
|
|
1417
|
+
|
|
1418
|
+
model = FreeTransformer(
|
|
1419
|
+
num_tokens = 256,
|
|
1420
|
+
max_seq_len = 1024,
|
|
1421
|
+
dim = 512,
|
|
1422
|
+
heads = 8,
|
|
1423
|
+
dec_head_depth = 4,
|
|
1424
|
+
dec_tail_depth = 4,
|
|
1425
|
+
enc_depth = 3,
|
|
1426
|
+
kl_loss_weight = 1.,
|
|
1427
|
+
per_token_latents = per_token_latents,
|
|
1428
|
+
latent_bits = 8
|
|
1429
|
+
)
|
|
1430
|
+
|
|
1431
|
+
seq = torch.randint(0, 256, (1, 1024))
|
|
1432
|
+
|
|
1433
|
+
loss, (ar_loss, aux_loss) = model(seq, return_all_losses = True)
|
|
1434
|
+
loss.backward()
|
|
1435
|
+
|
|
1436
|
+
assert aux_loss.numel() == 1
|
|
@@ -54,11 +54,11 @@ model = FreeTransformer(
|
|
|
54
54
|
max_seq_len = SEQ_LEN,
|
|
55
55
|
dim = 512,
|
|
56
56
|
heads = 8,
|
|
57
|
-
rotary_pos_emb = True,
|
|
58
57
|
dec_head_depth = 4,
|
|
59
58
|
dec_tail_depth = 4,
|
|
60
59
|
enc_depth = 3,
|
|
61
60
|
kl_loss_weight = 1.,
|
|
61
|
+
per_token_latents = True,
|
|
62
62
|
kl_loss_threshold = NAT,
|
|
63
63
|
latent_bits = LATENT_BITS
|
|
64
64
|
).cuda()
|
|
@@ -128,19 +128,19 @@ class FreeTransformer(Module):
|
|
|
128
128
|
dim,
|
|
129
129
|
dec_head_depth,
|
|
130
130
|
dec_tail_depth,
|
|
131
|
-
enc_depth,
|
|
132
131
|
max_seq_len,
|
|
132
|
+
enc_depth = 1,
|
|
133
133
|
dim_latent = None,
|
|
134
134
|
attn_dim_head = 64,
|
|
135
135
|
heads = 8,
|
|
136
136
|
latent_bits = 16,
|
|
137
|
+
per_token_latents = True, # they use a latent per token in the sequence, instead of one for entire sequence, iiuc
|
|
137
138
|
kl_loss_threshold = NAT,
|
|
138
139
|
binary_mapper_kwargs: dict = dict(),
|
|
139
140
|
enc_kwargs: dict = dict(),
|
|
140
141
|
dec_kwargs: dict = dict(),
|
|
141
142
|
kl_loss_weight = 1.,
|
|
142
143
|
pad_id = -1,
|
|
143
|
-
encoder: Module | None = None,
|
|
144
144
|
**kwargs
|
|
145
145
|
):
|
|
146
146
|
super().__init__()
|
|
@@ -150,33 +150,30 @@ class FreeTransformer(Module):
|
|
|
150
150
|
|
|
151
151
|
self.token_unembed = nn.Linear(dim, num_tokens, bias = False)
|
|
152
152
|
|
|
153
|
-
|
|
154
|
-
encoder = Encoder(
|
|
155
|
-
dim = dim,
|
|
156
|
-
depth = enc_depth,
|
|
157
|
-
attn_dim_head = attn_dim_head,
|
|
158
|
-
heads = heads,
|
|
159
|
-
**kwargs,
|
|
160
|
-
**enc_kwargs
|
|
161
|
-
)
|
|
153
|
+
self.query_token_for_latents = nn.Parameter(torch.randn(dim) * 1e-2)
|
|
162
154
|
|
|
163
|
-
self.
|
|
155
|
+
self.per_token_latents = per_token_latents
|
|
164
156
|
|
|
165
|
-
self.
|
|
166
|
-
|
|
167
|
-
|
|
157
|
+
self.encoder = Encoder(
|
|
158
|
+
dim = dim,
|
|
159
|
+
depth = enc_depth,
|
|
160
|
+
attn_dim_head = attn_dim_head,
|
|
161
|
+
heads = heads,
|
|
162
|
+
only_cross = True,
|
|
163
|
+
cross_attend = True,
|
|
164
|
+
**kwargs,
|
|
165
|
+
**enc_kwargs
|
|
168
166
|
)
|
|
169
167
|
|
|
168
|
+
self.to_latent_bit_logits = nn.Linear(dim, latent_bits, bias = False)
|
|
169
|
+
|
|
170
170
|
self.binary_mapper = BinaryMapper(
|
|
171
171
|
latent_bits,
|
|
172
172
|
kl_loss_threshold,
|
|
173
173
|
**binary_mapper_kwargs
|
|
174
174
|
)
|
|
175
175
|
|
|
176
|
-
self.from_latent_to_condition = nn.
|
|
177
|
-
nn.Linear(2 ** latent_bits, dim, bias = False),
|
|
178
|
-
Rearrange('b d -> b 1 d')
|
|
179
|
-
)
|
|
176
|
+
self.from_latent_to_condition = nn.Linear(self.binary_mapper.num_codes, dim, bias = False)
|
|
180
177
|
|
|
181
178
|
self.decoder_head = Decoder(
|
|
182
179
|
dim = dim,
|
|
@@ -208,11 +205,34 @@ class FreeTransformer(Module):
|
|
|
208
205
|
|
|
209
206
|
def encode_to_latents(
|
|
210
207
|
self,
|
|
211
|
-
|
|
208
|
+
decoder_head_embeds,
|
|
212
209
|
mask = None,
|
|
213
210
|
return_kl_loss = False
|
|
214
211
|
):
|
|
215
|
-
|
|
212
|
+
batch, seq_len, device = *decoder_head_embeds.shape[:2], decoder_head_embeds.device
|
|
213
|
+
|
|
214
|
+
query_tokens = repeat(self.query_token_for_latents, 'd -> b 1 d', b = batch)
|
|
215
|
+
|
|
216
|
+
encoder_kwargs = dict()
|
|
217
|
+
|
|
218
|
+
# handle the interesting per query token latents, as in the paper
|
|
219
|
+
|
|
220
|
+
if self.per_token_latents:
|
|
221
|
+
query_tokens = repeat(query_tokens, 'b 1 d -> b n d', n = seq_len)
|
|
222
|
+
|
|
223
|
+
rotary_pos = torch.arange(seq_len, device = device)
|
|
224
|
+
|
|
225
|
+
encoder_kwargs.update(
|
|
226
|
+
pos = rotary_pos,
|
|
227
|
+
context_pos = rotary_pos
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
pooled = self.encoder(
|
|
231
|
+
query_tokens,
|
|
232
|
+
context = decoder_head_embeds,
|
|
233
|
+
context_mask = mask,
|
|
234
|
+
**encoder_kwargs
|
|
235
|
+
)
|
|
216
236
|
|
|
217
237
|
bit_logits = self.to_latent_bit_logits(pooled)
|
|
218
238
|
|
|
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
|
|
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
|
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|