license: gpl-3.0
language:
- en
datasets:
- Mxode/Magpie-Pro-10K-GPT4o-mini
pipeline_tag: text2text-generation
tags:
- text-generation-inference
NanoLM-1B-Instruct-v2
简介
为了探索小模型的潜力,我尝试构建了一系列模型,这些模型可在NanoLM系列中找到。
这是NanoLM-1B-Instruct-v2,基于超过400万条高质量指令数据微调而成。
该模型目前仅支持英文。
模型详情
Nano LMs |
非嵌入参数量 |
架构 |
层数 |
维度 |
注意力头数 |
序列长度 |
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 |
性能指标
|
NanoLM-1B-Instruct-v2 |
Tinyllama-1.1B |
Gemma-2B |
Qwen1.5-1.8B |
Qwen2-1.5B |
Qwen1.5-4B |
Mistral-7B-v0.1 |
Mistral-7B-v0.3 |
Qwen1.5-7B |
GSM8K |
44.1 |
2.3 |
17.7 |
33.6 |
55.8 |
52.2 |
37.83 |
34.5 |
53.5 |
MATH |
14.8 |
0.7 |
11.8 |
10.1 |
21.7 |
10.0 |
8.48 |
- |
20.3 |
BBH |
0.42 |
0.30 |
0.35 |
0.35 |
0.36 |
0.41 |
0.44 |
0.45 |
0.46 |
使用方法
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_path = 'Mxode/NanoLM-1B-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": "你是一个乐于助人的助手。"},
{"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
prompt = "计算(99 - 1) * (3 + 4)"
print(get_response(prompt, do_sample=False))
"""
要计算\((99 - 1) * (3 + 4)\),请遵循运算顺序,即PEMDAS(括号、指数、乘除、加减)。
首先,计算括号内的表达式:
1. \(99 - 1 = 98\)
2. \(3 + 4 = 7\)
然后,将结果相乘:
\(98 * 7 = 686\)
因此,\((99 - 1) * (3 + 4) = 686\)。
"""