初始化项目,由ModelHub XC社区提供模型

Model: Mxode/NanoLM-0.3B-Instruct-v2
Source: Original Platform
This commit is contained in:
ModelHub XC
2026-05-29 21:20:27 +08:00
commit f6bdf565ef
12 changed files with 454824 additions and 0 deletions

35
.gitattributes vendored Normal file
View File

@@ -0,0 +1,35 @@
*.7z filter=lfs diff=lfs merge=lfs -text
*.arrow filter=lfs diff=lfs merge=lfs -text
*.bin filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.ckpt filter=lfs diff=lfs merge=lfs -text
*.ftz filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.h5 filter=lfs diff=lfs merge=lfs -text
*.joblib filter=lfs diff=lfs merge=lfs -text
*.lfs.* filter=lfs diff=lfs merge=lfs -text
*.mlmodel filter=lfs diff=lfs merge=lfs -text
*.model filter=lfs diff=lfs merge=lfs -text
*.msgpack filter=lfs diff=lfs merge=lfs -text
*.npy filter=lfs diff=lfs merge=lfs -text
*.npz filter=lfs diff=lfs merge=lfs -text
*.onnx filter=lfs diff=lfs merge=lfs -text
*.ot filter=lfs diff=lfs merge=lfs -text
*.parquet filter=lfs diff=lfs merge=lfs -text
*.pb filter=lfs diff=lfs merge=lfs -text
*.pickle filter=lfs diff=lfs merge=lfs -text
*.pkl filter=lfs diff=lfs merge=lfs -text
*.pt filter=lfs diff=lfs merge=lfs -text
*.pth filter=lfs diff=lfs merge=lfs -text
*.rar filter=lfs diff=lfs merge=lfs -text
*.safetensors filter=lfs diff=lfs merge=lfs -text
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
*.tar.* filter=lfs diff=lfs merge=lfs -text
*.tar filter=lfs diff=lfs merge=lfs -text
*.tflite filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.wasm filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text
*tfevents* filter=lfs diff=lfs merge=lfs -text

103
README.md Normal file
View File

@@ -0,0 +1,103 @@
---
license: gpl-3.0
language:
- en
datasets:
- Mxode/Magpie-Pro-10K-GPT4o-mini
pipeline_tag: text2text-generation
tags:
- chemistry
- biology
- finance
- legal
- music
- code
- climate
- medical
- text-generation-inference
---
# NanoLM-0.3B-Instruct-v2
English | [简体中文](README_zh-CN.md)
## Introduction
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).
This is NanoLM-0.3B-Instruct-v2. The model currently supports **English only**.
## Model Details
| Nano LMs | Non-emb Params | Arch | Layers | Dim | Heads | Seq Len |
| :----------: | :------------------: | :---: | :----: | :-------: | :---: | :---: |
| 25M | 15M | MistralForCausalLM | 12 | 312 | 12 |2K|
| 70M | 42M | LlamaForCausalLM | 12 | 576 | 9 |2K|
| **0.3B** | **180M** | **Qwen2ForCausalLM** | **12** | **896** | **14** | **4K** |
| 1B | 840M | Qwen2ForCausalLM | 18 | 1536 | 12 |4K|
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.
As a result, NanoLM-0.3B-Instruct-v1.1 has only 0.3 billion parameters, with approximately **180 million non-embedding parameters**.
Despite this, NanoLM-0.3B-Instruct-v1.1 still demonstrates strong instruction-following capabilities.
## How to use
```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_path = 'Mxode/NanoLM-0.3B-Instruct-v2'
model = AutoModelForCausalLM.from_pretrained(model_path).to('cuda:0', torch.bfloat16)
tokenizer = AutoTokenizer.from_pretrained(model_path)
def get_response(prompt: str, **kwargs):
generation_args = dict(
max_new_tokens = kwargs.pop("max_new_tokens", 512),
do_sample = kwargs.pop("do_sample", True),
temperature = kwargs.pop("temperature", 0.7),
top_p = kwargs.pop("top_p", 0.8),
top_k = kwargs.pop("top_k", 40),
**kwargs
)
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
generated_ids = model.generate(model_inputs.input_ids, **generation_args)
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
return response
prompt1 = "Calculate (4 - 1) * 7"
print(get_response(prompt1, do_sample=False))
"""
To calculate the expression (4 - 1) * 7, we need to follow the order of operations (PEMDAS):
1. Evaluate the expression inside the parentheses: 4 - 1 = 3
2. Multiply 3 by 7: 3 * 7 = 21
So, (4 - 1) * 7 = 21.
"""
```

76
README_zh-CN.md Normal file
View File

@@ -0,0 +1,76 @@
# NanoLM-0.3B-Instruct-v2
[English](README.md) | 简体中文
## Introduction
为了探究小模型的潜能,我尝试构建一系列小模型,并存放于 [NanoLM Collections](https://huggingface.co/collections/Mxode/nanolm-66d6d75b4a69536bca2705b2)。
这是 NanoLM-0.3B-Instruct-v2。该模型目前仅支持**英文**。
## 模型详情
| Nano LMs | Non-emb Params | Arch | Layers | Dim | Heads | Seq Len |
| :----------: | :------------------: | :---: | :----: | :-------: | :---: | :---: |
| 25M | 15M | MistralForCausalLM | 12 | 312 | 12 |2K|
| 70M | 42M | LlamaForCausalLM | 12 | 576 | 9 |2K|
| **0.3B** | **180M** | **Qwen2ForCausalLM** | **12** | **896** | **14** | **4K** |
| 1B | 840M | Qwen2ForCausalLM | 18 | 1536 | 12 |4K|
## 如何使用
```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_path = 'Mxode/NanoLM-0.3B-Instruct-v2'
model = AutoModelForCausalLM.from_pretrained(model_path).to('cuda:0', torch.bfloat16)
tokenizer = AutoTokenizer.from_pretrained(model_path)
def get_response(prompt: str, **kwargs):
generation_args = dict(
max_new_tokens = kwargs.pop("max_new_tokens", 512),
do_sample = kwargs.pop("do_sample", True),
temperature = kwargs.pop("temperature", 0.7),
top_p = kwargs.pop("top_p", 0.8),
top_k = kwargs.pop("top_k", 40),
**kwargs
)
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
generated_ids = model.generate(model_inputs.input_ids, **generation_args)
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
return response
prompt1 = "Calculate (4 - 1) * 7"
print(get_response(prompt1, do_sample=False))
"""
To calculate the expression (4 - 1) * 7, we need to follow the order of operations (PEMDAS):
1. Evaluate the expression inside the parentheses: 4 - 1 = 3
2. Multiply 3 by 7: 3 * 7 = 21
So, (4 - 1) * 7 = 21.
"""
```

5
added_tokens.json Normal file
View File

@@ -0,0 +1,5 @@
{
"<|endoftext|>": 151643,
"<|im_end|>": 151645,
"<|im_start|>": 151644
}

28
config.json Normal file
View File

@@ -0,0 +1,28 @@
{
"_name_or_path": "Mxode/NanoLM-0.3B-Instruct-v2",
"architectures": [
"Qwen2ForCausalLM"
],
"attention_dropout": 0.0,
"bos_token_id": 151643,
"eos_token_id": 151643,
"hidden_act": "silu",
"hidden_size": 896,
"initializer_range": 0.02,
"intermediate_size": 4864,
"max_position_embeddings": 131072,
"max_window_layers": 12,
"model_type": "qwen2",
"num_attention_heads": 14,
"num_hidden_layers": 12,
"num_key_value_heads": 2,
"rms_norm_eps": 1e-06,
"rope_theta": 1000000.0,
"sliding_window": 131072,
"tie_word_embeddings": true,
"torch_dtype": "bfloat16",
"transformers_version": "4.42.0",
"use_cache": false,
"use_sliding_window": false,
"vocab_size": 151936
}

10
generation_config.json Normal file
View File

@@ -0,0 +1,10 @@
{
"do_sample": true,
"eos_token_id": 151645,
"max_new_tokens": 2048,
"pad_token_id": 151643,
"temperature": 0.3,
"top_k": 20,
"top_p": 0.7,
"transformers_version": "4.42.0"
}

151388
merges.txt Normal file

File diff suppressed because it is too large Load Diff

3
model.safetensors Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:bed1f62c817bd585457eb8ea418c3864a2da29fa4263dc477c08dea666d7da79
size 630184520

20
special_tokens_map.json Normal file
View File

@@ -0,0 +1,20 @@
{
"additional_special_tokens": [
"<|im_start|>",
"<|im_end|>"
],
"eos_token": {
"content": "<|im_end|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
},
"pad_token": {
"content": "<|endoftext|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false
}
}

303112
tokenizer.json Normal file

File diff suppressed because it is too large Load Diff

43
tokenizer_config.json Normal file
View File

@@ -0,0 +1,43 @@
{
"add_prefix_space": false,
"added_tokens_decoder": {
"151643": {
"content": "<|endoftext|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151644": {
"content": "<|im_start|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
},
"151645": {
"content": "<|im_end|>",
"lstrip": false,
"normalized": false,
"rstrip": false,
"single_word": false,
"special": true
}
},
"additional_special_tokens": [
"<|im_start|>",
"<|im_end|>"
],
"bos_token": null,
"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 %}",
"clean_up_tokenization_spaces": false,
"eos_token": "<|im_end|>",
"errors": "replace",
"model_max_length": 32768,
"pad_token": "<|endoftext|>",
"split_special_tokens": false,
"tokenizer_class": "Qwen2Tokenizer",
"unk_token": null
}

1
vocab.json Normal file

File diff suppressed because one or more lines are too long