x-transformers 2.32.3__tar.gz → 2.32.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.
- {x_transformers-2.32.3 → x_transformers-2.32.4}/PKG-INFO +1 -1
- {x_transformers-2.32.3 → x_transformers-2.32.4}/pyproject.toml +1 -1
- {x_transformers-2.32.3 → x_transformers-2.32.4}/x_transformers/__init__.py +0 -6
- {x_transformers-2.32.3 → x_transformers-2.32.4}/x_transformers/x_transformers.py +20 -3
- {x_transformers-2.32.3 → x_transformers-2.32.4}/.gitignore +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/LICENSE +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/README.md +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/data/README.md +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/experiments/lightmtp_pathstar/README.md +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/x_transformers/attend.py +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/x_transformers/autoregressive_wrapper.py +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/x_transformers/belief_state_wrapper.py +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/x_transformers/causal_seq_cond.py +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/x_transformers/continuous.py +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/x_transformers/continuous_autoencoder.py +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/x_transformers/discover_wrapper.py +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/x_transformers/dpo.py +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/x_transformers/entropy_based_tokenizer.py +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/x_transformers/free_transformer.py +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/x_transformers/full_bandwidth.py +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/x_transformers/gpt_lejepa.py +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/x_transformers/gpt_vae.py +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/x_transformers/multi_input.py +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/x_transformers/neo_mlp.py +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/x_transformers/next_latent_wrapper.py +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/x_transformers/nonautoregressive_wrapper.py +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/x_transformers/paged_attention.py +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/x_transformers/recirculation.py +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/x_transformers/up_wrapper.py +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/x_transformers/xl_autoregressive_wrapper.py +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/x_transformers/xm_latent_decoder.py +0 -0
- {x_transformers-2.32.3 → x_transformers-2.32.4}/x_transformers/xval.py +0 -0
|
@@ -44,12 +44,6 @@ from x_transformers.neo_mlp import (
|
|
|
44
44
|
NeoMLP
|
|
45
45
|
)
|
|
46
46
|
|
|
47
|
-
from x_transformers.paged_attention import (
|
|
48
|
-
PagedAttention,
|
|
49
|
-
PagedKVCache,
|
|
50
|
-
paged_attention
|
|
51
|
-
)
|
|
52
|
-
|
|
53
47
|
from x_transformers.causal_seq_cond import (
|
|
54
48
|
DSConvConditioner,
|
|
55
49
|
EMAConditioner,
|
|
@@ -1344,10 +1344,12 @@ class MVSplitResidualUpdate(Module):
|
|
|
1344
1344
|
init_alpha = 0.,
|
|
1345
1345
|
init_beta = 0.03,
|
|
1346
1346
|
learned = False,
|
|
1347
|
+
causal = False,
|
|
1347
1348
|
**kwargs
|
|
1348
1349
|
):
|
|
1349
1350
|
super().__init__()
|
|
1350
1351
|
self.learned = learned
|
|
1352
|
+
self.causal = causal
|
|
1351
1353
|
|
|
1352
1354
|
if learned:
|
|
1353
1355
|
self.to_alpha = nn.Linear(dim, dim)
|
|
@@ -1365,9 +1367,20 @@ class MVSplitResidualUpdate(Module):
|
|
|
1365
1367
|
def prepare(self, residual):
|
|
1366
1368
|
return residual, residual, dict()
|
|
1367
1369
|
|
|
1370
|
+
def seq_mean(self, t, mask = None):
|
|
1371
|
+
if not self.causal:
|
|
1372
|
+
return masked_mean(t, mask = mask, dim = -2, keepdim = True)
|
|
1373
|
+
|
|
1374
|
+
# causal prefix mean - each token only averages over itself and the past
|
|
1375
|
+
|
|
1376
|
+
mask = default(mask, lambda: torch.ones(t.shape[:-1], device = t.device, dtype = torch.bool))
|
|
1377
|
+
mask = rearrange(mask, 'b n -> b n 1')
|
|
1378
|
+
|
|
1379
|
+
return (t * mask).cumsum(dim = -2) / mask.cumsum(dim = -2).clamp(min = 1)
|
|
1380
|
+
|
|
1368
1381
|
def forward(self, x, residual, mask = None, **kwargs):
|
|
1369
|
-
mean_x =
|
|
1370
|
-
mean_residual =
|
|
1382
|
+
mean_x = self.seq_mean(x, mask = mask)
|
|
1383
|
+
mean_residual = self.seq_mean(residual, mask = mask)
|
|
1371
1384
|
|
|
1372
1385
|
alpha = self.to_alpha(mean_x) if self.learned else self.alpha
|
|
1373
1386
|
beta = self.to_beta(mean_x) if self.learned else self.beta
|
|
@@ -3554,7 +3567,7 @@ class AttentionLayers(Module):
|
|
|
3554
3567
|
elif orthog_residual:
|
|
3555
3568
|
residual_fn = OrthogonalResidualUpdate
|
|
3556
3569
|
elif mv_split_residual:
|
|
3557
|
-
residual_fn = MVSplitResidualUpdate
|
|
3570
|
+
residual_fn = partial(MVSplitResidualUpdate, causal = causal)
|
|
3558
3571
|
else:
|
|
3559
3572
|
residual_fn = Residual
|
|
3560
3573
|
|
|
@@ -3617,6 +3630,10 @@ class AttentionLayers(Module):
|
|
|
3617
3630
|
|
|
3618
3631
|
self.can_cache_kv = all([module.can_cache_kv for module in self.modules() if isinstance(module, Attention)])
|
|
3619
3632
|
|
|
3633
|
+
# causal mv split residual needs the prefix mean, which is not part of the kv cache
|
|
3634
|
+
|
|
3635
|
+
self.can_cache_kv &= not (mv_split_residual and causal)
|
|
3636
|
+
|
|
3620
3637
|
def attn_qk_clip_(
|
|
3621
3638
|
self,
|
|
3622
3639
|
intermediates: LayerIntermediates,
|
|
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
|