🚀 NanoLM-1B-Instruct-v1.1
NanoLM-1B-Instruct-v1.1是為探索小模型潛力而構建的一系列模型之一,目前僅支持英文。
🚀 快速開始
為了探索小模型的潛力,我嘗試構建了一系列小模型,這些模型可在 NanoLM Collections 中找到。
這是 NanoLM-1B-Instruct-v1.1,該模型目前僅支持英文。
✨ 主要特性
此模型聚焦於小模型領域,在有限的參數規模下探索模型能力,涉及化學、生物學、金融、法律、音樂、藝術、代碼、氣候、醫學等多個領域的文本生成。
📚 詳細文檔
模型詳情
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 |
💻 使用示例
基礎用法
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_path = 'Mxode/NanoLM-1B-Instruct-v1.1'
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
prompt = "Calculate (4 - 1)^(9 - 5)"
print(get_response(prompt, do_sample=False))
"""
The expression (4 - 1)^(9 - 5) can be simplified as follows:
(4 - 1) = 3
So the expression becomes 3^(9 - 5)
3^(9 - 5) = 3^4
3^4 = 81
Therefore, (4 - 1)^(9 - 5) = 81.
"""
📄 許可證
本項目採用 GPL-3.0 許可證。