Skip to content

Commit

Permalink
✨ feat: 新增Qwen2模型
Browse files Browse the repository at this point in the history
  • Loading branch information
henryzhuhr committed Jun 9, 2024
1 parent 0541323 commit aab7bc6
Show file tree
Hide file tree
Showing 18 changed files with 493 additions and 400 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/docs-pnpm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ jobs:
steps:
- name: Checkout this
# @see https://github.com/actions/checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0 # 如果未启用 lastUpdated,则不需要

- name: Install Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 20

Expand Down
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
resource/

download/
downloads/

weight/
weights/

tmp/
tmps/
temp/
temps/

# Vuepress/Vitepress
node_modules
docs/.vuepress/.temp
Expand Down
1 change: 1 addition & 0 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default defineConfig({
lightModeSwitchTitle: '切换到浅色模式',
darkModeSwitchTitle: '切换到深色模式'
},
lastUpdated: true,
markdown: {
math: true
}
Expand Down
40 changes: 0 additions & 40 deletions docs/.vuepress/config.ts

This file was deleted.

3 changes: 3 additions & 0 deletions docs/ref.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- [Qwen2.openvino Demo](https://github.com/OpenVINO-dev-contest/Qwen2.openvino/blob/main/README_zh.md)
- OCR: [PaddleOCR](https://github.com/OpenVINO-dev-contest/PaddleOCR) + [PaddleOCR_OpenVINO_CPP](https://github.com/OpenVINO-dev-contest/PaddleOCR_OpenVINO_CPP)
- [ROS-LLM](https://github.com/Auromix/ROS-LLM/tree/ros2-humble)
63 changes: 29 additions & 34 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ outline: deep

## 项目进展

- TODO: 引入更多大模型。聊天只是一个最基本的功能,利用大模型的理解能力和生成能力,才是真正要做的
- 「2024.06.09」 支持基于 2024.6.7 开源的 [Qwen2](https://qwenlm.github.io/blog/qwen2/)([Code](https://github.com/QwenLM/Qwen2)) 模型进行指令微调的任务,目前仅完成了对话交流功能
- 「2024.04.28」 基于千文大模型(Qwen1.5)的模型导出和模型推理测试,并且完成了上下文对话的测试,能记录用户的对话历史
- 「2024.04.26」 项目启动

> TODO: 引入更多大模型。聊天只是一个最基本的功能,利用大模型的理解能力和生成能力,才是真正要做的

<!--
## 环境要求
本项目在以下环境中测试通过:
Expand Down Expand Up @@ -61,61 +65,52 @@ wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
```

运行脚本快速创建环境,会在当前目录下 `.env/toyllm` 创建环境,并安装依赖
创建环境,会在当前目录下 `.env/toyllm` 创建环境,并安装依赖
```shell
bash scripts/init-env.sh
# zsh ...
```
> 默认 Python 版本为系统 Python 版本,如果希望指定版本,可以在脚本 `scripts/init-env.sh` 中取消注释 `CUSTOM_PYTHON_VERSION=3.10`,并修改为指定版本
手动激活该环境
```shell
conda activate .env/toyllm
conda create -n toyllm python -y
conda activate toyllm
```

## 项目使用说明

目前,仅实现了 **千问模型(Qwen1.5)** 的对话交流功能

### 导出模型

导出模型,运行
请到 Hugging Face [Qwen2](https://huggingface.co/collections/Qwen/qwen2-6659360b33528ced941e557f) 下载模型

[Qwen2-1.5B](https://huggingface.co/Qwen/Qwen2-1.5B-Instruct) 为例,下载模型到 `downloads` 目录下
```shell
python3 export.py [--model_id MODEL_ID] [--quan_type MODEL_NAME]
git lfs install
git clone https://huggingface.co/Qwen/Qwen2-1.5B-Instruct downloads/Qwen/Qwen2-1.5B-Instruct
```

导出模型,默认导出至 `weights` 目录下
```shell
python export.py \
--model_id Qwen/Qwen2-1.5B-Instruct \
--weight_dir downloads/Qwen/Qwen2-1.5B-Instruct \
--quan_type int8
```
- `--model_id`:huggingface 中的模型 id,默认为 `Qwen/Qwen1.5-1.8B-Chat`
- `--quan_type`:量化类型,支持 `fp16`/`int8`/`int4`,默认为 `int8`
- tokenizer 和模型会被一同默认导出到 `./weights` 目录下,不作区分,并估计 `model_id` 命名,因此

### 模型推理

对话交流模型功能,以及预设了部分对话,可以直接运行方面测试模型效果,运行
```shell
python3 infer-chat.py [--model_id MODEL_ID] [--model_path MODEL_PATH] [--device DEVICE]
python infer-chat.py \
--model_id Qwen/Qwen2-1.5B-Instruct \
--model_path weights/Qwen/Qwen2-1.5B-Instruct-IR-int8 \
--quan_type int8 \
--max_sequence_length 512
```
- `--model_id`:huggingface 中的模型 id,默认为 `Qwen/Qwen1.5-1.8B-Chat`
- `--model_path`:模型路径,该参数为模型导出的路径

推理结果中可以看到,该模型可以记录用户的对话历史,并根据上下文进行对话


## 参考资料

- 🚀 千文大模型 [QwenLM/Qwen1.5](https://github.com/QwenLM/Qwen1.5?tab=readme-ov-file)
- 🚀 通义千问 [QwenLM/Qwen2](https://github.com/QwenLM/Qwen2)


## 论文引用

千文大模型的技术报告
```bibtex
@article{qwen,
title={Qwen Technical Report},
author={Jinze Bai and Shuai Bai and Yunfei Chu and Zeyu Cui and Kai Dang and Xiaodong Deng and Yang Fan and Wenbin Ge and Yu Han and Fei Huang and Binyuan Hui and Luo Ji and Mei Li and Junyang Lin and Runji Lin and Dayiheng Liu and Gao Liu and Chengqiang Lu and Keming Lu and Jianxin Ma and Rui Men and Xingzhang Ren and Xuancheng Ren and Chuanqi Tan and Sinan Tan and Jianhong Tu and Peng Wang and Shijie Wang and Wei Wang and Shengguang Wu and Benfeng Xu and Jin Xu and An Yang and Hao Yang and Jian Yang and Shusheng Yang and Yang Yao and Bowen Yu and Hongyi Yuan and Zheng Yuan and Jianwei Zhang and Xingxuan Zhang and Yichang Zhang and Zhenru Zhang and Chang Zhou and Jingren Zhou and Xiaohuan Zhou and Tianhang Zhu},
journal={arXiv preprint arXiv:2309.16609},
year={2023}
}
```

<!-- ## License
## License

本项目遵循 [GPL-3.0](https://opensource.org/licenses/GPL-3.0) 协议,请遵循协议使用本项目-->
本项目遵循 [GPL-3.0](https://opensource.org/licenses/GPL-3.0) 协议,请遵循协议使用本项目
96 changes: 0 additions & 96 deletions export.legacy.py

This file was deleted.

Loading

0 comments on commit aab7bc6

Please sign in to comment.