yujiepan commited on
Commit
45d961d
·
verified ·
1 Parent(s): d8acf17

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
.meta.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "torch": "2.11.0",
3
+ "transformers": "5.5.0"
4
+ }
README.md ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ base_model:
4
+ - Qwen/Qwen2.5-72B-Instruct
5
+ ---
6
+
7
+ This tiny model is intended for debugging. It is randomly initialized using the configuration adapted from [Qwen/Qwen2.5-72B-Instruct](https://huggingface.co/Qwen/Qwen2.5-72B-Instruct).
8
+
9
+ | File path | Size |
10
+ |------|------|
11
+ | model.safetensors | 4.9MB |
12
+
13
+
14
+ ### Example usage:
15
+
16
+ ```python
17
+ from transformers import pipeline
18
+ model_id = "tiny-random/qwen2.5"
19
+ pipe = pipeline(
20
+ "text-generation", model=model_id,
21
+ trust_remote_code=True, max_new_tokens=8,
22
+ )
23
+ print(pipe("Hello World!"))
24
+
25
+ from transformers import AutoModelForCausalLM, AutoTokenizer
26
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
27
+ model = AutoModelForCausalLM.from_pretrained(
28
+ model_id,
29
+ dtype="auto",
30
+ device_map="auto"
31
+ )
32
+ prompt = "Give me a short introduction to large language model."
33
+ messages = [
34
+ {"role": "user", "content": prompt}
35
+ ]
36
+ text = tokenizer.apply_chat_template(
37
+ messages,
38
+ tokenize=False,
39
+ add_generation_prompt=True,
40
+ )
41
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
42
+ generated_ids = model.generate(
43
+ **model_inputs,
44
+ max_new_tokens=32
45
+ )
46
+ output_ids = generated_ids[0].tolist()
47
+ content = tokenizer.decode(output_ids, skip_special_tokens=False)
48
+ print(content)
49
+ ```
50
+
51
+ ### Codes to create this repo:
52
+
53
+ <details>
54
+ <summary>Click to expand</summary>
55
+
56
+ ```python
57
+ import json
58
+ from pathlib import Path
59
+
60
+ import torch
61
+ from huggingface_hub import hf_hub_download
62
+ from transformers import (
63
+ AutoConfig,
64
+ AutoModelForCausalLM,
65
+ AutoTokenizer,
66
+ GenerationConfig,
67
+ pipeline,
68
+ set_seed,
69
+ )
70
+
71
+ source_model_id = "Qwen/Qwen2.5-72B-Instruct"
72
+ save_folder = "/tmp/tiny-random/qwen25"
73
+
74
+ tokenizer = AutoTokenizer.from_pretrained(
75
+ source_model_id, trust_remote_code=True,
76
+ )
77
+ tokenizer.save_pretrained(save_folder)
78
+
79
+ with open(hf_hub_download(source_model_id, filename='config.json', repo_type='model'), 'r', encoding='utf-8') as f:
80
+ config_json: dict = json.load(f)
81
+ config_json.update({
82
+ "num_hidden_layers": 4,
83
+ "hidden_size": 8,
84
+ "intermediate_size": 32,
85
+ "max_window_layers": 2,
86
+ "head_dim": 32,
87
+ "num_attention_heads": 8,
88
+ "num_key_value_heads": 4,
89
+ })
90
+ with open(f"{save_folder}/config.json", "w", encoding='utf-8') as f:
91
+ json.dump(config_json, f, indent=2)
92
+
93
+ config = AutoConfig.from_pretrained(
94
+ save_folder,
95
+ trust_remote_code=True,
96
+ )
97
+ model = AutoModelForCausalLM.from_config(
98
+ config,
99
+ torch_dtype=torch.bfloat16,
100
+ trust_remote_code=True,
101
+ )
102
+ model.generation_config = GenerationConfig.from_pretrained(
103
+ source_model_id, trust_remote_code=True,
104
+ )
105
+ set_seed(42)
106
+ with torch.no_grad():
107
+ for name, p in sorted(model.named_parameters()):
108
+ torch.nn.init.normal_(p, 0, 0.2)
109
+ print(name, p.shape)
110
+ model.save_pretrained(save_folder)
111
+ ```
112
+
113
+ </details>
114
+
115
+
116
+ ### Test environment:
117
+
118
+ - torch: 2.11.0
119
+ - transformers: 5.5.0
chat_template.jinja ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if tools %}
2
+ {{- '<|im_start|>system\n' }}
3
+ {%- if messages[0]['role'] == 'system' %}
4
+ {{- messages[0]['content'] }}
5
+ {%- else %}
6
+ {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}
7
+ {%- endif %}
8
+ {{- "\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
9
+ {%- for tool in tools %}
10
+ {{- "\n" }}
11
+ {{- tool | tojson }}
12
+ {%- endfor %}
13
+ {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
14
+ {%- else %}
15
+ {%- if messages[0]['role'] == 'system' %}
16
+ {{- '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }}
17
+ {%- else %}
18
+ {{- '<|im_start|>system\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n' }}
19
+ {%- endif %}
20
+ {%- endif %}
21
+ {%- for message in messages %}
22
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}
23
+ {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
24
+ {%- elif message.role == "assistant" %}
25
+ {{- '<|im_start|>' + message.role }}
26
+ {%- if message.content %}
27
+ {{- '\n' + message.content }}
28
+ {%- endif %}
29
+ {%- for tool_call in message.tool_calls %}
30
+ {%- if tool_call.function is defined %}
31
+ {%- set tool_call = tool_call.function %}
32
+ {%- endif %}
33
+ {{- '\n<tool_call>\n{"name": "' }}
34
+ {{- tool_call.name }}
35
+ {{- '", "arguments": ' }}
36
+ {{- tool_call.arguments | tojson }}
37
+ {{- '}\n</tool_call>' }}
38
+ {%- endfor %}
39
+ {{- '<|im_end|>\n' }}
40
+ {%- elif message.role == "tool" %}
41
+ {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}
42
+ {{- '<|im_start|>user' }}
43
+ {%- endif %}
44
+ {{- '\n<tool_response>\n' }}
45
+ {{- message.content }}
46
+ {{- '\n</tool_response>' }}
47
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
48
+ {{- '<|im_end|>\n' }}
49
+ {%- endif %}
50
+ {%- endif %}
51
+ {%- endfor %}
52
+ {%- if add_generation_prompt %}
53
+ {{- '<|im_start|>assistant\n' }}
54
+ {%- endif %}
config.json ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen2ForCausalLM"
4
+ ],
5
+ "attention_dropout": 0.0,
6
+ "bos_token_id": 151643,
7
+ "dtype": "bfloat16",
8
+ "eos_token_id": 151645,
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
+ "full_attention",
16
+ "full_attention",
17
+ "full_attention",
18
+ "full_attention"
19
+ ],
20
+ "max_position_embeddings": 32768,
21
+ "max_window_layers": 2,
22
+ "model_type": "qwen2",
23
+ "num_attention_heads": 8,
24
+ "num_hidden_layers": 4,
25
+ "num_key_value_heads": 4,
26
+ "pad_token_id": null,
27
+ "rms_norm_eps": 1e-06,
28
+ "rope_parameters": {
29
+ "rope_theta": 1000000.0,
30
+ "rope_type": "default"
31
+ },
32
+ "sliding_window": null,
33
+ "tie_word_embeddings": false,
34
+ "transformers_version": "5.5.0",
35
+ "use_cache": true,
36
+ "use_sliding_window": false,
37
+ "vocab_size": 152064
38
+ }
generation_config.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 151643,
3
+ "do_sample": true,
4
+ "eos_token_id": [
5
+ 151645,
6
+ 151643
7
+ ],
8
+ "pad_token_id": 151643,
9
+ "repetition_penalty": 1.05,
10
+ "temperature": 0.7,
11
+ "top_k": 20,
12
+ "top_p": 0.8,
13
+ "transformers_version": "5.5.0",
14
+ "trust_remote_code": true
15
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2347b1266fad03235e41d189a0bba43b746abe56c15e83673abed6733e3bbe26
3
+ size 4930912
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3fd169731d2cbde95e10bf356d66d5997fd885dd8dbb6fb4684da3f23b2585d8
3
+ size 11421892
tokenizer_config.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "backend": "tokenizers",
4
+ "bos_token": null,
5
+ "clean_up_tokenization_spaces": false,
6
+ "eos_token": "<|im_end|>",
7
+ "errors": "replace",
8
+ "extra_special_tokens": [
9
+ "<|im_start|>",
10
+ "<|im_end|>",
11
+ "<|object_ref_start|>",
12
+ "<|object_ref_end|>",
13
+ "<|box_start|>",
14
+ "<|box_end|>",
15
+ "<|quad_start|>",
16
+ "<|quad_end|>",
17
+ "<|vision_start|>",
18
+ "<|vision_end|>",
19
+ "<|vision_pad|>",
20
+ "<|image_pad|>",
21
+ "<|video_pad|>"
22
+ ],
23
+ "is_local": false,
24
+ "model_max_length": 131072,
25
+ "pad_token": "<|endoftext|>",
26
+ "split_special_tokens": false,
27
+ "tokenizer_class": "Qwen2Tokenizer",
28
+ "unk_token": null
29
+ }