Mxode commited on
Commit
617aed1
1 Parent(s): 54da2ed

upload model

Browse files
README.md CHANGED
@@ -1,3 +1,94 @@
1
  ---
2
  license: gpl-3.0
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: gpl-3.0
3
+ language:
4
+ - en
5
  ---
6
+ # NanoLM-25M-Instruct-v1
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-25M-Instruct-v1. 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-25M-Instruct-v1'
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
+ prompt1 = "What can you do for me?"
74
+ print(get_response(prompt1, do_sample=False))
75
+
76
+ """
77
+ I'm so glad you asked! I'm a large language model, so I don't have personal experiences or emotions, but I can provide information and assist with tasks to help with your tasks.
78
+
79
+ Here are some ways I can assist you:
80
+
81
+ 1. **Answer questions**: I can provide information on a wide range of topics, from science and history to entertainment and culture.
82
+ 2. **Generate text**: I can create text based on a prompt or topic, and can even help with writing tasks such as proofreading and editing.
83
+ 3. **Translate text**: I can translate text from one language to another, including popular languages such as Spanish, French, German, Chinese, and many more.
84
+ 4. **Summarize content**: I can summarize long pieces of text, such as articles or documents, into shorter, more digestible versions.
85
+ 5. **Offer suggestions**: I can provide suggestions for things like gift ideas, travel destinations, books, or movies.
86
+ 6. **Chat and converse**: I can engage in natural-sounding conversations, using context and understanding to respond to questions and statements.
87
+ 7. **Play games**: I can play simple text-based games, such as 20 Questions, Hangman, or Word Jumble.
88
+ 8. **Provide definitions**: I can define words and phrases, explaining their meanings and usage.
89
+ 9. **Offer suggestions**: I can provide suggestions for things like gift ideas, travel destinations, or books to read.
90
+ 10. **Entertain**: I can engage in fun conversations, tell jokes, and even create simple games or puzzles.
91
+
92
+ Which of these methods would you like to do?
93
+ """
94
+ ```
README_zh-CN.md ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # NanoLM-25M-Instruct-v1
2
+
3
+ [English](README.md) | 简体中文
4
+
5
+
6
+ ## Introduction
7
+
8
+ 为了探究小模型的潜能,我尝试构建一系列小模型,并存放于 [NanoLM Collections](https://huggingface.co/collections/Mxode/nanolm-66d6d75b4a69536bca2705b2)。
9
+
10
+ 这是 NanoLM-25M-Instruct-v1。该模型目前仅支持**英文**。
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-25M-Instruct-v1'
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 = "What can you do for me?"
66
+ print(get_response(prompt1, do_sample=False))
67
+
68
+ """
69
+ I'm so glad you asked! I'm a large language model, so I don't have personal experiences or emotions, but I can provide information and assist with tasks to help with your tasks.
70
+
71
+ Here are some ways I can assist you:
72
+
73
+ 1. **Answer questions**: I can provide information on a wide range of topics, from science and history to entertainment and culture.
74
+ 2. **Generate text**: I can create text based on a prompt or topic, and can even help with writing tasks such as proofreading and editing.
75
+ 3. **Translate text**: I can translate text from one language to another, including popular languages such as Spanish, French, German, Chinese, and many more.
76
+ 4. **Summarize content**: I can summarize long pieces of text, such as articles or documents, into shorter, more digestible versions.
77
+ 5. **Offer suggestions**: I can provide suggestions for things like gift ideas, travel destinations, books, or movies.
78
+ 6. **Chat and converse**: I can engage in natural-sounding conversations, using context and understanding to respond to questions and statements.
79
+ 7. **Play games**: I can play simple text-based games, such as 20 Questions, Hangman, or Word Jumble.
80
+ 8. **Provide definitions**: I can define words and phrases, explaining their meanings and usage.
81
+ 9. **Offer suggestions**: I can provide suggestions for things like gift ideas, travel destinations, or books to read.
82
+ 10. **Entertain**: I can engage in fun conversations, tell jokes, and even create simple games or puzzles.
83
+
84
+ Which of these methods would you like to do?
85
+ """
86
+ ```
added_tokens.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "<image>": 32003,
3
+ "<|endoftext|>": 32002,
4
+ "<|im_end|>": 32001,
5
+ "<|im_start|>": 32000
6
+ }
config.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "Mxode/NanoLM-25M-Instruct-v1",
3
+ "architectures": [
4
+ "MistralForCausalLM"
5
+ ],
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 1,
8
+ "eos_token_id": 32001,
9
+ "hidden_act": "silu",
10
+ "hidden_size": 312,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 1092,
13
+ "max_position_embeddings": 2048,
14
+ "model_type": "mistral",
15
+ "num_attention_heads": 12,
16
+ "num_hidden_layers": 12,
17
+ "num_key_value_heads": 4,
18
+ "rms_norm_eps": 1e-06,
19
+ "rope_theta": 10000.0,
20
+ "sliding_window": null,
21
+ "tie_word_embeddings": true,
22
+ "torch_dtype": "bfloat16",
23
+ "transformers_version": "4.42.0",
24
+ "use_cache": false,
25
+ "vocab_size": 32064
26
+ }
generation_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "do_sample": true,
3
+ "eos_token_id": 32001,
4
+ "max_new_tokens": 2048,
5
+ "pad_token_id": 32002,
6
+ "temperature": 0.3,
7
+ "top_k": 20,
8
+ "top_p": 0.7,
9
+ "transformers_version": "4.42.0"
10
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7a0e1d819ee06353704cc39bfcddad8f11fdee964457a2503be667fe7ff48e80
3
+ size 50796360
special_tokens_map.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|im_start|>",
4
+ "<|im_end|>",
5
+ "<|endoftext|>",
6
+ "<image>"
7
+ ],
8
+ "bos_token": {
9
+ "content": "<s>",
10
+ "lstrip": false,
11
+ "normalized": false,
12
+ "rstrip": false,
13
+ "single_word": false
14
+ },
15
+ "eos_token": {
16
+ "content": "<|im_end|>",
17
+ "lstrip": false,
18
+ "normalized": false,
19
+ "rstrip": false,
20
+ "single_word": false
21
+ },
22
+ "pad_token": {
23
+ "content": "<|endoftext|>",
24
+ "lstrip": false,
25
+ "normalized": false,
26
+ "rstrip": false,
27
+ "single_word": false
28
+ },
29
+ "unk_token": {
30
+ "content": "<unk>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false
35
+ }
36
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dadfd56d766715c61d2ef780a525ab43b8e6da4de6865bda3d95fdef5e134055
3
+ size 493443
tokenizer_config.json ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_eos_token": false,
4
+ "add_prefix_space": null,
5
+ "added_tokens_decoder": {
6
+ "0": {
7
+ "content": "<unk>",
8
+ "lstrip": false,
9
+ "normalized": false,
10
+ "rstrip": false,
11
+ "single_word": false,
12
+ "special": true
13
+ },
14
+ "1": {
15
+ "content": "<s>",
16
+ "lstrip": false,
17
+ "normalized": false,
18
+ "rstrip": false,
19
+ "single_word": false,
20
+ "special": true
21
+ },
22
+ "2": {
23
+ "content": "</s>",
24
+ "lstrip": false,
25
+ "normalized": false,
26
+ "rstrip": false,
27
+ "single_word": false,
28
+ "special": true
29
+ },
30
+ "32000": {
31
+ "content": "<|im_start|>",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false,
36
+ "special": true
37
+ },
38
+ "32001": {
39
+ "content": "<|im_end|>",
40
+ "lstrip": false,
41
+ "normalized": false,
42
+ "rstrip": false,
43
+ "single_word": false,
44
+ "special": true
45
+ },
46
+ "32002": {
47
+ "content": "<|endoftext|>",
48
+ "lstrip": false,
49
+ "normalized": false,
50
+ "rstrip": false,
51
+ "single_word": false,
52
+ "special": true
53
+ },
54
+ "32003": {
55
+ "content": "<image>",
56
+ "lstrip": false,
57
+ "normalized": false,
58
+ "rstrip": false,
59
+ "single_word": false,
60
+ "special": true
61
+ }
62
+ },
63
+ "additional_special_tokens": [
64
+ "<|im_start|>",
65
+ "<|im_end|>",
66
+ "<|endoftext|>",
67
+ "<image>"
68
+ ],
69
+ "bos_token": "<s>",
70
+ "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 %}",
71
+ "clean_up_tokenization_spaces": false,
72
+ "eos_token": "<|im_end|>",
73
+ "errors": "replace",
74
+ "legacy": true,
75
+ "model_max_length": 2048,
76
+ "pad_token": "<|endoftext|>",
77
+ "padding_side": "left",
78
+ "sp_model_kwargs": {},
79
+ "spaces_between_special_tokens": false,
80
+ "tokenizer_class": "LlamaTokenizer",
81
+ "unk_token": "<unk>",
82
+ "use_default_system_prompt": false
83
+ }