Skip to content

Commit f103deb

Browse files
authored
Merge pull request #827 from TransformerLensOrg/dev
Release 2.11
2 parents 30c90f4 + cc927d7 commit f103deb

File tree

4 files changed

+47
-9
lines changed

4 files changed

+47
-9
lines changed

demos/Colab_Compatibility.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@
5858
},
5959
{
6060
"cell_type": "code",
61-
"execution_count": 2,
61+
"execution_count": 1,
6262
"metadata": {},
6363
"outputs": [
6464
{
6565
"name": "stdout",
6666
"output_type": "stream",
6767
"text": [
68-
"TransformerLens currently supports 205 models out of the box.\n"
68+
"TransformerLens currently supports 206 models out of the box.\n"
6969
]
7070
}
7171
],
@@ -429,6 +429,7 @@
429429
" \"meta-llama/Llama-2-70b-chat-hf\",\n",
430430
" \"meta-llama/Llama-3.1-70B\",\n",
431431
" \"meta-llama/Llama-3.1-70B-Instruct\",\n",
432+
" \"meta-llama/Llama-3.3-70B-Instruct\",\n",
432433
" \"meta-llama/Meta-Llama-3-70B\",\n",
433434
" \"meta-llama/Meta-Llama-3-70B-Instruct\",\n",
434435
" \"mistralai/Mixtral-8x7B-Instruct-v0.1\",\n",

tests/integration/test_hooks.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,10 @@ def set_to_randn(z, hook):
234234
# exactly when the zero hook is attached last XOR it is prepended
235235

236236
assert torch.allclose(logits, model.unembed.b_U[None, :]) == logits_are_unembed_bias
237+
238+
239+
def test_use_attn_in_with_gqa_raises_error():
240+
# Create model that uses GroupedQueryAttention
241+
model = HookedTransformer.from_pretrained("Qwen/Qwen2-0.5B")
242+
with pytest.raises(AssertionError):
243+
model.set_use_attn_in(True)

transformer_lens/HookedTransformer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ def from_pretrained(
13111311
center_writing_weights = False
13121312
if center_unembed and cfg.output_logits_soft_cap > 0.0:
13131313
logging.warning(
1314-
"You tried to specify center_unembed=True for a model using logit softcap, but this can't be done! Softcapping is not invariant upon adding a constant"
1314+
"You tried to specify center_unembed=True for a model using logit softcap, but this can't be done! Softcapping is not invariant upon adding a constant "
13151315
"Setting center_unembed=False instead."
13161316
)
13171317
center_unembed = False
@@ -1969,6 +1969,9 @@ def set_use_attn_in(self, use_attn_in: bool):
19691969
"""
19701970
Toggles whether to allow editing of inputs to each attention head.
19711971
"""
1972+
assert (
1973+
self.cfg.n_key_value_heads is None
1974+
), "Can't use attn_in with GroupedQueryAttention, please use split_qkv_input instead"
19721975
self.cfg.use_attn_in = use_attn_in
19731976

19741977
def set_ungroup_grouped_query_attention(self, ungroup_grouped_query_attention: bool):

transformer_lens/loading_from_pretrained.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,15 @@
151151
"meta-llama/Meta-Llama-3-8B-Instruct",
152152
"meta-llama/Meta-Llama-3-70B",
153153
"meta-llama/Meta-Llama-3-70B-Instruct",
154-
"meta-llama/Llama-3.2-1B",
155-
"meta-llama/Llama-3.2-3B",
156-
"meta-llama/Llama-3.2-1B-Instruct",
157-
"meta-llama/Llama-3.2-3B-Instruct",
158154
"meta-llama/Llama-3.1-70B",
159155
"meta-llama/Llama-3.1-8B",
160156
"meta-llama/Llama-3.1-8B-Instruct",
161157
"meta-llama/Llama-3.1-70B-Instruct",
158+
"meta-llama/Llama-3.2-1B",
159+
"meta-llama/Llama-3.2-3B",
160+
"meta-llama/Llama-3.2-1B-Instruct",
161+
"meta-llama/Llama-3.2-3B-Instruct",
162+
"meta-llama/Llama-3.3-70B-Instruct",
162163
"Baidicoot/Othello-GPT-Transformer-Lens",
163164
"bert-base-cased",
164165
"roneneldan/TinyStories-1M",
@@ -960,6 +961,30 @@ def convert_hf_model_config(model_name: str, **kwargs):
960961
"NTK_by_parts_high_freq_factor": 4.0,
961962
"NTK_by_parts_factor": 32.0,
962963
}
964+
elif "Llama-3.3-70B" in official_model_name:
965+
cfg_dict = {
966+
"d_model": 8192,
967+
"d_head": 128,
968+
"n_heads": 64,
969+
"d_mlp": 28672,
970+
"n_layers": 80,
971+
"n_ctx": 2048, # capped due to memory issues
972+
"eps": 1e-5,
973+
"d_vocab": 128256,
974+
"act_fn": "silu",
975+
"n_key_value_heads": 8,
976+
"normalization_type": "RMS",
977+
"positional_embedding_type": "rotary",
978+
"rotary_adjacent_pairs": False,
979+
"rotary_dim": 32,
980+
"final_rms": True,
981+
"gated_mlp": True,
982+
"rotary_base": 500000.0,
983+
"use_NTK_by_parts_rope": True,
984+
"NTK_by_parts_low_freq_factor": 1.0,
985+
"NTK_by_parts_high_freq_factor": 4.0,
986+
"NTK_by_parts_factor": 8.0,
987+
}
963988
elif "Llama-3.1-8B" in official_model_name:
964989
cfg_dict = {
965990
"d_model": 4096,
@@ -1241,6 +1266,7 @@ def convert_hf_model_config(model_name: str, **kwargs):
12411266
"trust_remote_code": True,
12421267
"final_rms": True,
12431268
"gated_mlp": True,
1269+
"default_prepend_bos": False,
12441270
}
12451271
elif architecture == "Qwen2ForCausalLM":
12461272
# Note that Qwen1.5 models have architecture type Qwen2ForCausalLM.
@@ -1259,12 +1285,13 @@ def convert_hf_model_config(model_name: str, **kwargs):
12591285
"initializer_range": hf_config.initializer_range,
12601286
"normalization_type": "RMS",
12611287
"positional_embedding_type": "rotary",
1262-
"rotary_base": hf_config.rope_theta,
1288+
"rotary_base": int(hf_config.rope_theta),
12631289
"rotary_adjacent_pairs": False,
12641290
"rotary_dim": hf_config.hidden_size // hf_config.num_attention_heads,
12651291
"tokenizer_prepends_bos": True,
12661292
"final_rms": True,
12671293
"gated_mlp": True,
1294+
"default_prepend_bos": False,
12681295
}
12691296
elif architecture == "PhiForCausalLM":
12701297
# Architecture for microsoft/phi models
@@ -1325,7 +1352,7 @@ def convert_hf_model_config(model_name: str, **kwargs):
13251352
"act_fn": "gelu_new",
13261353
"initializer_range": 0.02,
13271354
"normalization_type": "RMS",
1328-
"rotary_base": 10000.0,
1355+
"rotary_base": 10000,
13291356
"rotary_dim": 256,
13301357
"positional_embedding_type": "rotary",
13311358
"use_attn_scale": True,

0 commit comments

Comments
 (0)