---
title: happy-llm-215M-sft
canonical_url: "https://www.modelscope.cn/models/kmno4zx/happy-llm-215M-sft"
md_url: "https://www.modelscope.cn/models/kmno4zx/happy-llm-215M-sft.md"
repository: kmno4zx/happy-llm-215M-sft
chinese_name: Happy-LLM-215M-SFT
last_updated: 2025-06-21
license: "Apache License 2.0"
pipeline_tag: text-generation
tasks:
  - text-generation
model_type:
  - Tiny-K
architectures:
  - Transformer
library_name:
  - pytorch
  - transformer
frameworks:
  - Pytorch
downloads: 2691
stars: 11
---

# happy-llm-215M-sft

> happy-llm-215M-sft - kmno4zx 在 ModelScope 开源的模型。本模型为Happy-LLM教程中，第五章节的 sft 模型

kmno4zx/happy-llm-215M-sft 是 ModelScope 魔搭社区上的text-generation模型，采用 Apache License 2.0 许可。

- **Repository**: kmno4zx/happy-llm-215M-sft
- **License**: Apache License 2.0
- **Tasks**: text-generation
- **Downloads**: 2691
- **Stars**: 11
- **Last updated**: 2025-06-21

Source: https://www.modelscope.cn/models/kmno4zx/happy-llm-215M-sft

---

# Happy-LLM-215M-SFT

<div align='center'>
    <img src="./images/head.jpg" alt="alt text" width="80%">
    <h1>Happy-LLM</h1>
</div>

<div align="center">
  <img src="https://img.shields.io/github/stars/datawhalechina/happy-llm?style=flat&logo=github" alt="GitHub stars"/>
  <img src="https://img.shields.io/github/forks/datawhalechina/happy-llm?style=flat&logo=github" alt="GitHub forks"/>
  <img src="https://img.shields.io/badge/language-Chinese-brightgreen?style=flat" alt="Language"/>
  <a href="https://github.com/datawhalechina/happy-llm"><img src="https://img.shields.io/badge/GitHub-Project-blue?style=flat&logo=github" alt="GitHub Project"></a>
  <a href="https://swanlab.cn/@kmno4/Happy-LLM/overview"><img src="https://raw.githubusercontent.com/SwanHubX/assets/main/badge1.svg" alt="SwanLab"></a>
</div>

本模型为 Happy-LLM 215M SFT模型，基于 Pytorch 框架，模型大小为 215M，训练数据为[BelleGroup](https://huggingface.co/datasets/BelleGroup/train_3.5M_CN)，总量大概在 350万 条对话数据左右。

> 注：本模型仅用于教学目的，请勿将本模型应用于任何生产环境。

## 模型下载

可以使用如下方式下载模型

```bash
#安装ModelScope
pip install modelscope
```
```python
#SDK模型下载
from modelscope import snapshot_download
model_dir = snapshot_download('kmno4zx/happy-llm-215M-sft')
```

## 模型使用

```bash
pip install -r requirements.txt
```

运行以下代码即可：

```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

model_id = "kmno4zx/happy-llm-215M-sft"

tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, trust_remote_code=True, device_map="cuda:0").eval()

messages = [{"role": "system", "content": "你是一个AI助手"}]

while True:
    prompt = input('User: ')
    messages.append({"role": "user", "content": prompt})

    input_ids = tokenizer.apply_chat_template(messages,tokenize=False,add_generation_prompt=True)
    input_ids = tokenizer(input_ids).data['input_ids']
    x = (torch.tensor(input_ids, dtype=torch.long)[None, ...]).to(model.device)

    with torch.no_grad():
        y = model.generate(x, stop_id=tokenizer.eos_token_id, max_new_tokens=512, temperature=0.6)
        response = tokenizer.decode(y[0].tolist())
    
    print(f"Assistant: {response}")

    messages.append({"role": "assistant", "content": response})
```

```OUTPUT
User: 你好
Assistant: 你好!有什么我可以帮你的吗?
User: 你是谁？
Assistant: 我是一款人工智能程序,可以通过自然语言处理技术来回答你的问题。
User: 真棒！
Assistant: 谢谢!有什么我能帮助你的吗?
```

## 🙏 致谢

### 核心贡献者
- [宋志学-项目负责人](https://github.com/KMnO4-zx) (Datawhale成员-中国矿业大学(北京))
- [邹雨衡-项目负责人](https://github.com/logan-zou) (Datawhale成员-对外经济贸易大学)
- [朱信忠-指导专家](https://xinzhongzhu.github.io/)（Datawhale首席科学家-浙江师范大学杭州人工智能研究院教授）

### 特别感谢
- 感谢 [@Sm1les](https://github.com/Sm1les) 对本项目的帮助与支持
- 感谢所有为本项目做出贡献的开发者们 ❤️

<div align=center style="margin-top: 30px;">
  <a href="https://github.com/datawhalechina/happy-llm/graphs/contributors">
    <img src="https://contrib.rocks/image?repo=datawhalechina/happy-llm" />
  </a>
</div>

## Star History

<div align='center'>
    <img src="./images/star-history-2025612.png" alt="Datawhale" width="90%">
</div>

<div align="center">
  <p>⭐ 如果这个项目对你有帮助，请给我们一个 Star！</p>
</div>

## 关于 Datawhale

<div align='center'>
    <img src="./images/datawhale.png" alt="Datawhale" width="30%">
    <p>扫描二维码关注 Datawhale 公众号，获取更多优质开源内容</p>
</div>
