helenai commited on
Commit
4c4020b
·
verified ·
1 Parent(s): 810dd97

Upload folder using huggingface_hub

Browse files
README.md CHANGED
@@ -1,3 +1,5 @@
 
 
1
  Code for creating the tiny model:
2
 
3
  ```python
@@ -6,30 +8,34 @@ import torch
6
  torch.set_default_dtype(torch.float32)
7
 
8
  import os
 
9
 
10
- from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer, set_seed
 
11
 
12
  # === Settings ===
13
- model_id = "microsoft/Phi-4-mini-instruct"
14
- output_dir = "phi-4-mini-tiny-random"
 
 
15
 
16
  set_seed(0)
17
 
18
  # === Step 1: Define tiny model config ===
 
19
  config = AutoConfig.from_pretrained(model_id)
20
 
21
- # the "originally" values are for Phi-4-mini-instruct
22
- config.num_hidden_layers = 4 # originally 32
23
- config.num_attention_heads = 4 # originally 24
24
- config.num_key_value_heads = 2 # originally 8
25
- config.hidden_size = 64 # originally 3072, this has the largest influence on model size
26
- config.intermediate_size = 256 # originally 8192; MLP layer
27
- config.initializer_range = 0.1 # originally 0.02; without this change, phi-4-mini model outputs collapse with larger inputs
28
 
29
- # Keep 6 RoPE factors (originally 48). Adjust config.hidden_size when adjusting this.
30
  if config.rope_scaling:
31
- config.rope_scaling["short_factor"] = config.rope_scaling["short_factor"][::8]
32
- config.rope_scaling["long_factor"] = config.rope_scaling["long_factor"][::8]
33
 
34
  # === Step 2: Create model from config ===
35
  model = AutoModelForCausalLM.from_config(config)
@@ -45,4 +51,4 @@ tokenizer = AutoTokenizer.from_pretrained(model_id)
45
  os.makedirs(output_dir, exist_ok=True)
46
  model.save_pretrained(output_dir)
47
  tokenizer.save_pretrained(output_dir)
48
- ```
 
1
+ Tiny random model with Phi3 architecture based on microsoft/Phi-3.5-mini-instruct, including longrope config
2
+
3
  Code for creating the tiny model:
4
 
5
  ```python
 
8
  torch.set_default_dtype(torch.float32)
9
 
10
  import os
11
+ from pathlib import Path
12
 
13
+ from optimum.intel import OVModelForCausalLM
14
+ from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer, set_seed, Phi3ForCausalLM
15
 
16
  # === Settings ===
17
+
18
+ model_id = "microsoft/Phi-3.5-mini-instruct"
19
+ output_dir = "phi-3.5-mini-tiny-random"
20
+ ov_output_dir = output_dir + "-ov"
21
 
22
  set_seed(0)
23
 
24
  # === Step 1: Define tiny model config ===
25
+
26
  config = AutoConfig.from_pretrained(model_id)
27
 
28
+ config.num_hidden_layers = 4
29
+ config.num_attention_heads = 4
30
+ config.num_key_value_heads = 2
31
+ config.hidden_size = 96
32
+ config.intermediate_size = 256
33
+ config.initializer_range = 0.1
 
34
 
35
+ # Keep fewer RoPE factors. Adjust config.hidden_size when adjusting this.
36
  if config.rope_scaling:
37
+ config.rope_scaling["short_factor"] = config.rope_scaling["short_factor"][::4]
38
+ config.rope_scaling["long_factor"] = config.rope_scaling["long_factor"][::4]
39
 
40
  # === Step 2: Create model from config ===
41
  model = AutoModelForCausalLM.from_config(config)
 
51
  os.makedirs(output_dir, exist_ok=True)
52
  model.save_pretrained(output_dir)
53
  tokenizer.save_pretrained(output_dir)
54
+ ```
added_tokens.json CHANGED
@@ -1,12 +1,13 @@
1
  {
2
- "<|/tool_call|>": 200026,
3
- "<|/tool|>": 200024,
4
- "<|assistant|>": 200019,
5
- "<|end|>": 200020,
6
- "<|system|>": 200022,
7
- "<|tag|>": 200028,
8
- "<|tool_call|>": 200025,
9
- "<|tool_response|>": 200027,
10
- "<|tool|>": 200023,
11
- "<|user|>": 200021
 
12
  }
 
1
  {
2
+ "<|assistant|>": 32001,
3
+ "<|endoftext|>": 32000,
4
+ "<|end|>": 32007,
5
+ "<|placeholder1|>": 32002,
6
+ "<|placeholder2|>": 32003,
7
+ "<|placeholder3|>": 32004,
8
+ "<|placeholder4|>": 32005,
9
+ "<|placeholder5|>": 32008,
10
+ "<|placeholder6|>": 32009,
11
+ "<|system|>": 32006,
12
+ "<|user|>": 32010
13
  }
chat_template.jinja CHANGED
@@ -1 +1,8 @@
1
- {% for message in messages %}{% if message['role'] == 'system' and 'tools' in message and message['tools'] is not none %}{{ '<|' + message['role'] + '|>' + message['content'] + '<|tool|>' + message['tools'] + '<|/tool|>' + '<|end|>' }}{% else %}{{ '<|' + message['role'] + '|>' + message['content'] + '<|end|>' }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|assistant|>' }}{% else %}{{ eos_token }}{% endif %}
 
 
 
 
 
 
 
 
1
+ {% for message in messages %}{% if message['role'] == 'system' and message['content'] %}{{'<|system|>
2
+ ' + message['content'] + '<|end|>
3
+ '}}{% elif message['role'] == 'user' %}{{'<|user|>
4
+ ' + message['content'] + '<|end|>
5
+ '}}{% elif message['role'] == 'assistant' %}{{'<|assistant|>
6
+ ' + message['content'] + '<|end|>
7
+ '}}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|assistant|>
8
+ ' }}{% else %}{{ eos_token }}{% endif %}
config.json CHANGED
@@ -1,59 +1,67 @@
1
  {
 
2
  "architectures": [
3
  "Phi3ForCausalLM"
4
  ],
5
  "attention_bias": false,
6
  "attention_dropout": 0.0,
7
  "auto_map": {
8
- "AutoConfig": "configuration_phi3.Phi3Config",
9
- "AutoModelForCausalLM": "modeling_phi3.Phi3ForCausalLM",
10
- "AutoTokenizer": "Xenova/gpt-4o"
11
  },
12
- "bos_token_id": 199999,
13
  "embd_pdrop": 0.0,
14
- "eos_token_id": 199999,
15
- "full_attn_mod": 1,
16
  "hidden_act": "silu",
17
- "hidden_size": 64,
18
  "initializer_range": 0.1,
19
  "intermediate_size": 256,
20
- "interpolate_factor": 1,
21
- "lm_head_bias": false,
22
  "max_position_embeddings": 131072,
23
- "mlp_bias": false,
24
  "model_type": "phi3",
25
  "num_attention_heads": 4,
26
  "num_hidden_layers": 4,
27
  "num_key_value_heads": 2,
28
  "original_max_position_embeddings": 4096,
29
- "pad_token_id": 199999,
30
- "partial_rotary_factor": 0.75,
31
  "resid_pdrop": 0.0,
32
  "rms_norm_eps": 1e-05,
33
  "rope_scaling": {
34
  "long_factor": [
35
- 1,
36
- 2.446418898,
37
- 5.984965424,
38
- 14.64173252,
39
- 32.1,
40
- 32.71
 
 
 
 
 
 
41
  ],
42
  "short_factor": [
43
  1.0,
44
- 1.0,
45
- 1.0,
46
- 1.0,
47
- 1.0,
48
- 1.0
 
 
 
 
 
 
49
  ],
50
  "type": "longrope"
51
  },
52
  "rope_theta": 10000.0,
53
  "sliding_window": 262144,
54
- "tie_word_embeddings": true,
55
  "torch_dtype": "bfloat16",
56
- "transformers_version": "4.55.4",
57
  "use_cache": true,
58
- "vocab_size": 200064
59
  }
 
1
  {
2
+ "_name_or_path": "microsoft/Phi-3.5-mini-instruct",
3
  "architectures": [
4
  "Phi3ForCausalLM"
5
  ],
6
  "attention_bias": false,
7
  "attention_dropout": 0.0,
8
  "auto_map": {
9
+ "AutoConfig": "microsoft/Phi-3.5-mini-instruct--configuration_phi3.Phi3Config",
10
+ "AutoModelForCausalLM": "microsoft/Phi-3.5-mini-instruct--modeling_phi3.Phi3ForCausalLM"
 
11
  },
12
+ "bos_token_id": 1,
13
  "embd_pdrop": 0.0,
14
+ "eos_token_id": 32000,
 
15
  "hidden_act": "silu",
16
+ "hidden_size": 96,
17
  "initializer_range": 0.1,
18
  "intermediate_size": 256,
 
 
19
  "max_position_embeddings": 131072,
 
20
  "model_type": "phi3",
21
  "num_attention_heads": 4,
22
  "num_hidden_layers": 4,
23
  "num_key_value_heads": 2,
24
  "original_max_position_embeddings": 4096,
25
+ "pad_token_id": 32000,
26
+ "partial_rotary_factor": 1.0,
27
  "resid_pdrop": 0.0,
28
  "rms_norm_eps": 1e-05,
29
  "rope_scaling": {
30
  "long_factor": [
31
+ 1.0800000429153442,
32
+ 1.5899999141693115,
33
+ 3.2300000190734863,
34
+ 7.700000286102295,
35
+ 24.46000099182129,
36
+ 32.590003967285156,
37
+ 50.340003967285156,
38
+ 58.21000289916992,
39
+ 62.71000289916992,
40
+ 63.93000411987305,
41
+ 64.06999969482422,
42
+ 64.4800033569336
43
  ],
44
  "short_factor": [
45
  1.0,
46
+ 1.0499999523162842,
47
+ 1.0499999523162842,
48
+ 1.1599998474121094,
49
+ 1.339999794960022,
50
+ 1.8499997854232788,
51
+ 1.9899996519088745,
52
+ 2.0199997425079346,
53
+ 2.0299997329711914,
54
+ 2.0299997329711914,
55
+ 2.0799996852874756,
56
+ 2.5899994373321533
57
  ],
58
  "type": "longrope"
59
  },
60
  "rope_theta": 10000.0,
61
  "sliding_window": 262144,
62
+ "tie_word_embeddings": false,
63
  "torch_dtype": "bfloat16",
64
+ "transformers_version": "4.49.0",
65
  "use_cache": true,
66
+ "vocab_size": 32064
67
  }
generation_config.json CHANGED
@@ -1,7 +1,7 @@
1
  {
2
  "_from_model_config": true,
3
- "bos_token_id": 199999,
4
- "eos_token_id": 199999,
5
- "pad_token_id": 199999,
6
- "transformers_version": "4.55.4"
7
  }
 
1
  {
2
  "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "eos_token_id": 32000,
5
+ "pad_token_id": 32000,
6
+ "transformers_version": "4.49.0"
7
  }
model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:dd0f9279935f9954e78ee211b05cf0af55be72ae6ca265315baee0d7b1674ad7
3
- size 26103712
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:74cead14dfeca6601724692aa0bd751abe8708cde35894a3d814cc67f83bf98e
3
+ size 13128248
special_tokens_map.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "bos_token": {
3
- "content": "<|endoftext|>",
4
  "lstrip": false,
5
  "normalized": false,
6
  "rstrip": false,
@@ -21,7 +21,7 @@
21
  "single_word": false
22
  },
23
  "unk_token": {
24
- "content": "<|endoftext|>",
25
  "lstrip": false,
26
  "normalized": false,
27
  "rstrip": false,
 
1
  {
2
  "bos_token": {
3
+ "content": "<s>",
4
  "lstrip": false,
5
  "normalized": false,
6
  "rstrip": false,
 
21
  "single_word": false
22
  },
23
  "unk_token": {
24
+ "content": "<unk>",
25
  "lstrip": false,
26
  "normalized": false,
27
  "rstrip": false,
tokenizer.json CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:382cc235b56c725945e149cc25f191da667c836655efd0857b004320e90e91ea
3
- size 15524095
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3cb815b904d82b82b25dcd90edd00e71a5ee5443472ad611bcb84f1339300647
3
+ size 3620657
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9e556afd44213b6bd1be2b850ebbbd98f5481437a8021afaf58ee7fb1818d347
3
+ size 499723
tokenizer_config.json CHANGED
@@ -1,25 +1,41 @@
1
  {
2
  "add_bos_token": false,
3
  "add_eos_token": false,
4
- "add_prefix_space": false,
5
  "added_tokens_decoder": {
6
- "199999": {
7
- "content": "<|endoftext|>",
8
  "lstrip": false,
9
  "normalized": false,
10
  "rstrip": false,
11
  "single_word": false,
12
  "special": true
13
  },
14
- "200018": {
15
- "content": "<|endofprompt|>",
16
  "lstrip": false,
17
  "normalized": false,
18
  "rstrip": false,
19
  "single_word": false,
20
  "special": true
21
  },
22
- "200019": {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  "content": "<|assistant|>",
24
  "lstrip": false,
25
  "normalized": false,
@@ -27,72 +43,72 @@
27
  "single_word": false,
28
  "special": true
29
  },
30
- "200020": {
31
- "content": "<|end|>",
32
  "lstrip": false,
33
  "normalized": false,
34
  "rstrip": true,
35
  "single_word": false,
36
  "special": true
37
  },
38
- "200021": {
39
- "content": "<|user|>",
40
  "lstrip": false,
41
  "normalized": false,
42
  "rstrip": true,
43
  "single_word": false,
44
  "special": true
45
  },
46
- "200022": {
47
- "content": "<|system|>",
48
  "lstrip": false,
49
  "normalized": false,
50
  "rstrip": true,
51
  "single_word": false,
52
  "special": true
53
  },
54
- "200023": {
55
- "content": "<|tool|>",
56
  "lstrip": false,
57
  "normalized": false,
58
  "rstrip": true,
59
  "single_word": false,
60
- "special": false
61
  },
62
- "200024": {
63
- "content": "<|/tool|>",
64
  "lstrip": false,
65
  "normalized": false,
66
  "rstrip": true,
67
  "single_word": false,
68
- "special": false
69
  },
70
- "200025": {
71
- "content": "<|tool_call|>",
72
  "lstrip": false,
73
  "normalized": false,
74
  "rstrip": true,
75
  "single_word": false,
76
- "special": false
77
  },
78
- "200026": {
79
- "content": "<|/tool_call|>",
80
  "lstrip": false,
81
  "normalized": false,
82
  "rstrip": true,
83
  "single_word": false,
84
- "special": false
85
  },
86
- "200027": {
87
- "content": "<|tool_response|>",
88
  "lstrip": false,
89
  "normalized": false,
90
  "rstrip": true,
91
  "single_word": false,
92
- "special": false
93
  },
94
- "200028": {
95
- "content": "<|tag|>",
96
  "lstrip": false,
97
  "normalized": false,
98
  "rstrip": true,
@@ -100,12 +116,17 @@
100
  "special": true
101
  }
102
  },
103
- "bos_token": "<|endoftext|>",
 
104
  "clean_up_tokenization_spaces": false,
105
  "eos_token": "<|endoftext|>",
106
  "extra_special_tokens": {},
 
107
  "model_max_length": 131072,
108
  "pad_token": "<|endoftext|>",
109
- "tokenizer_class": "GPT2Tokenizer",
110
- "unk_token": "<|endoftext|>"
 
 
 
111
  }
 
1
  {
2
  "add_bos_token": false,
3
  "add_eos_token": false,
4
+ "add_prefix_space": null,
5
  "added_tokens_decoder": {
6
+ "0": {
7
+ "content": "<unk>",
8
  "lstrip": false,
9
  "normalized": false,
10
  "rstrip": false,
11
  "single_word": false,
12
  "special": true
13
  },
14
+ "1": {
15
+ "content": "<s>",
16
  "lstrip": false,
17
  "normalized": false,
18
  "rstrip": false,
19
  "single_word": false,
20
  "special": true
21
  },
22
+ "2": {
23
+ "content": "</s>",
24
+ "lstrip": false,
25
+ "normalized": false,
26
+ "rstrip": true,
27
+ "single_word": false,
28
+ "special": false
29
+ },
30
+ "32000": {
31
+ "content": "<|endoftext|>",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false,
36
+ "special": true
37
+ },
38
+ "32001": {
39
  "content": "<|assistant|>",
40
  "lstrip": false,
41
  "normalized": false,
 
43
  "single_word": false,
44
  "special": true
45
  },
46
+ "32002": {
47
+ "content": "<|placeholder1|>",
48
  "lstrip": false,
49
  "normalized": false,
50
  "rstrip": true,
51
  "single_word": false,
52
  "special": true
53
  },
54
+ "32003": {
55
+ "content": "<|placeholder2|>",
56
  "lstrip": false,
57
  "normalized": false,
58
  "rstrip": true,
59
  "single_word": false,
60
  "special": true
61
  },
62
+ "32004": {
63
+ "content": "<|placeholder3|>",
64
  "lstrip": false,
65
  "normalized": false,
66
  "rstrip": true,
67
  "single_word": false,
68
  "special": true
69
  },
70
+ "32005": {
71
+ "content": "<|placeholder4|>",
72
  "lstrip": false,
73
  "normalized": false,
74
  "rstrip": true,
75
  "single_word": false,
76
+ "special": true
77
  },
78
+ "32006": {
79
+ "content": "<|system|>",
80
  "lstrip": false,
81
  "normalized": false,
82
  "rstrip": true,
83
  "single_word": false,
84
+ "special": true
85
  },
86
+ "32007": {
87
+ "content": "<|end|>",
88
  "lstrip": false,
89
  "normalized": false,
90
  "rstrip": true,
91
  "single_word": false,
92
+ "special": true
93
  },
94
+ "32008": {
95
+ "content": "<|placeholder5|>",
96
  "lstrip": false,
97
  "normalized": false,
98
  "rstrip": true,
99
  "single_word": false,
100
+ "special": true
101
  },
102
+ "32009": {
103
+ "content": "<|placeholder6|>",
104
  "lstrip": false,
105
  "normalized": false,
106
  "rstrip": true,
107
  "single_word": false,
108
+ "special": true
109
  },
110
+ "32010": {
111
+ "content": "<|user|>",
112
  "lstrip": false,
113
  "normalized": false,
114
  "rstrip": true,
 
116
  "special": true
117
  }
118
  },
119
+ "bos_token": "<s>",
120
+ "chat_template": "{% for message in messages %}{% if message['role'] == 'system' and message['content'] %}{{'<|system|>\n' + message['content'] + '<|end|>\n'}}{% elif message['role'] == 'user' %}{{'<|user|>\n' + message['content'] + '<|end|>\n'}}{% elif message['role'] == 'assistant' %}{{'<|assistant|>\n' + message['content'] + '<|end|>\n'}}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ '<|assistant|>\n' }}{% else %}{{ eos_token }}{% endif %}",
121
  "clean_up_tokenization_spaces": false,
122
  "eos_token": "<|endoftext|>",
123
  "extra_special_tokens": {},
124
+ "legacy": false,
125
  "model_max_length": 131072,
126
  "pad_token": "<|endoftext|>",
127
+ "padding_side": "left",
128
+ "sp_model_kwargs": {},
129
+ "tokenizer_class": "LlamaTokenizer",
130
+ "unk_token": "<unk>",
131
+ "use_default_system_prompt": false
132
  }