titans-pytorch 0.1.1__tar.gz → 0.1.2__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.4
2
2
  Name: titans-pytorch
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Titans
5
5
  Project-URL: Homepage, https://pypi.org/project/titans-pytorch/
6
6
  Project-URL: Repository, https://github.com/lucidrains/titans-pytorch
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "titans-pytorch"
3
- version = "0.1.1"
3
+ version = "0.1.2"
4
4
  description = "Titans"
5
5
  authors = [
6
6
  { name = "Phil Wang", email = "lucidrains@gmail.com" }
@@ -50,10 +50,12 @@ def test_titans_attn_memory():
50
50
 
51
51
  assert seq.shape == retrieved.shape
52
52
 
53
+ @pytest.mark.parametrize('seq_len', (1023, 17))
53
54
  @pytest.mark.parametrize('num_persist_mem_tokens', (0, 16))
54
55
  @pytest.mark.parametrize('num_longterm_mem_tokens', (0, 16))
55
56
  @pytest.mark.parametrize('neural_mem_gate_attn_output', (False, True))
56
57
  def test_mac(
58
+ seq_len,
57
59
  num_persist_mem_tokens,
58
60
  num_longterm_mem_tokens,
59
61
  neural_mem_gate_attn_output
@@ -70,13 +72,15 @@ def test_mac(
70
72
  neural_mem_gate_attn_output = neural_mem_gate_attn_output
71
73
  )
72
74
 
73
- x = torch.randint(0, 256, (1, 1023))
75
+ x = torch.randint(0, 256, (1, seq_len))
74
76
 
75
77
  logits = transformer(x)
76
- assert logits.shape == (1, 1023, 256)
78
+ assert logits.shape == (1, seq_len, 256)
77
79
 
80
+ @pytest.mark.parametrize('seq_len', (1023, 17))
78
81
  @pytest.mark.parametrize('sliding', (True, False))
79
82
  def test_flex(
83
+ seq_len,
80
84
  sliding
81
85
  ):
82
86
  if not (torch.cuda.is_available() and exists(flex_attention)):
@@ -91,7 +95,7 @@ def test_flex(
91
95
  sliding = sliding
92
96
  ).cuda()
93
97
 
94
- seq = torch.randn(1, 1019, 512).cuda()
98
+ seq = torch.randn(1, seq_len, 512).cuda()
95
99
 
96
100
  out_flex, _ = attn(seq)
97
101
  out_non_flex, _ = attn(seq, disable_flex_attn = True)
@@ -528,7 +528,8 @@ class MemoryAsContextTransformer(Module):
528
528
  filter_fn: Callable = min_p_filter,
529
529
  filter_kwargs: dict = dict(
530
530
  min_p = 0.1,
531
- )
531
+ ),
532
+ show_progress = True
532
533
  ):
533
534
  was_training = self.training
534
535
  self.eval()
@@ -536,7 +537,9 @@ class MemoryAsContextTransformer(Module):
536
537
  prompt_seq_len, out = prompt.shape[-1], prompt.clone()
537
538
  sample_num_times = max(0, seq_len - prompt_seq_len)
538
539
 
539
- for _ in tqdm.tqdm(range(sample_num_times)):
540
+ iter_wrap = tqdm.tqdm if show_progress else identity
541
+
542
+ for _ in iter_wrap(range(sample_num_times)):
540
543
  logits = self.forward(out, disable_flex_attn = True)
541
544
  logits = logits[:, -1]
542
545
 
File without changes
File without changes
File without changes
File without changes