Mxode commited on
Commit
278ee69
1 Parent(s): 4e03777

upload model

Browse files
README.md CHANGED
@@ -1,3 +1,90 @@
1
  ---
2
  license: gpl-3.0
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: gpl-3.0
3
+ language:
4
+ - en
5
  ---
6
+ # NanoLM-0.3B-Instruct-v2
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-0.3B-Instruct-v2. 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
+ The tokenizer and model architecture of NanoLM-0.3B-Instruct-v1.1 are the same as [Qwen/Qwen2-0.5B](https://huggingface.co/Qwen/Qwen2-0.5B), but the number of layers has been reduced from 24 to 12.
30
+
31
+ As a result, NanoLM-0.3B-Instruct-v1.1 has only 0.3 billion parameters, with approximately **180 million non-embedding parameters**.
32
+
33
+ Despite this, NanoLM-0.3B-Instruct-v1.1 still demonstrates strong instruction-following capabilities.
34
+
35
+
36
+
37
+ ## How to use
38
+
39
+ ```python
40
+ import torch
41
+ from transformers import AutoModelForCausalLM, AutoTokenizer
42
+
43
+ model_path = 'Mxode/NanoLM-0.3B-Instruct-v2'
44
+
45
+ model = AutoModelForCausalLM.from_pretrained(model_path).to('cuda:0', torch.bfloat16)
46
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
47
+
48
+
49
+ def get_response(prompt: str, **kwargs):
50
+ generation_args = dict(
51
+ max_new_tokens = kwargs.pop("max_new_tokens", 512),
52
+ do_sample = kwargs.pop("do_sample", True),
53
+ temperature = kwargs.pop("temperature", 0.7),
54
+ top_p = kwargs.pop("top_p", 0.8),
55
+ top_k = kwargs.pop("top_k", 40),
56
+ **kwargs
57
+ )
58
+
59
+ messages = [
60
+ {"role": "system", "content": "You are a helpful assistant."},
61
+ {"role": "user", "content": prompt}
62
+ ]
63
+ text = tokenizer.apply_chat_template(
64
+ messages,
65
+ tokenize=False,
66
+ add_generation_prompt=True
67
+ )
68
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
69
+
70
+ generated_ids = model.generate(model_inputs.input_ids, **generation_args)
71
+ generated_ids = [
72
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
73
+ ]
74
+
75
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
76
+ return response
77
+
78
+
79
+ prompt1 = "Calculate (4 - 1) * 7"
80
+ print(get_response(prompt1, do_sample=False))
81
+
82
+ """
83
+ To calculate the expression (4 - 1) * 7, we need to follow the order of operations (PEMDAS):
84
+
85
+ 1. Evaluate the expression inside the parentheses: 4 - 1 = 3
86
+ 2. Multiply 3 by 7: 3 * 7 = 21
87
+
88
+ So, (4 - 1) * 7 = 21.
89
+ """
90
+ ```
README_zh-CN.md ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # NanoLM-0.3B-Instruct-v2
2
+
3
+ [English](README.md) | 简体中文
4
+
5
+
6
+ ## Introduction
7
+
8
+ 为了探究小模型的潜能,我尝试构建一系列小模型,并存放于 [NanoLM Collections](https://huggingface.co/collections/Mxode/nanolm-66d6d75b4a69536bca2705b2)。
9
+
10
+ 这是 NanoLM-0.3B-Instruct-v2。该模型目前仅支持**英文**。
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-0.3B-Instruct-v2'
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
+ prompt1 = "Calculate (4 - 1) * 7"
66
+ print(get_response(prompt1, do_sample=False))
67
+
68
+ """
69
+ To calculate the expression (4 - 1) * 7, we need to follow the order of operations (PEMDAS):
70
+
71
+ 1. Evaluate the expression inside the parentheses: 4 - 1 = 3
72
+ 2. Multiply 3 by 7: 3 * 7 = 21
73
+
74
+ So, (4 - 1) * 7 = 21.
75
+ """
76
+ ```
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,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "Mxode/NanoLM-0.3B-Instruct-v2",
3
+ "architectures": [
4
+ "Qwen2ForCausalLM"
5
+ ],
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 151643,
8
+ "eos_token_id": 151643,
9
+ "hidden_act": "silu",
10
+ "hidden_size": 896,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 4864,
13
+ "max_position_embeddings": 131072,
14
+ "max_window_layers": 12,
15
+ "model_type": "qwen2",
16
+ "num_attention_heads": 14,
17
+ "num_hidden_layers": 12,
18
+ "num_key_value_heads": 2,
19
+ "rms_norm_eps": 1e-06,
20
+ "rope_theta": 1000000.0,
21
+ "sliding_window": 131072,
22
+ "tie_word_embeddings": true,
23
+ "torch_dtype": "bfloat16",
24
+ "transformers_version": "4.42.0",
25
+ "use_cache": false,
26
+ "use_sliding_window": false,
27
+ "vocab_size": 151936
28
+ }
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:bed1f62c817bd585457eb8ea418c3864a2da29fa4263dc477c08dea666d7da79
3
+ size 630184520
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