sae-lens 6.13.0__py3-none-any.whl → 6.13.1__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.
sae_lens/__init__.py CHANGED
@@ -1,5 +1,5 @@
1
1
  # ruff: noqa: E402
2
- __version__ = "6.13.0"
2
+ __version__ = "6.13.1"
3
3
 
4
4
  import logging
5
5
 
@@ -68,7 +68,7 @@ def concat_and_batch_sequences(
68
68
  ) -> Generator[torch.Tensor, None, None]:
69
69
  """
70
70
  Generator to concat token sequences together from the tokens_interator, yielding
71
- batches of size `context_size`.
71
+ sequences of size `context_size`. Batching across the batch dimension is handled by the caller.
72
72
 
73
73
  Args:
74
74
  tokens_iterator: An iterator which returns a 1D tensors of tokens
@@ -76,13 +76,28 @@ def concat_and_batch_sequences(
76
76
  begin_batch_token_id: If provided, this token will be at position 0 of each batch
77
77
  begin_sequence_token_id: If provided, this token will be the first token of each sequence
78
78
  sequence_separator_token_id: If provided, this token will be inserted between concatenated sequences
79
- disable_concat_sequences: If True, disable concatenating sequences and ignore sequences shorter than context_size
79
+ disable_concat_sequences: If True, disable concatenating sequences and ignore sequences shorter than context_size (including BOS token if present)
80
80
  max_batches: If not provided, the iterator will be run to completion.
81
81
  """
82
82
  if disable_concat_sequences:
83
- for tokens in tokens_iterator:
84
- if len(tokens) >= context_size:
85
- yield tokens[:context_size]
83
+ if begin_batch_token_id and not begin_sequence_token_id:
84
+ begin_sequence_token_id = begin_batch_token_id
85
+ for sequence in tokens_iterator:
86
+ if (
87
+ begin_sequence_token_id is not None
88
+ and sequence[0] != begin_sequence_token_id
89
+ and len(sequence) >= context_size - 1
90
+ ):
91
+ begin_sequence_token_id_tensor = torch.tensor(
92
+ [begin_sequence_token_id],
93
+ dtype=torch.long,
94
+ device=sequence.device,
95
+ )
96
+ sequence = torch.cat(
97
+ [begin_sequence_token_id_tensor, sequence[: context_size - 1]]
98
+ )
99
+ if len(sequence) >= context_size:
100
+ yield sequence[:context_size]
86
101
  return
87
102
 
88
103
  batch: torch.Tensor | None = None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sae-lens
3
- Version: 6.13.0
3
+ Version: 6.13.1
4
4
  Summary: Training and Analyzing Sparse Autoencoders (SAEs)
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -1,4 +1,4 @@
1
- sae_lens/__init__.py,sha256=6cL-2l4CIzZJfgyRP5I90zu2Tty196wOgFg1JGlQd1c,3589
1
+ sae_lens/__init__.py,sha256=xuL4qrRobR4wwhmiepHzhHKlkGxn8h9D1QSNcg82CL4,3589
2
2
  sae_lens/analysis/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  sae_lens/analysis/hooked_sae_transformer.py,sha256=vRu6JseH1lZaEeILD5bEkQEQ1wYHHDcxD-f2olKmE9Y,14275
4
4
  sae_lens/analysis/neuronpedia_integration.py,sha256=Gx1W7hUBEuMoasNcnOnZ1wmqbXDd1pSZ1nqKEya1HQc,4962
@@ -22,7 +22,7 @@ sae_lens/saes/sae.py,sha256=nuII6ZmaVtJWhPjyhasHQyiv_Wj-zdAtRQqJRYbVBQs,38274
22
22
  sae_lens/saes/standard_sae.py,sha256=9UqYyYtQuThYxXKNaDjYcyowpOx2-7cShG-TeUP6JCQ,5940
23
23
  sae_lens/saes/topk_sae.py,sha256=pM26I9uDeh_ZWx0HXUyPVFfEV2pfuRJmAPNWR5pmRhY,17615
24
24
  sae_lens/saes/transcoder.py,sha256=BfLSbTYVNZh-ruGxseZiZJ_acEL6_7QyTdfqUr0lDOg,12156
25
- sae_lens/tokenization_and_batching.py,sha256=jV7Rx5wHHcYMmexFhvbSk2q5R0gYBjtKoJKpowAgMEo,4665
25
+ sae_lens/tokenization_and_batching.py,sha256=D_o7cXvRqhT89H3wNzoRymNALNE6eHojBWLdXOUwUGE,5438
26
26
  sae_lens/training/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
27
  sae_lens/training/activation_scaler.py,sha256=seEE-2Qd2JMHxqgnsNWPt-DGtYGZxWPnOwCGuVNSOtI,1719
28
28
  sae_lens/training/activations_store.py,sha256=2EUY2abqpT5El3T95sypM_JRDgiKL3VeT73U9SQIFGY,32903
@@ -33,7 +33,7 @@ sae_lens/training/types.py,sha256=1FpLx_Doda9vZpmfm-x1e8wGBYpyhe9Kpb_JuM5nIFM,90
33
33
  sae_lens/training/upload_saes_to_huggingface.py,sha256=r_WzI1zLtGZ5TzAxuG3xa_8T09j3zXJrWd_vzPsPGkQ,4469
34
34
  sae_lens/tutorial/tsea.py,sha256=fd1am_XXsf2KMbByDapJo-2qlxduKaa62Z2qcQZ3QKU,18145
35
35
  sae_lens/util.py,sha256=lW7fBn_b8quvRYlen9PUmB7km60YhKyjmuelB1f6KzQ,2253
36
- sae_lens-6.13.0.dist-info/METADATA,sha256=rqSlR_xjf3fqZga4OHpNtrhKzaA4tIrobj-e6yq8sbA,5318
37
- sae_lens-6.13.0.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
38
- sae_lens-6.13.0.dist-info/licenses/LICENSE,sha256=DW6e-hDosiu4CfW0-imI57sV1I5f9UEslpviNQcOAKs,1069
39
- sae_lens-6.13.0.dist-info/RECORD,,
36
+ sae_lens-6.13.1.dist-info/METADATA,sha256=j4uVlz-RU2jes4RPx6qzQcX_PWqHTPWC-z4PhwaTRjc,5318
37
+ sae_lens-6.13.1.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
38
+ sae_lens-6.13.1.dist-info/licenses/LICENSE,sha256=DW6e-hDosiu4CfW0-imI57sV1I5f9UEslpviNQcOAKs,1069
39
+ sae_lens-6.13.1.dist-info/RECORD,,