Text Generation
Transformers
Safetensors
English
olmo2_noqknorm_prenorm
dense
baseline
ablation
memory-matched
conversational
custom_code
Instructions to use allenai/Dense_1b_130B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use allenai/Dense_1b_130B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="allenai/Dense_1b_130B", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("allenai/Dense_1b_130B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use allenai/Dense_1b_130B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "allenai/Dense_1b_130B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "allenai/Dense_1b_130B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/allenai/Dense_1b_130B
- SGLang
How to use allenai/Dense_1b_130B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "allenai/Dense_1b_130B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "allenai/Dense_1b_130B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "allenai/Dense_1b_130B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "allenai/Dense_1b_130B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use allenai/Dense_1b_130B with Docker Model Runner:
docker model run hf.co/allenai/Dense_1b_130B
Add model and trust_remote_code files.
Browse files- chat_template.jinja +4 -0
- config.json +30 -0
- configuration_olmo2_noqknorm_prenorm.py +179 -0
- generation_config.json +4 -0
- merges.txt +0 -0
- model-00001-of-00002.safetensors +3 -0
- model-00002-of-00002.safetensors +3 -0
- model.safetensors.index.json +155 -0
- modeling_olmo2_noqknorm_prenorm.py +473 -0
- special_tokens_map.json +11 -0
- tokenizer.json +0 -0
- tokenizer_config.json +189 -0
- vocab.json +0 -0
chat_template.jinja
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% for message in messages %}{{'<|im_start|>' + message['role'] + '
|
| 2 |
+
' + message['content'] + '<|im_end|>' + '
|
| 3 |
+
'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant
|
| 4 |
+
' }}{% endif %}
|
config.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"Olmo2NoQKNormPrenormForCausalLM"
|
| 4 |
+
],
|
| 5 |
+
"attention_bias": false,
|
| 6 |
+
"attention_dropout": 0.0,
|
| 7 |
+
"dtype": "float32",
|
| 8 |
+
"eos_token_id": 100257,
|
| 9 |
+
"hidden_act": "silu",
|
| 10 |
+
"hidden_size": 2048,
|
| 11 |
+
"initializer_range": 0.02,
|
| 12 |
+
"intermediate_size": 8192,
|
| 13 |
+
"max_position_embeddings": 4096,
|
| 14 |
+
"model_type": "olmo2_noqknorm_prenorm",
|
| 15 |
+
"num_attention_heads": 16,
|
| 16 |
+
"num_hidden_layers": 16,
|
| 17 |
+
"num_key_value_heads": 16,
|
| 18 |
+
"pad_token_id": 100277,
|
| 19 |
+
"rms_norm_eps": 1e-06,
|
| 20 |
+
"rope_scaling": null,
|
| 21 |
+
"rope_theta": 500000,
|
| 22 |
+
"tie_word_embeddings": false,
|
| 23 |
+
"transformers_version": "4.57.1",
|
| 24 |
+
"use_cache": true,
|
| 25 |
+
"vocab_size": 100352,
|
| 26 |
+
"auto_map": {
|
| 27 |
+
"AutoConfig": "configuration_olmo2_noqknorm_prenorm.Olmo2NoQKNormPrenormConfig",
|
| 28 |
+
"AutoModelForCausalLM": "modeling_olmo2_noqknorm_prenorm.Olmo2NoQKNormPrenormForCausalLM"
|
| 29 |
+
}
|
| 30 |
+
}
|
configuration_olmo2_noqknorm_prenorm.py
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 2 |
+
# This file was automatically generated from src/transformers/models/olmo2_noqknorm_prenorm/modular_olmo2_noqknorm_prenorm.py.
|
| 3 |
+
# Do NOT edit this file manually as any edits will be overwritten by the generation of
|
| 4 |
+
# the file from the modular. If any change should be done, please apply the change to the
|
| 5 |
+
# modular_olmo2_noqknorm_prenorm.py file directly. One of our CI enforces this.
|
| 6 |
+
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 7 |
+
from transformers.configuration_utils import PretrainedConfig
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class Olmo2NoQKNormPrenormConfig(PretrainedConfig):
|
| 11 |
+
r"""
|
| 12 |
+
This is the configuration class to store the configuration of a [`Olmo2NoQKNormPrenormModel`]. It is used to instantiate an Olmo2NoQKNormPrenorm
|
| 13 |
+
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
|
| 14 |
+
defaults will yield a similar configuration to that of the [allenai/Olmo2NoQKNormPrenorm-7B-1124-hf](https://huggingface.co/allenai/Olmo2NoQKNormPrenorm-7B-1124-hf).
|
| 15 |
+
|
| 16 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
| 17 |
+
documentation from [`PretrainedConfig`] for more information.
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
Args:
|
| 21 |
+
vocab_size (`int`, *optional*, defaults to 50304):
|
| 22 |
+
Vocabulary size of the Olmo2NoQKNormPrenorm model. Defines the number of different tokens that can be represented by the
|
| 23 |
+
`inputs_ids` passed when calling [`Olmo2NoQKNormPrenormModel`]
|
| 24 |
+
hidden_size (`int`, *optional*, defaults to 4096):
|
| 25 |
+
Dimension of the hidden representations.
|
| 26 |
+
intermediate_size (`int`, *optional*, defaults to 11008):
|
| 27 |
+
Dimension of the MLP representations.
|
| 28 |
+
num_hidden_layers (`int`, *optional*, defaults to 32):
|
| 29 |
+
Number of hidden layers in the Transformer decoder.
|
| 30 |
+
num_attention_heads (`int`, *optional*, defaults to 32):
|
| 31 |
+
Number of attention heads for each attention layer in the Transformer decoder.
|
| 32 |
+
num_key_value_heads (`int`, *optional*):
|
| 33 |
+
This is the number of key_value heads that should be used to implement Grouped Query Attention. If
|
| 34 |
+
`num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
|
| 35 |
+
`num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
|
| 36 |
+
converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
|
| 37 |
+
by meanpooling all the original heads within that group. For more details, check out [this
|
| 38 |
+
paper](https://huggingface.co/papers/2305.13245). If it is not specified, will default to
|
| 39 |
+
`num_attention_heads`.
|
| 40 |
+
hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
|
| 41 |
+
The non-linear activation function (function or string) in the decoder.
|
| 42 |
+
max_position_embeddings (`int`, *optional*, defaults to 2048):
|
| 43 |
+
The maximum sequence length that this model might ever be used with.
|
| 44 |
+
initializer_range (`float`, *optional*, defaults to 0.02):
|
| 45 |
+
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
| 46 |
+
use_cache (`bool`, *optional*, defaults to `True`):
|
| 47 |
+
Whether or not the model should return the last key/values attentions (not used by all models). Only
|
| 48 |
+
relevant if `config.is_decoder=True`.
|
| 49 |
+
pad_token_id (`int`, *optional*, defaults to 1):
|
| 50 |
+
Padding token id.
|
| 51 |
+
bos_token_id (`int`, *optional*):
|
| 52 |
+
Beginning of stream token id.
|
| 53 |
+
eos_token_id (`int`, *optional*, defaults to 50279):
|
| 54 |
+
End of stream token id.
|
| 55 |
+
tie_word_embeddings (`bool`, *optional*, defaults to `False`):
|
| 56 |
+
Whether to tie weight embeddings
|
| 57 |
+
rope_theta (`float`, *optional*, defaults to 10000.0):
|
| 58 |
+
The base period of the RoPE embeddings.
|
| 59 |
+
rope_scaling (`Dict`, *optional*):
|
| 60 |
+
Dictionary containing the scaling configuration for the RoPE embeddings. Currently supports two scaling
|
| 61 |
+
strategies: linear and dynamic. Their scaling factor must be a float greater than 1. The expected format is
|
| 62 |
+
`{"type": strategy name, "factor": scaling factor}`. When using this flag, don't update
|
| 63 |
+
`max_position_embeddings` to the expected new maximum. See the following thread for more information on how
|
| 64 |
+
these scaling strategies behave:
|
| 65 |
+
https://www.reddit.com/r/LocalLLaMA/comments/14mrgpr/dynamically_scaled_rope_further_increases/. This is an
|
| 66 |
+
experimental feature, subject to breaking API changes in future versions.
|
| 67 |
+
attention_bias (`bool`, defaults to `False`, *optional*, defaults to `False`):
|
| 68 |
+
Whether to use a bias in the query, key, value and output projection layers during self-attention.
|
| 69 |
+
attention_dropout (`float`, *optional*, defaults to 0.0):
|
| 70 |
+
The dropout ratio for the attention probabilities.
|
| 71 |
+
rms_norm_eps (`float`, *optional*, defaults to 1e-05):
|
| 72 |
+
The epsilon used by the rms normalization layers.
|
| 73 |
+
|
| 74 |
+
```python
|
| 75 |
+
>>> from transformers import Olmo2NoQKNormPrenormModel, Olmo2NoQKNormPrenormConfig
|
| 76 |
+
|
| 77 |
+
>>> # Initializing a Olmo2NoQKNormPrenorm 7B style configuration
|
| 78 |
+
>>> configuration = Olmo2NoQKNormPrenormConfig()
|
| 79 |
+
|
| 80 |
+
>>> # Initializing a model from the Olmo2NoQKNormPrenorm 7B style configuration
|
| 81 |
+
>>> model = Olmo2NoQKNormPrenormModel(configuration)
|
| 82 |
+
|
| 83 |
+
>>> # Accessing the model configuration
|
| 84 |
+
>>> configuration = model.config
|
| 85 |
+
```
|
| 86 |
+
"""
|
| 87 |
+
|
| 88 |
+
model_type = "olmo2_noqknorm_prenorm"
|
| 89 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
| 90 |
+
base_model_tp_plan = {
|
| 91 |
+
"layers.*.self_attn.q_proj": "colwise", # No longer need rep
|
| 92 |
+
"layers.*.self_attn.k_proj": "colwise", # No longer need rep
|
| 93 |
+
"layers.*.self_attn.v_proj": "colwise", # No longer need rep
|
| 94 |
+
"layers.*.self_attn.o_proj": "rowwise", # No longer need rep
|
| 95 |
+
"layers.*.mlp.gate_proj": "colwise",
|
| 96 |
+
"layers.*.mlp.up_proj": "colwise",
|
| 97 |
+
"layers.*.mlp.down_proj": "rowwise",
|
| 98 |
+
}
|
| 99 |
+
base_model_pp_plan = {
|
| 100 |
+
"embed_tokens": (["input_ids"], ["inputs_embeds"]),
|
| 101 |
+
"layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
|
| 102 |
+
"norm": (["hidden_states"], ["hidden_states"]),
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
def __init__(
|
| 106 |
+
self,
|
| 107 |
+
vocab_size=50304,
|
| 108 |
+
hidden_size=4096,
|
| 109 |
+
intermediate_size=11008,
|
| 110 |
+
num_hidden_layers=32,
|
| 111 |
+
num_attention_heads=32,
|
| 112 |
+
num_key_value_heads=None,
|
| 113 |
+
hidden_act="silu",
|
| 114 |
+
max_position_embeddings=2048,
|
| 115 |
+
initializer_range=0.02,
|
| 116 |
+
use_cache=True,
|
| 117 |
+
pad_token_id=1,
|
| 118 |
+
bos_token_id=None,
|
| 119 |
+
eos_token_id=50279,
|
| 120 |
+
tie_word_embeddings=False,
|
| 121 |
+
rope_theta=10000.0,
|
| 122 |
+
rope_scaling=None,
|
| 123 |
+
attention_bias=False,
|
| 124 |
+
attention_dropout=0.0,
|
| 125 |
+
rms_norm_eps=1e-5,
|
| 126 |
+
**kwargs,
|
| 127 |
+
):
|
| 128 |
+
super().__init__(
|
| 129 |
+
pad_token_id=pad_token_id,
|
| 130 |
+
bos_token_id=bos_token_id,
|
| 131 |
+
eos_token_id=eos_token_id,
|
| 132 |
+
tie_word_embeddings=tie_word_embeddings,
|
| 133 |
+
**kwargs,
|
| 134 |
+
)
|
| 135 |
+
self.vocab_size = vocab_size
|
| 136 |
+
self.max_position_embeddings = max_position_embeddings
|
| 137 |
+
self.hidden_size = hidden_size
|
| 138 |
+
self.intermediate_size = intermediate_size
|
| 139 |
+
self.num_hidden_layers = num_hidden_layers
|
| 140 |
+
self.num_attention_heads = num_attention_heads
|
| 141 |
+
|
| 142 |
+
# for backward compatibility
|
| 143 |
+
if num_key_value_heads is None:
|
| 144 |
+
num_key_value_heads = num_attention_heads
|
| 145 |
+
|
| 146 |
+
self.num_key_value_heads = num_key_value_heads
|
| 147 |
+
self.hidden_act = hidden_act
|
| 148 |
+
self.initializer_range = initializer_range
|
| 149 |
+
self.use_cache = use_cache
|
| 150 |
+
self.rope_theta = rope_theta
|
| 151 |
+
self.rope_scaling = rope_scaling
|
| 152 |
+
self._rope_scaling_validation()
|
| 153 |
+
self.attention_bias = attention_bias
|
| 154 |
+
self.attention_dropout = attention_dropout
|
| 155 |
+
|
| 156 |
+
self.rms_norm_eps = rms_norm_eps
|
| 157 |
+
|
| 158 |
+
def _rope_scaling_validation(self):
|
| 159 |
+
"""
|
| 160 |
+
Validate the `rope_scaling` configuration.
|
| 161 |
+
"""
|
| 162 |
+
if self.rope_scaling is None:
|
| 163 |
+
return
|
| 164 |
+
|
| 165 |
+
if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 2:
|
| 166 |
+
raise ValueError(
|
| 167 |
+
f"`rope_scaling` must be a dictionary with two fields, `type` and `factor`, got {self.rope_scaling}"
|
| 168 |
+
)
|
| 169 |
+
rope_scaling_type = self.rope_scaling.get("type", None)
|
| 170 |
+
rope_scaling_factor = self.rope_scaling.get("factor", None)
|
| 171 |
+
if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
|
| 172 |
+
raise ValueError(
|
| 173 |
+
f"`rope_scaling`'s type field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"
|
| 174 |
+
)
|
| 175 |
+
if rope_scaling_factor is None or not isinstance(rope_scaling_factor, float) or rope_scaling_factor <= 1.0:
|
| 176 |
+
raise ValueError(f"`rope_scaling`'s factor field must be a float > 1, got {rope_scaling_factor}")
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
__all__ = ["Olmo2NoQKNormPrenormConfig"]
|
generation_config.json
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"transformers_version": "4.57.1"
|
| 4 |
+
}
|
merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model-00001-of-00002.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:becfbeb17ae64c4e4aefbc70fe72170d53004eeded744c0b7c736e18fca6ed0c
|
| 3 |
+
size 4983095256
|
model-00002-of-00002.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bd9fc7c0858c17498af7b3143b3383d4ea9681a622989ef4c205daa25ebb31eb
|
| 3 |
+
size 956326560
|
model.safetensors.index.json
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"metadata": {
|
| 3 |
+
"total_parameters": 1484851200,
|
| 4 |
+
"total_size": 5939404800
|
| 5 |
+
},
|
| 6 |
+
"weight_map": {
|
| 7 |
+
"lm_head.weight": "model-00002-of-00002.safetensors",
|
| 8 |
+
"model.embed_tokens.weight": "model-00001-of-00002.safetensors",
|
| 9 |
+
"model.layers.0.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 10 |
+
"model.layers.0.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 11 |
+
"model.layers.0.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 12 |
+
"model.layers.0.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 13 |
+
"model.layers.0.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 14 |
+
"model.layers.0.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 15 |
+
"model.layers.0.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 16 |
+
"model.layers.0.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 17 |
+
"model.layers.0.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 18 |
+
"model.layers.1.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 19 |
+
"model.layers.1.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 20 |
+
"model.layers.1.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 21 |
+
"model.layers.1.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 22 |
+
"model.layers.1.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 23 |
+
"model.layers.1.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 24 |
+
"model.layers.1.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 25 |
+
"model.layers.1.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 26 |
+
"model.layers.1.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 27 |
+
"model.layers.10.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 28 |
+
"model.layers.10.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 29 |
+
"model.layers.10.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 30 |
+
"model.layers.10.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 31 |
+
"model.layers.10.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 32 |
+
"model.layers.10.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 33 |
+
"model.layers.10.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 34 |
+
"model.layers.10.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 35 |
+
"model.layers.10.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 36 |
+
"model.layers.11.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 37 |
+
"model.layers.11.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 38 |
+
"model.layers.11.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 39 |
+
"model.layers.11.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 40 |
+
"model.layers.11.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 41 |
+
"model.layers.11.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 42 |
+
"model.layers.11.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 43 |
+
"model.layers.11.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 44 |
+
"model.layers.11.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 45 |
+
"model.layers.12.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 46 |
+
"model.layers.12.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 47 |
+
"model.layers.12.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 48 |
+
"model.layers.12.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 49 |
+
"model.layers.12.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 50 |
+
"model.layers.12.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 51 |
+
"model.layers.12.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 52 |
+
"model.layers.12.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 53 |
+
"model.layers.12.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 54 |
+
"model.layers.13.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 55 |
+
"model.layers.13.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 56 |
+
"model.layers.13.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 57 |
+
"model.layers.13.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 58 |
+
"model.layers.13.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 59 |
+
"model.layers.13.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 60 |
+
"model.layers.13.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 61 |
+
"model.layers.13.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 62 |
+
"model.layers.13.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 63 |
+
"model.layers.14.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 64 |
+
"model.layers.14.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 65 |
+
"model.layers.14.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 66 |
+
"model.layers.14.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 67 |
+
"model.layers.14.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 68 |
+
"model.layers.14.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 69 |
+
"model.layers.14.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 70 |
+
"model.layers.14.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 71 |
+
"model.layers.14.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 72 |
+
"model.layers.15.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
|
| 73 |
+
"model.layers.15.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 74 |
+
"model.layers.15.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
|
| 75 |
+
"model.layers.15.pre_attention_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 76 |
+
"model.layers.15.pre_feedforward_layernorm.weight": "model-00002-of-00002.safetensors",
|
| 77 |
+
"model.layers.15.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 78 |
+
"model.layers.15.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 79 |
+
"model.layers.15.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 80 |
+
"model.layers.15.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 81 |
+
"model.layers.2.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 82 |
+
"model.layers.2.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 83 |
+
"model.layers.2.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 84 |
+
"model.layers.2.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 85 |
+
"model.layers.2.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 86 |
+
"model.layers.2.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 87 |
+
"model.layers.2.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 88 |
+
"model.layers.2.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 89 |
+
"model.layers.2.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 90 |
+
"model.layers.3.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 91 |
+
"model.layers.3.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 92 |
+
"model.layers.3.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 93 |
+
"model.layers.3.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 94 |
+
"model.layers.3.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 95 |
+
"model.layers.3.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 96 |
+
"model.layers.3.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 97 |
+
"model.layers.3.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 98 |
+
"model.layers.3.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 99 |
+
"model.layers.4.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 100 |
+
"model.layers.4.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 101 |
+
"model.layers.4.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 102 |
+
"model.layers.4.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 103 |
+
"model.layers.4.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 104 |
+
"model.layers.4.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 105 |
+
"model.layers.4.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 106 |
+
"model.layers.4.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 107 |
+
"model.layers.4.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 108 |
+
"model.layers.5.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 109 |
+
"model.layers.5.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 110 |
+
"model.layers.5.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 111 |
+
"model.layers.5.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 112 |
+
"model.layers.5.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 113 |
+
"model.layers.5.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 114 |
+
"model.layers.5.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 115 |
+
"model.layers.5.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 116 |
+
"model.layers.5.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 117 |
+
"model.layers.6.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 118 |
+
"model.layers.6.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 119 |
+
"model.layers.6.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 120 |
+
"model.layers.6.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 121 |
+
"model.layers.6.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 122 |
+
"model.layers.6.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 123 |
+
"model.layers.6.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 124 |
+
"model.layers.6.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 125 |
+
"model.layers.6.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 126 |
+
"model.layers.7.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 127 |
+
"model.layers.7.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 128 |
+
"model.layers.7.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 129 |
+
"model.layers.7.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 130 |
+
"model.layers.7.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 131 |
+
"model.layers.7.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 132 |
+
"model.layers.7.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 133 |
+
"model.layers.7.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 134 |
+
"model.layers.7.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 135 |
+
"model.layers.8.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 136 |
+
"model.layers.8.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 137 |
+
"model.layers.8.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 138 |
+
"model.layers.8.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 139 |
+
"model.layers.8.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 140 |
+
"model.layers.8.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 141 |
+
"model.layers.8.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 142 |
+
"model.layers.8.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 143 |
+
"model.layers.8.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 144 |
+
"model.layers.9.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
|
| 145 |
+
"model.layers.9.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
|
| 146 |
+
"model.layers.9.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
|
| 147 |
+
"model.layers.9.pre_attention_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 148 |
+
"model.layers.9.pre_feedforward_layernorm.weight": "model-00001-of-00002.safetensors",
|
| 149 |
+
"model.layers.9.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
|
| 150 |
+
"model.layers.9.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
|
| 151 |
+
"model.layers.9.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
|
| 152 |
+
"model.layers.9.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
|
| 153 |
+
"model.norm.weight": "model-00002-of-00002.safetensors"
|
| 154 |
+
}
|
| 155 |
+
}
|
modeling_olmo2_noqknorm_prenorm.py
ADDED
|
@@ -0,0 +1,473 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 2 |
+
# This file was automatically generated from src/transformers/models/olmo2_noqknorm_prenorm/modular_olmo2_noqknorm_prenorm.py.
|
| 3 |
+
# Do NOT edit this file manually as any edits will be overwritten by the generation of
|
| 4 |
+
# the file from the modular. If any change should be done, please apply the change to the
|
| 5 |
+
# modular_olmo2_noqknorm_prenorm.py file directly. One of our CI enforces this.
|
| 6 |
+
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 7 |
+
from typing import Callable, Optional, Union
|
| 8 |
+
|
| 9 |
+
import torch
|
| 10 |
+
import torch.nn as nn
|
| 11 |
+
|
| 12 |
+
from transformers.utils.generic import TransformersKwargs
|
| 13 |
+
|
| 14 |
+
from transformers.activations import ACT2FN
|
| 15 |
+
from transformers.cache_utils import Cache, DynamicCache
|
| 16 |
+
from transformers.generation import GenerationMixin
|
| 17 |
+
from transformers.integrations import use_kernel_forward_from_hub
|
| 18 |
+
from transformers.masking_utils import create_causal_mask
|
| 19 |
+
from transformers.modeling_layers import GradientCheckpointingLayer
|
| 20 |
+
from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast
|
| 21 |
+
from transformers.modeling_rope_utils import ROPE_INIT_FUNCTIONS, dynamic_rope_update
|
| 22 |
+
from transformers.modeling_utils import ALL_ATTENTION_FUNCTIONS, PreTrainedModel
|
| 23 |
+
from transformers.processing_utils import Unpack
|
| 24 |
+
from transformers.utils import auto_docstring, can_return_tuple
|
| 25 |
+
from transformers.utils.deprecation import deprecate_kwarg
|
| 26 |
+
from transformers.utils.generic import check_model_inputs
|
| 27 |
+
from .configuration_olmo2_noqknorm_prenorm import Olmo2NoQKNormPrenormConfig
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
@use_kernel_forward_from_hub("RMSNorm")
|
| 31 |
+
class Olmo2NoQKNormPrenormRMSNorm(nn.Module):
|
| 32 |
+
def __init__(self, hidden_size, eps=1e-6):
|
| 33 |
+
"""
|
| 34 |
+
Olmo2NoQKNormPrenormRMSNorm is equivalent to T5LayerNorm
|
| 35 |
+
"""
|
| 36 |
+
super().__init__()
|
| 37 |
+
self.weight = nn.Parameter(torch.ones(hidden_size))
|
| 38 |
+
self.variance_epsilon = eps
|
| 39 |
+
|
| 40 |
+
def forward(self, hidden_states):
|
| 41 |
+
input_dtype = hidden_states.dtype
|
| 42 |
+
hidden_states = hidden_states.to(torch.float32)
|
| 43 |
+
variance = hidden_states.pow(2).mean(-1, keepdim=True)
|
| 44 |
+
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
|
| 45 |
+
return (self.weight * hidden_states).to(input_dtype)
|
| 46 |
+
|
| 47 |
+
def extra_repr(self):
|
| 48 |
+
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
|
| 52 |
+
"""
|
| 53 |
+
This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
|
| 54 |
+
num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
|
| 55 |
+
"""
|
| 56 |
+
batch, num_key_value_heads, slen, head_dim = hidden_states.shape
|
| 57 |
+
if n_rep == 1:
|
| 58 |
+
return hidden_states
|
| 59 |
+
hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
|
| 60 |
+
return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def eager_attention_forward(
|
| 64 |
+
module: nn.Module,
|
| 65 |
+
query: torch.Tensor,
|
| 66 |
+
key: torch.Tensor,
|
| 67 |
+
value: torch.Tensor,
|
| 68 |
+
attention_mask: Optional[torch.Tensor],
|
| 69 |
+
scaling: float,
|
| 70 |
+
dropout: float = 0.0,
|
| 71 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 72 |
+
):
|
| 73 |
+
key_states = repeat_kv(key, module.num_key_value_groups)
|
| 74 |
+
value_states = repeat_kv(value, module.num_key_value_groups)
|
| 75 |
+
|
| 76 |
+
attn_weights = torch.matmul(query, key_states.transpose(2, 3)) * scaling
|
| 77 |
+
if attention_mask is not None:
|
| 78 |
+
causal_mask = attention_mask[:, :, :, : key_states.shape[-2]]
|
| 79 |
+
attn_weights = attn_weights + causal_mask
|
| 80 |
+
|
| 81 |
+
attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query.dtype)
|
| 82 |
+
attn_weights = nn.functional.dropout(attn_weights, p=dropout, training=module.training)
|
| 83 |
+
attn_output = torch.matmul(attn_weights, value_states)
|
| 84 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
| 85 |
+
|
| 86 |
+
return attn_output, attn_weights
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
|
| 90 |
+
"""Applies Rotary Position Embedding to the query and key tensors.
|
| 91 |
+
|
| 92 |
+
Args:
|
| 93 |
+
q (`torch.Tensor`): The query tensor.
|
| 94 |
+
k (`torch.Tensor`): The key tensor.
|
| 95 |
+
cos (`torch.Tensor`): The cosine part of the rotary embedding.
|
| 96 |
+
sin (`torch.Tensor`): The sine part of the rotary embedding.
|
| 97 |
+
position_ids (`torch.Tensor`, *optional*):
|
| 98 |
+
Deprecated and unused.
|
| 99 |
+
unsqueeze_dim (`int`, *optional*, defaults to 1):
|
| 100 |
+
The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
|
| 101 |
+
sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
|
| 102 |
+
that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
|
| 103 |
+
k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
|
| 104 |
+
cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
|
| 105 |
+
the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
|
| 106 |
+
Returns:
|
| 107 |
+
`tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
|
| 108 |
+
"""
|
| 109 |
+
q_type, k_type = q.dtype, k.dtype
|
| 110 |
+
cos = cos.unsqueeze(unsqueeze_dim)
|
| 111 |
+
sin = sin.unsqueeze(unsqueeze_dim)
|
| 112 |
+
q_embed = (q * cos) + (rotate_half(q) * sin)
|
| 113 |
+
k_embed = (k * cos) + (rotate_half(k) * sin)
|
| 114 |
+
return q_embed.to(q_type), k_embed.to(k_type)
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def rotate_half(x):
|
| 118 |
+
"""Rotates half the hidden dims of the input."""
|
| 119 |
+
x1 = x[..., : x.shape[-1] // 2]
|
| 120 |
+
x2 = x[..., x.shape[-1] // 2 :]
|
| 121 |
+
return torch.cat((-x2, x1), dim=-1)
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
class Olmo2NoQKNormPrenormAttention(nn.Module):
|
| 125 |
+
"""Multi-headed attention from 'Attention Is All You Need' paper"""
|
| 126 |
+
|
| 127 |
+
def __init__(self, config: Olmo2NoQKNormPrenormConfig, layer_idx: Optional[int] = None):
|
| 128 |
+
super().__init__()
|
| 129 |
+
self.config = config
|
| 130 |
+
self.layer_idx = layer_idx
|
| 131 |
+
self.head_dim = getattr(config, "head_dim", config.hidden_size // config.num_attention_heads)
|
| 132 |
+
self.num_key_value_groups = config.num_attention_heads // config.num_key_value_heads
|
| 133 |
+
self.scaling = self.head_dim**-0.5
|
| 134 |
+
self.attention_dropout = config.attention_dropout
|
| 135 |
+
self.is_causal = True
|
| 136 |
+
|
| 137 |
+
self.q_proj = nn.Linear(
|
| 138 |
+
config.hidden_size, config.num_attention_heads * self.head_dim, bias=config.attention_bias
|
| 139 |
+
)
|
| 140 |
+
self.k_proj = nn.Linear(
|
| 141 |
+
config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
|
| 142 |
+
)
|
| 143 |
+
self.v_proj = nn.Linear(
|
| 144 |
+
config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
|
| 145 |
+
)
|
| 146 |
+
self.o_proj = nn.Linear(
|
| 147 |
+
config.num_attention_heads * self.head_dim, config.hidden_size, bias=config.attention_bias
|
| 148 |
+
)
|
| 149 |
+
|
| 150 |
+
@deprecate_kwarg("past_key_value", new_name="past_key_values", version="4.58")
|
| 151 |
+
def forward(
|
| 152 |
+
self,
|
| 153 |
+
hidden_states: torch.Tensor,
|
| 154 |
+
position_embeddings: tuple[torch.Tensor, torch.Tensor],
|
| 155 |
+
attention_mask: Optional[torch.Tensor],
|
| 156 |
+
past_key_values: Optional[Cache] = None,
|
| 157 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 158 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 159 |
+
) -> tuple[torch.Tensor, Optional[torch.Tensor]]:
|
| 160 |
+
input_shape = hidden_states.shape[:-1]
|
| 161 |
+
hidden_shape = (*input_shape, -1, self.head_dim)
|
| 162 |
+
|
| 163 |
+
query_states = self.q_proj(hidden_states)
|
| 164 |
+
key_states = self.k_proj(hidden_states)
|
| 165 |
+
value_states = self.v_proj(hidden_states)
|
| 166 |
+
|
| 167 |
+
query_states = query_states.view(hidden_shape).transpose(1, 2)
|
| 168 |
+
key_states = key_states.view(hidden_shape).transpose(1, 2)
|
| 169 |
+
value_states = value_states.view(hidden_shape).transpose(1, 2)
|
| 170 |
+
|
| 171 |
+
cos, sin = position_embeddings
|
| 172 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin)
|
| 173 |
+
|
| 174 |
+
if past_key_values is not None:
|
| 175 |
+
# sin and cos are specific to RoPE models; cache_position needed for the static cache
|
| 176 |
+
cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position}
|
| 177 |
+
key_states, value_states = past_key_values.update(key_states, value_states, self.layer_idx, cache_kwargs)
|
| 178 |
+
|
| 179 |
+
attention_interface: Callable = eager_attention_forward
|
| 180 |
+
if self.config._attn_implementation != "eager":
|
| 181 |
+
attention_interface = ALL_ATTENTION_FUNCTIONS[self.config._attn_implementation]
|
| 182 |
+
|
| 183 |
+
attn_output, attn_weights = attention_interface(
|
| 184 |
+
self,
|
| 185 |
+
query_states,
|
| 186 |
+
key_states,
|
| 187 |
+
value_states,
|
| 188 |
+
attention_mask,
|
| 189 |
+
dropout=0.0 if not self.training else self.attention_dropout,
|
| 190 |
+
scaling=self.scaling,
|
| 191 |
+
**kwargs,
|
| 192 |
+
)
|
| 193 |
+
|
| 194 |
+
attn_output = attn_output.reshape(*input_shape, -1).contiguous()
|
| 195 |
+
attn_output = self.o_proj(attn_output)
|
| 196 |
+
return attn_output, attn_weights
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
class Olmo2NoQKNormPrenormMLP(nn.Module):
|
| 200 |
+
def __init__(self, config):
|
| 201 |
+
super().__init__()
|
| 202 |
+
self.config = config
|
| 203 |
+
self.hidden_size = config.hidden_size
|
| 204 |
+
self.intermediate_size = config.intermediate_size
|
| 205 |
+
self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
|
| 206 |
+
self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
|
| 207 |
+
self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=False)
|
| 208 |
+
self.act_fn = ACT2FN[config.hidden_act]
|
| 209 |
+
|
| 210 |
+
def forward(self, x):
|
| 211 |
+
down_proj = self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
|
| 212 |
+
return down_proj
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
class Olmo2NoQKNormPrenormDecoderLayer(GradientCheckpointingLayer):
|
| 216 |
+
def __init__(self, config: Olmo2NoQKNormPrenormConfig, layer_idx: int):
|
| 217 |
+
super().__init__()
|
| 218 |
+
self.hidden_size = config.hidden_size
|
| 219 |
+
self.self_attn = Olmo2NoQKNormPrenormAttention(config=config, layer_idx=layer_idx)
|
| 220 |
+
|
| 221 |
+
self.mlp = Olmo2NoQKNormPrenormMLP(config)
|
| 222 |
+
|
| 223 |
+
self.pre_attention_layernorm = Olmo2NoQKNormPrenormRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 224 |
+
self.pre_feedforward_layernorm = Olmo2NoQKNormPrenormRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 225 |
+
|
| 226 |
+
@deprecate_kwarg("past_key_value", new_name="past_key_values", version="4.58")
|
| 227 |
+
def forward(
|
| 228 |
+
self,
|
| 229 |
+
hidden_states: torch.Tensor,
|
| 230 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 231 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 232 |
+
past_key_values: Optional[Cache] = None,
|
| 233 |
+
use_cache: Optional[bool] = False,
|
| 234 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 235 |
+
position_embeddings: Optional[tuple[torch.Tensor, torch.Tensor]] = None, # necessary, but kept here for BC
|
| 236 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 237 |
+
) -> torch.Tensor:
|
| 238 |
+
residual = hidden_states
|
| 239 |
+
# apply norm before attention
|
| 240 |
+
hidden_states = self.pre_attention_layernorm(hidden_states)
|
| 241 |
+
hidden_states, _ = self.self_attn(
|
| 242 |
+
hidden_states=hidden_states,
|
| 243 |
+
attention_mask=attention_mask,
|
| 244 |
+
position_ids=position_ids,
|
| 245 |
+
past_key_values=past_key_values,
|
| 246 |
+
use_cache=use_cache,
|
| 247 |
+
cache_position=cache_position,
|
| 248 |
+
position_embeddings=position_embeddings,
|
| 249 |
+
**kwargs,
|
| 250 |
+
)
|
| 251 |
+
hidden_states = residual + hidden_states
|
| 252 |
+
|
| 253 |
+
# Fully Connected
|
| 254 |
+
residual = hidden_states
|
| 255 |
+
|
| 256 |
+
# apply norm before feedforward
|
| 257 |
+
hidden_states = self.pre_feedforward_layernorm(hidden_states)
|
| 258 |
+
hidden_states = self.mlp(hidden_states)
|
| 259 |
+
|
| 260 |
+
hidden_states = residual + hidden_states
|
| 261 |
+
return hidden_states
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
@auto_docstring
|
| 265 |
+
class Olmo2NoQKNormPrenormPreTrainedModel(PreTrainedModel):
|
| 266 |
+
config: Olmo2NoQKNormPrenormConfig
|
| 267 |
+
base_model_prefix = "model"
|
| 268 |
+
supports_gradient_checkpointing = True
|
| 269 |
+
_no_split_modules = ["Olmo2NoQKNormPrenormDecoderLayer"]
|
| 270 |
+
_skip_keys_device_placement = ["past_key_values"]
|
| 271 |
+
_supports_flash_attn = True
|
| 272 |
+
_supports_sdpa = True
|
| 273 |
+
_supports_flex_attn = True
|
| 274 |
+
|
| 275 |
+
_can_compile_fullgraph = True
|
| 276 |
+
_supports_attention_backend = True
|
| 277 |
+
_can_record_outputs = {
|
| 278 |
+
"hidden_states": Olmo2NoQKNormPrenormDecoderLayer,
|
| 279 |
+
"attentions": Olmo2NoQKNormPrenormAttention,
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
class Olmo2NoQKNormPrenormRotaryEmbedding(nn.Module):
|
| 284 |
+
inv_freq: torch.Tensor # fix linting for `register_buffer`
|
| 285 |
+
|
| 286 |
+
def __init__(self, config: Olmo2NoQKNormPrenormConfig, device=None):
|
| 287 |
+
super().__init__()
|
| 288 |
+
# BC: "rope_type" was originally "type"
|
| 289 |
+
if hasattr(config, "rope_scaling") and isinstance(config.rope_scaling, dict):
|
| 290 |
+
self.rope_type = config.rope_scaling.get("rope_type", config.rope_scaling.get("type"))
|
| 291 |
+
else:
|
| 292 |
+
self.rope_type = "default"
|
| 293 |
+
self.max_seq_len_cached = config.max_position_embeddings
|
| 294 |
+
self.original_max_seq_len = config.max_position_embeddings
|
| 295 |
+
|
| 296 |
+
self.config = config
|
| 297 |
+
self.rope_init_fn = ROPE_INIT_FUNCTIONS[self.rope_type]
|
| 298 |
+
|
| 299 |
+
inv_freq, self.attention_scaling = self.rope_init_fn(self.config, device)
|
| 300 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False)
|
| 301 |
+
self.original_inv_freq = self.inv_freq
|
| 302 |
+
|
| 303 |
+
@torch.no_grad()
|
| 304 |
+
@dynamic_rope_update # power user: used with advanced RoPE types (e.g. dynamic rope)
|
| 305 |
+
def forward(self, x, position_ids):
|
| 306 |
+
inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1).to(x.device)
|
| 307 |
+
position_ids_expanded = position_ids[:, None, :].float()
|
| 308 |
+
|
| 309 |
+
device_type = x.device.type if isinstance(x.device.type, str) and x.device.type != "mps" else "cpu"
|
| 310 |
+
with torch.autocast(device_type=device_type, enabled=False): # Force float32
|
| 311 |
+
freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
|
| 312 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
| 313 |
+
cos = emb.cos() * self.attention_scaling
|
| 314 |
+
sin = emb.sin() * self.attention_scaling
|
| 315 |
+
return cos, sin
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
@auto_docstring
|
| 319 |
+
class Olmo2NoQKNormPrenormModel(Olmo2NoQKNormPrenormPreTrainedModel):
|
| 320 |
+
def __init__(self, config: Olmo2NoQKNormPrenormConfig):
|
| 321 |
+
super().__init__(config)
|
| 322 |
+
self.padding_idx = config.pad_token_id
|
| 323 |
+
self.vocab_size = config.vocab_size
|
| 324 |
+
|
| 325 |
+
self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
|
| 326 |
+
self.layers = nn.ModuleList(
|
| 327 |
+
[Olmo2NoQKNormPrenormDecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
|
| 328 |
+
)
|
| 329 |
+
self.norm = Olmo2NoQKNormPrenormRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 330 |
+
self.rotary_emb = Olmo2NoQKNormPrenormRotaryEmbedding(config=config)
|
| 331 |
+
self.gradient_checkpointing = False
|
| 332 |
+
|
| 333 |
+
# Initialize weights and apply final processing
|
| 334 |
+
self.post_init()
|
| 335 |
+
|
| 336 |
+
@check_model_inputs
|
| 337 |
+
@auto_docstring
|
| 338 |
+
def forward(
|
| 339 |
+
self,
|
| 340 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 341 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 342 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 343 |
+
past_key_values: Optional[Cache] = None,
|
| 344 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 345 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 346 |
+
use_cache: Optional[bool] = None,
|
| 347 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 348 |
+
) -> BaseModelOutputWithPast:
|
| 349 |
+
if (input_ids is None) ^ (inputs_embeds is not None):
|
| 350 |
+
raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
|
| 351 |
+
|
| 352 |
+
if inputs_embeds is None:
|
| 353 |
+
inputs_embeds: torch.Tensor = self.embed_tokens(input_ids)
|
| 354 |
+
|
| 355 |
+
if use_cache and past_key_values is None:
|
| 356 |
+
past_key_values = DynamicCache(config=self.config)
|
| 357 |
+
|
| 358 |
+
if cache_position is None:
|
| 359 |
+
past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
|
| 360 |
+
cache_position: torch.Tensor = torch.arange(
|
| 361 |
+
past_seen_tokens, past_seen_tokens + inputs_embeds.shape[1], device=inputs_embeds.device
|
| 362 |
+
)
|
| 363 |
+
|
| 364 |
+
if position_ids is None:
|
| 365 |
+
position_ids = cache_position.unsqueeze(0)
|
| 366 |
+
|
| 367 |
+
causal_mask = create_causal_mask(
|
| 368 |
+
config=self.config,
|
| 369 |
+
input_embeds=inputs_embeds,
|
| 370 |
+
attention_mask=attention_mask,
|
| 371 |
+
cache_position=cache_position,
|
| 372 |
+
past_key_values=past_key_values,
|
| 373 |
+
position_ids=position_ids,
|
| 374 |
+
)
|
| 375 |
+
|
| 376 |
+
hidden_states = inputs_embeds
|
| 377 |
+
position_embeddings = self.rotary_emb(hidden_states, position_ids)
|
| 378 |
+
|
| 379 |
+
for decoder_layer in self.layers[: self.config.num_hidden_layers]:
|
| 380 |
+
hidden_states = decoder_layer(
|
| 381 |
+
hidden_states,
|
| 382 |
+
attention_mask=causal_mask,
|
| 383 |
+
position_ids=position_ids,
|
| 384 |
+
past_key_values=past_key_values,
|
| 385 |
+
cache_position=cache_position,
|
| 386 |
+
position_embeddings=position_embeddings,
|
| 387 |
+
**kwargs,
|
| 388 |
+
)
|
| 389 |
+
|
| 390 |
+
hidden_states = self.norm(hidden_states)
|
| 391 |
+
return BaseModelOutputWithPast(
|
| 392 |
+
last_hidden_state=hidden_states,
|
| 393 |
+
past_key_values=past_key_values,
|
| 394 |
+
)
|
| 395 |
+
|
| 396 |
+
|
| 397 |
+
@auto_docstring
|
| 398 |
+
class Olmo2NoQKNormPrenormForCausalLM(Olmo2NoQKNormPrenormPreTrainedModel, GenerationMixin):
|
| 399 |
+
_tied_weights_keys = ["lm_head.weight"]
|
| 400 |
+
_tp_plan = {"lm_head": "colwise_rep"}
|
| 401 |
+
_pp_plan = {"lm_head": (["hidden_states"], ["logits"])}
|
| 402 |
+
|
| 403 |
+
def __init__(self, config):
|
| 404 |
+
super().__init__(config)
|
| 405 |
+
self.model = Olmo2NoQKNormPrenormModel(config)
|
| 406 |
+
self.vocab_size = config.vocab_size
|
| 407 |
+
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
| 408 |
+
|
| 409 |
+
# Initialize weights and apply final processing
|
| 410 |
+
self.post_init()
|
| 411 |
+
|
| 412 |
+
@can_return_tuple
|
| 413 |
+
@auto_docstring
|
| 414 |
+
def forward(
|
| 415 |
+
self,
|
| 416 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 417 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 418 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 419 |
+
past_key_values: Optional[Cache] = None,
|
| 420 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 421 |
+
labels: Optional[torch.LongTensor] = None,
|
| 422 |
+
use_cache: Optional[bool] = None,
|
| 423 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 424 |
+
logits_to_keep: Union[int, torch.Tensor] = 0,
|
| 425 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 426 |
+
) -> CausalLMOutputWithPast:
|
| 427 |
+
r"""
|
| 428 |
+
Example:
|
| 429 |
+
|
| 430 |
+
```python
|
| 431 |
+
>>> from transformers import AutoTokenizer, Olmo2NoQKNormPrenormForCausalLM
|
| 432 |
+
|
| 433 |
+
>>> model = Olmo2NoQKNormPrenormForCausalLM.from_pretrained("meta-olmo2_noqknorm_prenorm/Olmo2NoQKNormPrenorm-2-7b-hf")
|
| 434 |
+
>>> tokenizer = AutoTokenizer.from_pretrained("meta-olmo2_noqknorm_prenorm/Olmo2NoQKNormPrenorm-2-7b-hf")
|
| 435 |
+
|
| 436 |
+
>>> prompt = "Hey, are you conscious? Can you talk to me?"
|
| 437 |
+
>>> inputs = tokenizer(prompt, return_tensors="pt")
|
| 438 |
+
|
| 439 |
+
>>> # Generate
|
| 440 |
+
>>> generate_ids = model.generate(inputs.input_ids, max_length=30)
|
| 441 |
+
>>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
| 442 |
+
"Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
|
| 443 |
+
```"""
|
| 444 |
+
outputs: BaseModelOutputWithPast = self.model(
|
| 445 |
+
input_ids=input_ids,
|
| 446 |
+
attention_mask=attention_mask,
|
| 447 |
+
position_ids=position_ids,
|
| 448 |
+
past_key_values=past_key_values,
|
| 449 |
+
inputs_embeds=inputs_embeds,
|
| 450 |
+
use_cache=use_cache,
|
| 451 |
+
cache_position=cache_position,
|
| 452 |
+
**kwargs,
|
| 453 |
+
)
|
| 454 |
+
|
| 455 |
+
hidden_states = outputs.last_hidden_state
|
| 456 |
+
# Only compute necessary logits, and do not upcast them to float if we are not computing the loss
|
| 457 |
+
slice_indices = slice(-logits_to_keep, None) if isinstance(logits_to_keep, int) else logits_to_keep
|
| 458 |
+
logits = self.lm_head(hidden_states[:, slice_indices, :])
|
| 459 |
+
|
| 460 |
+
loss = None
|
| 461 |
+
if labels is not None:
|
| 462 |
+
loss = self.loss_function(logits=logits, labels=labels, vocab_size=self.config.vocab_size, **kwargs)
|
| 463 |
+
|
| 464 |
+
return CausalLMOutputWithPast(
|
| 465 |
+
loss=loss,
|
| 466 |
+
logits=logits,
|
| 467 |
+
past_key_values=outputs.past_key_values,
|
| 468 |
+
hidden_states=outputs.hidden_states,
|
| 469 |
+
attentions=outputs.attentions,
|
| 470 |
+
)
|
| 471 |
+
|
| 472 |
+
|
| 473 |
+
__all__ = ["Olmo2NoQKNormPrenormForCausalLM", "Olmo2NoQKNormPrenormModel", "Olmo2NoQKNormPrenormPreTrainedModel"]
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"eos_token": "<|endoftext|>",
|
| 3 |
+
"pad_token": "<|pad|>",
|
| 4 |
+
"unk_token": {
|
| 5 |
+
"content": "<|endoftext|>",
|
| 6 |
+
"lstrip": false,
|
| 7 |
+
"normalized": false,
|
| 8 |
+
"rstrip": false,
|
| 9 |
+
"single_word": false
|
| 10 |
+
}
|
| 11 |
+
}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"added_tokens_decoder": {
|
| 4 |
+
"100256": {
|
| 5 |
+
"content": "<|extra_id_0|>",
|
| 6 |
+
"lstrip": false,
|
| 7 |
+
"normalized": false,
|
| 8 |
+
"rstrip": false,
|
| 9 |
+
"single_word": false,
|
| 10 |
+
"special": false
|
| 11 |
+
},
|
| 12 |
+
"100257": {
|
| 13 |
+
"content": "<|endoftext|>",
|
| 14 |
+
"lstrip": false,
|
| 15 |
+
"normalized": false,
|
| 16 |
+
"rstrip": false,
|
| 17 |
+
"single_word": false,
|
| 18 |
+
"special": true
|
| 19 |
+
},
|
| 20 |
+
"100258": {
|
| 21 |
+
"content": "<|fim_prefix|>",
|
| 22 |
+
"lstrip": false,
|
| 23 |
+
"normalized": false,
|
| 24 |
+
"rstrip": false,
|
| 25 |
+
"single_word": false,
|
| 26 |
+
"special": true
|
| 27 |
+
},
|
| 28 |
+
"100259": {
|
| 29 |
+
"content": "<|fim_middle|>",
|
| 30 |
+
"lstrip": false,
|
| 31 |
+
"normalized": false,
|
| 32 |
+
"rstrip": false,
|
| 33 |
+
"single_word": false,
|
| 34 |
+
"special": true
|
| 35 |
+
},
|
| 36 |
+
"100260": {
|
| 37 |
+
"content": "<|fim_suffix|>",
|
| 38 |
+
"lstrip": false,
|
| 39 |
+
"normalized": false,
|
| 40 |
+
"rstrip": false,
|
| 41 |
+
"single_word": false,
|
| 42 |
+
"special": true
|
| 43 |
+
},
|
| 44 |
+
"100261": {
|
| 45 |
+
"content": "|||PHONE_NUMBER|||",
|
| 46 |
+
"lstrip": false,
|
| 47 |
+
"normalized": false,
|
| 48 |
+
"rstrip": false,
|
| 49 |
+
"single_word": false,
|
| 50 |
+
"special": false
|
| 51 |
+
},
|
| 52 |
+
"100262": {
|
| 53 |
+
"content": "|||EMAIL_ADDRESS|||",
|
| 54 |
+
"lstrip": false,
|
| 55 |
+
"normalized": false,
|
| 56 |
+
"rstrip": false,
|
| 57 |
+
"single_word": false,
|
| 58 |
+
"special": false
|
| 59 |
+
},
|
| 60 |
+
"100263": {
|
| 61 |
+
"content": "|||IP_ADDRESS|||",
|
| 62 |
+
"lstrip": false,
|
| 63 |
+
"normalized": false,
|
| 64 |
+
"rstrip": false,
|
| 65 |
+
"single_word": false,
|
| 66 |
+
"special": false
|
| 67 |
+
},
|
| 68 |
+
"100264": {
|
| 69 |
+
"content": "<|im_start|>",
|
| 70 |
+
"lstrip": false,
|
| 71 |
+
"normalized": false,
|
| 72 |
+
"rstrip": false,
|
| 73 |
+
"single_word": false,
|
| 74 |
+
"special": true
|
| 75 |
+
},
|
| 76 |
+
"100265": {
|
| 77 |
+
"content": "<|im_end|>",
|
| 78 |
+
"lstrip": false,
|
| 79 |
+
"normalized": false,
|
| 80 |
+
"rstrip": false,
|
| 81 |
+
"single_word": false,
|
| 82 |
+
"special": true
|
| 83 |
+
},
|
| 84 |
+
"100266": {
|
| 85 |
+
"content": "<|extra_id_1|>",
|
| 86 |
+
"lstrip": false,
|
| 87 |
+
"normalized": false,
|
| 88 |
+
"rstrip": false,
|
| 89 |
+
"single_word": false,
|
| 90 |
+
"special": false
|
| 91 |
+
},
|
| 92 |
+
"100267": {
|
| 93 |
+
"content": "<|extra_id_2|>",
|
| 94 |
+
"lstrip": false,
|
| 95 |
+
"normalized": false,
|
| 96 |
+
"rstrip": false,
|
| 97 |
+
"single_word": false,
|
| 98 |
+
"special": false
|
| 99 |
+
},
|
| 100 |
+
"100268": {
|
| 101 |
+
"content": "<|extra_id_3|>",
|
| 102 |
+
"lstrip": false,
|
| 103 |
+
"normalized": false,
|
| 104 |
+
"rstrip": false,
|
| 105 |
+
"single_word": false,
|
| 106 |
+
"special": false
|
| 107 |
+
},
|
| 108 |
+
"100269": {
|
| 109 |
+
"content": "<|extra_id_4|>",
|
| 110 |
+
"lstrip": false,
|
| 111 |
+
"normalized": false,
|
| 112 |
+
"rstrip": false,
|
| 113 |
+
"single_word": false,
|
| 114 |
+
"special": false
|
| 115 |
+
},
|
| 116 |
+
"100270": {
|
| 117 |
+
"content": "<|extra_id_5|>",
|
| 118 |
+
"lstrip": false,
|
| 119 |
+
"normalized": false,
|
| 120 |
+
"rstrip": false,
|
| 121 |
+
"single_word": false,
|
| 122 |
+
"special": false
|
| 123 |
+
},
|
| 124 |
+
"100271": {
|
| 125 |
+
"content": "<|extra_id_6|>",
|
| 126 |
+
"lstrip": false,
|
| 127 |
+
"normalized": false,
|
| 128 |
+
"rstrip": false,
|
| 129 |
+
"single_word": false,
|
| 130 |
+
"special": false
|
| 131 |
+
},
|
| 132 |
+
"100272": {
|
| 133 |
+
"content": "<|extra_id_7|>",
|
| 134 |
+
"lstrip": false,
|
| 135 |
+
"normalized": false,
|
| 136 |
+
"rstrip": false,
|
| 137 |
+
"single_word": false,
|
| 138 |
+
"special": false
|
| 139 |
+
},
|
| 140 |
+
"100273": {
|
| 141 |
+
"content": "<|extra_id_8|>",
|
| 142 |
+
"lstrip": false,
|
| 143 |
+
"normalized": false,
|
| 144 |
+
"rstrip": false,
|
| 145 |
+
"single_word": false,
|
| 146 |
+
"special": false
|
| 147 |
+
},
|
| 148 |
+
"100274": {
|
| 149 |
+
"content": "<|extra_id_9|>",
|
| 150 |
+
"lstrip": false,
|
| 151 |
+
"normalized": false,
|
| 152 |
+
"rstrip": false,
|
| 153 |
+
"single_word": false,
|
| 154 |
+
"special": false
|
| 155 |
+
},
|
| 156 |
+
"100275": {
|
| 157 |
+
"content": "<|extra_id_10|>",
|
| 158 |
+
"lstrip": false,
|
| 159 |
+
"normalized": false,
|
| 160 |
+
"rstrip": false,
|
| 161 |
+
"single_word": false,
|
| 162 |
+
"special": false
|
| 163 |
+
},
|
| 164 |
+
"100276": {
|
| 165 |
+
"content": "<|endofprompt|>",
|
| 166 |
+
"lstrip": false,
|
| 167 |
+
"normalized": false,
|
| 168 |
+
"rstrip": false,
|
| 169 |
+
"single_word": false,
|
| 170 |
+
"special": true
|
| 171 |
+
},
|
| 172 |
+
"100277": {
|
| 173 |
+
"content": "<|pad|>",
|
| 174 |
+
"lstrip": false,
|
| 175 |
+
"normalized": false,
|
| 176 |
+
"rstrip": false,
|
| 177 |
+
"single_word": false,
|
| 178 |
+
"special": true
|
| 179 |
+
}
|
| 180 |
+
},
|
| 181 |
+
"bos_token": null,
|
| 182 |
+
"clean_up_tokenization_spaces": false,
|
| 183 |
+
"eos_token": "<|endoftext|>",
|
| 184 |
+
"extra_special_tokens": {},
|
| 185 |
+
"model_max_length": 4096,
|
| 186 |
+
"pad_token": "<|pad|>",
|
| 187 |
+
"tokenizer_class": "GPT2Tokenizer",
|
| 188 |
+
"unk_token": "<|endoftext|>"
|
| 189 |
+
}
|
vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|