Edit model card

SmolLM-Chinese-180M

Introduction

遵循 SmolLM 的做法,从头训练了一个支持中英双语的 SmolLM-Chinese-180M。

这并非在 SmolLM 基础上做中文继续预训练得到的模型,而是训练方法遵循 SmolLM 得到的新模型。

请注意:这只是基座模型,未经过任何对齐。

Details

Tokenizer 选用了 Yi-1.5-9B-Chat 的。

模型结构选用最经典的 LLaMA。

模型参数设计遵循 Qwen2-0.5B,根据测试,深而窄的模型表现比较好,并且对于小模型,FFN 的升维维度可以适当更大。

但出于训练速度考虑,并未采用深而窄的模型设计,适当减小了深度。

学习率调度方式采用梯形调度,根据 SmolLM、MiniCPM 以及个人验证,在预训练上,效果确实好于余弦调度,并且梯形调度支持方便地增添数据和续训。

不同于 SmolLM 在最后 20% 的步骤开始衰减学习率,这里梯形调度的衰减步骤占比达到了 30%,采用和 MiniCPM 一致的指数衰减,最低衰减至最大学习率的 1%。

在非常多的开源数据集上进行了训练,并做了进一步筛选和过滤,因此仅列举了部分主要数据集。

训练数据整体比例大约为中文:英文:代码 = 4:4:2,同时中英文中均混合了一定的指令数据。

尚未进行任何基准测试。

How to Use

import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

model_path = 'Mxode/SmolLM-Chinese-180M'

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

def get_response(text: str, model, **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.55),
        top_p = kwargs.pop("top_p", 0.8),
        top_k = kwargs.pop("top_k", 40),
        **kwargs
    )

    prompt = text
    model_inputs = tokenizer([prompt], 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

text = "牛奶作为人类日常必须的优良营养食品,"

response = get_response(text, model, max_new_tokens=256, do_sample=True, temperature=1.0)
print(f'{text}{response}')
Downloads last month
1
Safetensors
Model size
177M params
Tensor type
F32
·
Inference Examples
Inference API (serverless) is not available, repository is disabled.

Datasets used to train Mxode/SmolLM-Chinese-180M