Skip to content

Commit

Permalink
Merge pull request #827 from TransformerLensOrg/dev
Browse files Browse the repository at this point in the history
Release 2.11
  • Loading branch information
bryce13950 authored Dec 31, 2024
2 parents 30c90f4 + cc927d7 commit f103deb
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
5 changes: 3 additions & 2 deletions demos/Colab_Compatibility.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"TransformerLens currently supports 205 models out of the box.\n"
"TransformerLens currently supports 206 models out of the box.\n"
]
}
],
Expand Down Expand Up @@ -429,6 +429,7 @@
" \"meta-llama/Llama-2-70b-chat-hf\",\n",
" \"meta-llama/Llama-3.1-70B\",\n",
" \"meta-llama/Llama-3.1-70B-Instruct\",\n",
" \"meta-llama/Llama-3.3-70B-Instruct\",\n",
" \"meta-llama/Meta-Llama-3-70B\",\n",
" \"meta-llama/Meta-Llama-3-70B-Instruct\",\n",
" \"mistralai/Mixtral-8x7B-Instruct-v0.1\",\n",
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,10 @@ def set_to_randn(z, hook):
# exactly when the zero hook is attached last XOR it is prepended

assert torch.allclose(logits, model.unembed.b_U[None, :]) == logits_are_unembed_bias


def test_use_attn_in_with_gqa_raises_error():
# Create model that uses GroupedQueryAttention
model = HookedTransformer.from_pretrained("Qwen/Qwen2-0.5B")
with pytest.raises(AssertionError):
model.set_use_attn_in(True)
5 changes: 4 additions & 1 deletion transformer_lens/HookedTransformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ def from_pretrained(
center_writing_weights = False
if center_unembed and cfg.output_logits_soft_cap > 0.0:
logging.warning(
"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"
"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 "
"Setting center_unembed=False instead."
)
center_unembed = False
Expand Down Expand Up @@ -1969,6 +1969,9 @@ def set_use_attn_in(self, use_attn_in: bool):
"""
Toggles whether to allow editing of inputs to each attention head.
"""
assert (
self.cfg.n_key_value_heads is None
), "Can't use attn_in with GroupedQueryAttention, please use split_qkv_input instead"
self.cfg.use_attn_in = use_attn_in

def set_ungroup_grouped_query_attention(self, ungroup_grouped_query_attention: bool):
Expand Down
39 changes: 33 additions & 6 deletions transformer_lens/loading_from_pretrained.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,15 @@
"meta-llama/Meta-Llama-3-8B-Instruct",
"meta-llama/Meta-Llama-3-70B",
"meta-llama/Meta-Llama-3-70B-Instruct",
"meta-llama/Llama-3.2-1B",
"meta-llama/Llama-3.2-3B",
"meta-llama/Llama-3.2-1B-Instruct",
"meta-llama/Llama-3.2-3B-Instruct",
"meta-llama/Llama-3.1-70B",
"meta-llama/Llama-3.1-8B",
"meta-llama/Llama-3.1-8B-Instruct",
"meta-llama/Llama-3.1-70B-Instruct",
"meta-llama/Llama-3.2-1B",
"meta-llama/Llama-3.2-3B",
"meta-llama/Llama-3.2-1B-Instruct",
"meta-llama/Llama-3.2-3B-Instruct",
"meta-llama/Llama-3.3-70B-Instruct",
"Baidicoot/Othello-GPT-Transformer-Lens",
"bert-base-cased",
"roneneldan/TinyStories-1M",
Expand Down Expand Up @@ -960,6 +961,30 @@ def convert_hf_model_config(model_name: str, **kwargs):
"NTK_by_parts_high_freq_factor": 4.0,
"NTK_by_parts_factor": 32.0,
}
elif "Llama-3.3-70B" in official_model_name:
cfg_dict = {
"d_model": 8192,
"d_head": 128,
"n_heads": 64,
"d_mlp": 28672,
"n_layers": 80,
"n_ctx": 2048, # capped due to memory issues
"eps": 1e-5,
"d_vocab": 128256,
"act_fn": "silu",
"n_key_value_heads": 8,
"normalization_type": "RMS",
"positional_embedding_type": "rotary",
"rotary_adjacent_pairs": False,
"rotary_dim": 32,
"final_rms": True,
"gated_mlp": True,
"rotary_base": 500000.0,
"use_NTK_by_parts_rope": True,
"NTK_by_parts_low_freq_factor": 1.0,
"NTK_by_parts_high_freq_factor": 4.0,
"NTK_by_parts_factor": 8.0,
}
elif "Llama-3.1-8B" in official_model_name:
cfg_dict = {
"d_model": 4096,
Expand Down Expand Up @@ -1241,6 +1266,7 @@ def convert_hf_model_config(model_name: str, **kwargs):
"trust_remote_code": True,
"final_rms": True,
"gated_mlp": True,
"default_prepend_bos": False,
}
elif architecture == "Qwen2ForCausalLM":
# Note that Qwen1.5 models have architecture type Qwen2ForCausalLM.
Expand All @@ -1259,12 +1285,13 @@ def convert_hf_model_config(model_name: str, **kwargs):
"initializer_range": hf_config.initializer_range,
"normalization_type": "RMS",
"positional_embedding_type": "rotary",
"rotary_base": hf_config.rope_theta,
"rotary_base": int(hf_config.rope_theta),
"rotary_adjacent_pairs": False,
"rotary_dim": hf_config.hidden_size // hf_config.num_attention_heads,
"tokenizer_prepends_bos": True,
"final_rms": True,
"gated_mlp": True,
"default_prepend_bos": False,
}
elif architecture == "PhiForCausalLM":
# Architecture for microsoft/phi models
Expand Down Expand Up @@ -1325,7 +1352,7 @@ def convert_hf_model_config(model_name: str, **kwargs):
"act_fn": "gelu_new",
"initializer_range": 0.02,
"normalization_type": "RMS",
"rotary_base": 10000.0,
"rotary_base": 10000,
"rotary_dim": 256,
"positional_embedding_type": "rotary",
"use_attn_scale": True,
Expand Down

0 comments on commit f103deb

Please sign in to comment.