NanoLM-70M-Instruct-v1 / README_zh-CN.md
Mxode's picture
Update README_zh-CN.md
eb55317 verified

NanoLM-70M-Instruct-v1

English | 简体中文

Introduction

为了探究小模型的潜能,我尝试构建一系列小模型,并存放于 NanoLM Collections

这是 NanoLM-70M-Instruct-v1。该模型目前仅支持英文

模型详情

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

NanoLM-70M-Instruct-v1 的分词器和模型架构与 SmolLM-135M 相同,但层数从30减少到12。

本质上是纯粹的 LLaMA 架构,即 LlamaForCausalLM。

因此,NanoLM-70M-Instruct-v1 的参数量只有 70 M。

尽管如此,NanoLM-70M-Instruct-v1 仍展示了指令跟随能力。

如何使用

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

model_path = 'Mxode/NanoLM-70M-Instruct-v1'

model = AutoModelForCausalLM.from_pretrained(model_path).to('cuda:0', torch.bfloat16)
tokenizer = AutoTokenizer.from_pretrained(model_path)


text = "Why is it important for entrepreneurs to prioritize financial management?"
prompt = tokenizer.apply_chat_template(
    [
        {'role': 'system', 'content': 'You are a helpful assistant.'},
        {'role': 'user', 'content': text}
    ],
    add_generation_prompt=True,
    tokenize=True,
    return_tensors='pt'
).to('cuda:0')


outputs = model.generate(
    prompt,
    max_new_tokens=1024,
    do_sample=True,
    temperature=0.7,
    repetition_penalty=1.1,
    eos_token_id=tokenizer.eos_token_id,
)
response = tokenizer.decode(outputs[0])
print(response)