Mxode commited on
Commit
ae440e5
1 Parent(s): 2bb761c

upload model

Browse files
README.md CHANGED
@@ -1,3 +1,89 @@
1
  ---
2
  license: gpl-3.0
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: gpl-3.0
3
+ language:
4
+ - en
5
  ---
6
+ # NanoLM-1B-Instruct-v1.1
7
+
8
+
9
+ English | [简体中文](README_zh-CN.md)
10
+
11
+
12
+ ## Introduction
13
+
14
+ In order to explore the potential of small models, I have attempted to build a series of them, which are available in the [NanoLM Collections](https://huggingface.co/collections/Mxode/nanolm-66d6d75b4a69536bca2705b2).
15
+
16
+ This is NanoLM-1B-Instruct-v1.1. The model currently supports **English only**.
17
+
18
+
19
+
20
+ ## Model Details
21
+
22
+ | Nano LMs | Non-emb Params | Arch | Layers | Dim | Heads | Seq Len |
23
+ | :----------: | :------------------: | :---: | :----: | :-------: | :---: | :---: |
24
+ | 25M | 15M | MistralForCausalLM | 12 | 312 | 12 | 2K |
25
+ | 70M | 42M | LlamaForCausalLM | 12 | 576 | 9 |2K|
26
+ | 0.3B | 180M | Qwen2ForCausalLM | 12 | 896 | 14 |4K|
27
+ | **1B** | **840M** | **Qwen2ForCausalLM** | **18** | **1536** | **12** | **4K** |
28
+
29
+
30
+
31
+ ## How to use
32
+
33
+ ```python
34
+ import torch
35
+ from transformers import AutoModelForCausalLM, AutoTokenizer
36
+
37
+ model_path = 'Mxode/NanoLM-1B-Instruct-v1.1'
38
+
39
+ model = AutoModelForCausalLM.from_pretrained(model_path).to('cuda:0', torch.bfloat16)
40
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
41
+
42
+
43
+ def get_response(prompt: str, **kwargs):
44
+ generation_args = dict(
45
+ max_new_tokens = kwargs.pop("max_new_tokens", 512),
46
+ do_sample = kwargs.pop("do_sample", True),
47
+ temperature = kwargs.pop("temperature", 0.7),
48
+ top_p = kwargs.pop("top_p", 0.8),
49
+ top_k = kwargs.pop("top_k", 40),
50
+ **kwargs
51
+ )
52
+
53
+ messages = [
54
+ {"role": "system", "content": "You are a helpful assistant."},
55
+ {"role": "user", "content": prompt}
56
+ ]
57
+ text = tokenizer.apply_chat_template(
58
+ messages,
59
+ tokenize=False,
60
+ add_generation_prompt=True
61
+ )
62
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
63
+
64
+ generated_ids = model.generate(model_inputs.input_ids, **generation_args)
65
+ generated_ids = [
66
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
67
+ ]
68
+
69
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
70
+ return response
71
+
72
+
73
+ prompt = "Calculate (4 - 1)^(9 - 5)"
74
+ print(get_response(prompt, do_sample=False))
75
+
76
+ """
77
+ The expression (4 - 1)^(9 - 5) can be simplified as follows:
78
+
79
+ (4 - 1) = 3
80
+
81
+ So the expression becomes 3^(9 - 5)
82
+
83
+ 3^(9 - 5) = 3^4
84
+
85
+ 3^4 = 81
86
+
87
+ Therefore, (4 - 1)^(9 - 5) = 81.
88
+ """
89
+ ```
README_zh-CN.md ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # NanoLM-1B-Instruct-v1.1
2
+
3
+ [English](README.md) | 简体中文
4
+
5
+
6
+ ## Introduction
7
+
8
+ 为了探究小模型的潜能,我尝试构建一系列小模型,并存放于 [NanoLM Collections](https://huggingface.co/collections/Mxode/nanolm-66d6d75b4a69536bca2705b2)。
9
+
10
+ 这是 NanoLM-1B-Instruct-v1.1。该模型目前仅支持**英文**。
11
+
12
+
13
+ ## 模型详情
14
+
15
+ | Nano LMs | Non-emb Params | Arch | Layers | Dim | Heads | Seq Len |
16
+ | :----------: | :------------------: | :---: | :----: | :-------: | :---: | :---: |
17
+ | 25M | 15M | MistralForCausalLM | 12 | 312 | 12 | 2K |
18
+ | 70M | 42M | LlamaForCausalLM | 12 | 576 | 9 |2K|
19
+ | 0.3B | 180M | Qwen2ForCausalLM | 12 | 896 | 14 |4K|
20
+ | **1B** | **840M** | **Qwen2ForCausalLM** | **18** | **1536** | **12** | **4K** |
21
+
22
+
23
+ ## 如何使用
24
+
25
+ ```python
26
+ import torch
27
+ from transformers import AutoModelForCausalLM, AutoTokenizer
28
+
29
+ model_path = 'Mxode/NanoLM-1B-Instruct-v1.1'
30
+
31
+ model = AutoModelForCausalLM.from_pretrained(model_path).to('cuda:0', torch.bfloat16)
32
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
33
+
34
+
35
+ def get_response(prompt: str, **kwargs):
36
+ generation_args = dict(
37
+ max_new_tokens = kwargs.pop("max_new_tokens", 512),
38
+ do_sample = kwargs.pop("do_sample", True),
39
+ temperature = kwargs.pop("temperature", 0.7),
40
+ top_p = kwargs.pop("top_p", 0.8),
41
+ top_k = kwargs.pop("top_k", 40),
42
+ **kwargs
43
+ )
44
+
45
+ messages = [
46
+ {"role": "system", "content": "You are a helpful assistant."},
47
+ {"role": "user", "content": prompt}
48
+ ]
49
+ text = tokenizer.apply_chat_template(
50
+ messages,
51
+ tokenize=False,
52
+ add_generation_prompt=True
53
+ )
54
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
55
+
56
+ generated_ids = model.generate(model_inputs.input_ids, **generation_args)
57
+ generated_ids = [
58
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
59
+ ]
60
+
61
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
62
+ return response
63
+
64
+
65
+ prompt = "Calculate (4 - 1)^(9 - 5)"
66
+ print(get_response(prompt, do_sample=False))
67
+
68
+ """
69
+ The expression (4 - 1)^(9 - 5) can be simplified as follows:
70
+
71
+ (4 - 1) = 3
72
+
73
+ So the expression becomes 3^(9 - 5)
74
+
75
+ 3^(9 - 5) = 3^4
76
+
77
+ 3^4 = 81
78
+
79
+ Therefore, (4 - 1)^(9 - 5) = 81.
80
+ """
81
+ ```
added_tokens.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "<|endoftext|>": 151643,
3
+ "<|im_end|>": 151645,
4
+ "<|im_start|>": 151644
5
+ }
config.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "Mxode/NanoLM-1B-Instruct-v1.1",
3
+ "architectures": [
4
+ "Qwen2ForCausalLM"
5
+ ],
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 151643,
8
+ "eos_token_id": 151645,
9
+ "hidden_act": "silu",
10
+ "hidden_size": 1536,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 8960,
13
+ "max_position_embeddings": 4096,
14
+ "max_window_layers": 18,
15
+ "model_type": "qwen2",
16
+ "num_attention_heads": 12,
17
+ "num_hidden_layers": 18,
18
+ "num_key_value_heads": 2,
19
+ "rms_norm_eps": 1e-06,
20
+ "rope_theta": 10000.0,
21
+ "sliding_window": 32768,
22
+ "tie_word_embeddings": true,
23
+ "torch_dtype": "bfloat16",
24
+ "transformers_version": "4.42.0",
25
+ "use_cache": false,
26
+ "use_mrope": false,
27
+ "use_sliding_window": false,
28
+ "vocab_size": 151936
29
+ }
generation_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "do_sample": true,
3
+ "eos_token_id": 151645,
4
+ "max_new_tokens": 2048,
5
+ "pad_token_id": 151643,
6
+ "temperature": 0.3,
7
+ "top_k": 20,
8
+ "top_p": 0.7,
9
+ "transformers_version": "4.42.0"
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:389dbb66ad6c045da3353a2d73054845716a0464ce0a277d15b4f576a0d36580
3
+ size 2151496896
special_tokens_map.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|im_start|>",
4
+ "<|im_end|>"
5
+ ],
6
+ "eos_token": {
7
+ "content": "<|im_end|>",
8
+ "lstrip": false,
9
+ "normalized": false,
10
+ "rstrip": false,
11
+ "single_word": false
12
+ },
13
+ "pad_token": {
14
+ "content": "<|endoftext|>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false
19
+ }
20
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "151643": {
5
+ "content": "<|endoftext|>",
6
+ "lstrip": false,
7
+ "normalized": false,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "151644": {
13
+ "content": "<|im_start|>",
14
+ "lstrip": false,
15
+ "normalized": false,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ },
20
+ "151645": {
21
+ "content": "<|im_end|>",
22
+ "lstrip": false,
23
+ "normalized": false,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": true
27
+ }
28
+ },
29
+ "additional_special_tokens": [
30
+ "<|im_start|>",
31
+ "<|im_end|>"
32
+ ],
33
+ "bos_token": null,
34
+ "chat_template": "{% for message in messages %}{% if loop.first and messages[0]['role'] != 'system' %}{{ '<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n' }}{% endif %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %}",
35
+ "clean_up_tokenization_spaces": false,
36
+ "eos_token": "<|im_end|>",
37
+ "errors": "replace",
38
+ "model_max_length": 32768,
39
+ "pad_token": "<|endoftext|>",
40
+ "split_special_tokens": false,
41
+ "tokenizer_class": "Qwen2Tokenizer",
42
+ "unk_token": null
43
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff