Mxode commited on
Commit
cad6274
·
verified ·
1 Parent(s): ae440e5

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +102 -88
README.md CHANGED
@@ -1,89 +1,103 @@
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
  ```
 
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
+ - art
15
+ - code
16
+ - climate
17
+ - medical
18
+ - text-generation-inference
19
+ ---
20
+ # NanoLM-1B-Instruct-v1.1
21
+
22
+
23
+ English | [简体中文](README_zh-CN.md)
24
+
25
+
26
+ ## Introduction
27
+
28
+ 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).
29
+
30
+ This is NanoLM-1B-Instruct-v1.1. The model currently supports **English only**.
31
+
32
+
33
+
34
+ ## Model Details
35
+
36
+ | Nano LMs | Non-emb Params | Arch | Layers | Dim | Heads | Seq Len |
37
+ | :----------: | :------------------: | :---: | :----: | :-------: | :---: | :---: |
38
+ | 25M | 15M | MistralForCausalLM | 12 | 312 | 12 | 2K |
39
+ | 70M | 42M | LlamaForCausalLM | 12 | 576 | 9 |2K|
40
+ | 0.3B | 180M | Qwen2ForCausalLM | 12 | 896 | 14 |4K|
41
+ | **1B** | **840M** | **Qwen2ForCausalLM** | **18** | **1536** | **12** | **4K** |
42
+
43
+
44
+
45
+ ## How to use
46
+
47
+ ```python
48
+ import torch
49
+ from transformers import AutoModelForCausalLM, AutoTokenizer
50
+
51
+ model_path = 'Mxode/NanoLM-1B-Instruct-v1.1'
52
+
53
+ model = AutoModelForCausalLM.from_pretrained(model_path).to('cuda:0', torch.bfloat16)
54
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
55
+
56
+
57
+ def get_response(prompt: str, **kwargs):
58
+ generation_args = dict(
59
+ max_new_tokens = kwargs.pop("max_new_tokens", 512),
60
+ do_sample = kwargs.pop("do_sample", True),
61
+ temperature = kwargs.pop("temperature", 0.7),
62
+ top_p = kwargs.pop("top_p", 0.8),
63
+ top_k = kwargs.pop("top_k", 40),
64
+ **kwargs
65
+ )
66
+
67
+ messages = [
68
+ {"role": "system", "content": "You are a helpful assistant."},
69
+ {"role": "user", "content": prompt}
70
+ ]
71
+ text = tokenizer.apply_chat_template(
72
+ messages,
73
+ tokenize=False,
74
+ add_generation_prompt=True
75
+ )
76
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
77
+
78
+ generated_ids = model.generate(model_inputs.input_ids, **generation_args)
79
+ generated_ids = [
80
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
81
+ ]
82
+
83
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
84
+ return response
85
+
86
+
87
+ prompt = "Calculate (4 - 1)^(9 - 5)"
88
+ print(get_response(prompt, do_sample=False))
89
+
90
+ """
91
+ The expression (4 - 1)^(9 - 5) can be simplified as follows:
92
+
93
+ (4 - 1) = 3
94
+
95
+ So the expression becomes 3^(9 - 5)
96
+
97
+ 3^(9 - 5) = 3^4
98
+
99
+ 3^4 = 81
100
+
101
+ Therefore, (4 - 1)^(9 - 5) = 81.
102
+ """
103
  ```