Mxode commited on
Commit
40027e2
1 Parent(s): 278ee69

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +103 -90
README.md CHANGED
@@ -1,90 +1,103 @@
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
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: gpl-3.0
3
+ language:
4
+ - en
5
+ datasets:
6
+ - Mxode/Magpie-Pro-10K-GPT4o-mini
7
+ pipeline_tag: text2text-generation
8
+ tags:
9
+ - chemistry
10
+ - biology
11
+ - finance
12
+ - legal
13
+ - music
14
+ - code
15
+ - climate
16
+ - medical
17
+ - text-generation-inference
18
+ ---
19
+ # NanoLM-0.3B-Instruct-v2
20
+
21
+
22
+ English | [简体中文](README_zh-CN.md)
23
+
24
+
25
+ ## Introduction
26
+
27
+ 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).
28
+
29
+ This is NanoLM-0.3B-Instruct-v2. The model currently supports **English only**.
30
+
31
+
32
+
33
+ ## Model Details
34
+
35
+ | Nano LMs | Non-emb Params | Arch | Layers | Dim | Heads | Seq Len |
36
+ | :----------: | :------------------: | :---: | :----: | :-------: | :---: | :---: |
37
+ | 25M | 15M | MistralForCausalLM | 12 | 312 | 12 |2K|
38
+ | 70M | 42M | LlamaForCausalLM | 12 | 576 | 9 |2K|
39
+ | **0.3B** | **180M** | **Qwen2ForCausalLM** | **12** | **896** | **14** | **4K** |
40
+ | 1B | 840M | Qwen2ForCausalLM | 18 | 1536 | 12 |4K|
41
+
42
+ 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.
43
+
44
+ As a result, NanoLM-0.3B-Instruct-v1.1 has only 0.3 billion parameters, with approximately **180 million non-embedding parameters**.
45
+
46
+ Despite this, NanoLM-0.3B-Instruct-v1.1 still demonstrates strong instruction-following capabilities.
47
+
48
+
49
+
50
+ ## How to use
51
+
52
+ ```python
53
+ import torch
54
+ from transformers import AutoModelForCausalLM, AutoTokenizer
55
+
56
+ model_path = 'Mxode/NanoLM-0.3B-Instruct-v2'
57
+
58
+ model = AutoModelForCausalLM.from_pretrained(model_path).to('cuda:0', torch.bfloat16)
59
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
60
+
61
+
62
+ def get_response(prompt: str, **kwargs):
63
+ generation_args = dict(
64
+ max_new_tokens = kwargs.pop("max_new_tokens", 512),
65
+ do_sample = kwargs.pop("do_sample", True),
66
+ temperature = kwargs.pop("temperature", 0.7),
67
+ top_p = kwargs.pop("top_p", 0.8),
68
+ top_k = kwargs.pop("top_k", 40),
69
+ **kwargs
70
+ )
71
+
72
+ messages = [
73
+ {"role": "system", "content": "You are a helpful assistant."},
74
+ {"role": "user", "content": prompt}
75
+ ]
76
+ text = tokenizer.apply_chat_template(
77
+ messages,
78
+ tokenize=False,
79
+ add_generation_prompt=True
80
+ )
81
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
82
+
83
+ generated_ids = model.generate(model_inputs.input_ids, **generation_args)
84
+ generated_ids = [
85
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
86
+ ]
87
+
88
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
89
+ return response
90
+
91
+
92
+ prompt1 = "Calculate (4 - 1) * 7"
93
+ print(get_response(prompt1, do_sample=False))
94
+
95
+ """
96
+ To calculate the expression (4 - 1) * 7, we need to follow the order of operations (PEMDAS):
97
+
98
+ 1. Evaluate the expression inside the parentheses: 4 - 1 = 3
99
+ 2. Multiply 3 by 7: 3 * 7 = 21
100
+
101
+ So, (4 - 1) * 7 = 21.
102
+ """
103
+ ```