yujiepan commited on
Commit
461377f
·
verified ·
1 Parent(s): 6dbacea

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ base_model:
4
+ - allenai/Olmo-3-32B-Think
5
+ ---
6
+
7
+ This tiny model is intended for debugging. It is randomly initialized using the configuration adapted from [allenai/Olmo-3-32B-Think](https://huggingface.co/allenai/Olmo-3-32B-Think).
8
+
9
+ ### Example usage:
10
+
11
+ ```python
12
+ import os
13
+ import re
14
+
15
+ import torch
16
+ from transformers import AutoModelForCausalLM, AutoTokenizer
17
+
18
+ model_id = "yujiepan/olmo-3-tiny-random"
19
+
20
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
21
+ model = AutoModelForCausalLM.from_pretrained(
22
+ model_id, device_map="auto", torch_dtype=torch.bfloat16)
23
+ messages = [
24
+ {"role": "user", "content": "How to make pasta?" * 1500},
25
+ ]
26
+ inputs = tokenizer.apply_chat_template(
27
+ messages,
28
+ tokenize=True,
29
+ add_generation_prompt=True,
30
+ return_tensors="pt",
31
+ )['input_ids']
32
+ print(inputs.shape)
33
+ outputs = model.generate(inputs.to(
34
+ model.device), max_new_tokens=32)
35
+ print(outputs)
36
+ ```
37
+
38
+ ### Codes to create this repo:
39
+
40
+ ```python
41
+ import json
42
+ from pathlib import Path
43
+
44
+ import accelerate
45
+ import torch
46
+ from huggingface_hub import file_exists, hf_hub_download
47
+ from transformers import (
48
+ AutoConfig,
49
+ AutoModelForCausalLM,
50
+ AutoProcessor,
51
+ GenerationConfig,
52
+ set_seed,
53
+ )
54
+
55
+ source_model_id = "allenai/Olmo-3-32B-Think"
56
+ save_folder = "/tmp/yujiepan/olmo-3-tiny-random"
57
+
58
+ processor = AutoProcessor.from_pretrained(
59
+ source_model_id, trust_remote_code=True)
60
+ processor.save_pretrained(save_folder)
61
+
62
+ with open(hf_hub_download(source_model_id, filename='config.json', repo_type='model'), 'r', encoding='utf-8') as f:
63
+ config_json = json.load(f)
64
+ config_json['hidden_size'] = 8
65
+ config_json['head_dim'] = 32 # vllm requirement
66
+ config_json['intermediate_size'] = 32
67
+ config_json['num_attention_heads'] = 8
68
+ config_json['num_hidden_layers'] = 2
69
+ config_json['num_key_value_heads'] = 4 # better support tensor parallel
70
+ config_json['tie_word_embeddings'] = False
71
+ config_json['layer_types'] = ['sliding_attention', 'full_attention']
72
+ with open(f"{save_folder}/config.json", "w", encoding='utf-8') as f:
73
+ json.dump(config_json, f, indent=2)
74
+
75
+ config = AutoConfig.from_pretrained(
76
+ save_folder,
77
+ trust_remote_code=True,
78
+ )
79
+ print(config)
80
+ torch.set_default_dtype(torch.bfloat16)
81
+ model = AutoModelForCausalLM.from_config(config, trust_remote_code=True)
82
+ torch.set_default_dtype(torch.float32)
83
+ if file_exists(filename="generation_config.json", repo_id=source_model_id, repo_type='model'):
84
+ model.generation_config = GenerationConfig.from_pretrained(
85
+ source_model_id, trust_remote_code=True,
86
+ )
87
+ model.generation_config.do_sample = True
88
+ set_seed(42)
89
+ model = model.cpu() # cpu is more stable for random initialization across machines
90
+ with torch.no_grad():
91
+ for name, p in sorted(model.named_parameters()):
92
+ torch.nn.init.normal_(p, 0, 0.1)
93
+ print(name, p.shape)
94
+ model.save_pretrained(save_folder)
95
+ ```
96
+
97
+ ### Printing the model:
98
+
99
+ ```text
100
+ Olmo3ForCausalLM(
101
+ (model): Olmo3Model(
102
+ (embed_tokens): Embedding(100278, 8, padding_idx=100277)
103
+ (layers): ModuleList(
104
+ (0-1): 2 x Olmo3DecoderLayer(
105
+ (self_attn): Olmo3Attention(
106
+ (q_proj): Linear(in_features=8, out_features=256, bias=False)
107
+ (k_proj): Linear(in_features=8, out_features=128, bias=False)
108
+ (v_proj): Linear(in_features=8, out_features=128, bias=False)
109
+ (o_proj): Linear(in_features=256, out_features=8, bias=False)
110
+ (q_norm): Olmo3RMSNorm((256,), eps=1e-06)
111
+ (k_norm): Olmo3RMSNorm((128,), eps=1e-06)
112
+ )
113
+ (mlp): Olmo3MLP(
114
+ (gate_proj): Linear(in_features=8, out_features=32, bias=False)
115
+ (up_proj): Linear(in_features=8, out_features=32, bias=False)
116
+ (down_proj): Linear(in_features=32, out_features=8, bias=False)
117
+ (act_fn): SiLUActivation()
118
+ )
119
+ (post_attention_layernorm): Olmo3RMSNorm((8,), eps=1e-06)
120
+ (post_feedforward_layernorm): Olmo3RMSNorm((8,), eps=1e-06)
121
+ )
122
+ )
123
+ (norm): Olmo3RMSNorm((8,), eps=1e-06)
124
+ (rotary_emb): Olmo3RotaryEmbedding()
125
+ )
126
+ (lm_head): Linear(in_features=8, out_features=100278, bias=False)
127
+ )
128
+ ```
chat_template.jinja ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {% set has_system = messages|selectattr('role', 'equalto', 'system')|list|length > 0 %}{% if not has_system %}{{ '<|im_start|>system
2
+ You are a helpful AI assistant.<|im_end|>
3
+ ' }}{% endif %}{% for message in messages %}{% if message['role'] == 'system' %}{{ '<|im_start|>system
4
+ ' + message['content'] }}{% if message.get('functions', none) is not none %}{{ ' <functions>' + message['functions'] + '</functions><|im_end|>
5
+ ' }}{% else %}{{ ' You do not currently have access to any functions. <functions></functions><|im_end|>
6
+ ' }}{% endif %}{% elif message['role'] == 'user' %}{% if message.get('functions', none) is not none %}{{ '<|im_start|>user
7
+ ' + message['content'] + '
8
+ ' + '<functions>' + message['functions'] + '</functions><|im_end|>
9
+ ' }}{% else %}{{ '<|im_start|>user
10
+ ' + message['content'] + '<|im_end|>
11
+ ' }}{% endif %}{% elif message['role'] == 'assistant' %}{{ '<|im_start|>assistant
12
+ ' }}{% if message.get('content', none) is not none %}{{ message['content'] }}{% endif %}{% if message.get('function_calls', none) is not none %}{{ '<function_calls>' + message['function_calls'] + '</function_calls>' }}{% endif %}{% if not loop.last %}{{ '<|im_end|>' + '
13
+ ' }}{% else %}{{ eos_token }}{% endif %}{% elif message['role'] == 'environment' %}{{ '<|im_start|>environment
14
+ ' + message['content'] + '<|im_end|>
15
+ ' }}{% endif %}{% if loop.last and add_generation_prompt %}{{ '<|im_start|>assistant
16
+ <think>' }}{% endif %}{% endfor %}
config.json ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Olmo3ForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "dtype": "bfloat16",
8
+ "eos_token_id": 100257,
9
+ "head_dim": 32,
10
+ "hidden_act": "silu",
11
+ "hidden_size": 8,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 32,
14
+ "layer_types": [
15
+ "sliding_attention",
16
+ "full_attention"
17
+ ],
18
+ "max_position_embeddings": 65536,
19
+ "model_type": "olmo3",
20
+ "num_attention_heads": 8,
21
+ "num_hidden_layers": 2,
22
+ "num_key_value_heads": 4,
23
+ "pad_token_id": 100277,
24
+ "rms_norm_eps": 1e-06,
25
+ "rope_parameters": {
26
+ "attention_factor": 1.2079441541679836,
27
+ "beta_fast": 32,
28
+ "beta_slow": 1,
29
+ "factor": 8.0,
30
+ "original_max_position_embeddings": 8192,
31
+ "rope_theta": 500000,
32
+ "rope_type": "yarn"
33
+ },
34
+ "rope_theta": 500000,
35
+ "sliding_window": 4096,
36
+ "tie_word_embeddings": false,
37
+ "transformers_version": "5.0.0.dev0",
38
+ "use_cache": false,
39
+ "vocab_size": 100278
40
+ }
generation_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "do_sample": true,
4
+ "eos_token_id": 100257,
5
+ "max_new_tokens": 32768,
6
+ "pad_token_id": 100277,
7
+ "temperature": 0.6,
8
+ "top_p": 0.95,
9
+ "transformers_version": "5.0.0.dev0"
10
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:55dcaa7c53df7d0abe1d51e1729c603a752a767e287be2a355cd5288f25f7dc6
3
+ size 3240800
special_tokens_map.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<|endoftext|>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "<|endoftext|>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "<|pad|>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "unk_token": {
24
+ "content": "<|endoftext|>",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ }
30
+ }
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": "<|endoftext|>",
182
+ "clean_up_tokenization_spaces": false,
183
+ "eos_token": "<|endoftext|>",
184
+ "extra_special_tokens": {},
185
+ "model_max_length": 65536,
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