Skip to content

Commit 1e15756

Browse files
authored
update web ui and swift cli (#126)
1 parent 1d87db9 commit 1e15756

File tree

93 files changed

+681
-694
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+681
-694
lines changed

README.md

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<a href="README_CN.md">中文</a>&nbsp | &nbspEnglish
1313
</p>
1414

15-
# Introduction
15+
# 📖 Introduction
1616

1717
SWIFT (Scalable lightWeight Infrastructure for Fine-Tuning) is an extensible framwork designed to faciliate lightweight model fine-tuning and inference. It integrates implementations for various efficient fine-tuning methods, by embracing approaches that is parameter-efficient, memory-efficient, and time-efficient. SWIFT integrates seamlessly into ModelScope ecosystem and offers the capabilities to finetune various models, with a primary emphasis on LLMs and vision models. Additionally, SWIFT is fully compatible with [PEFT](https://github.com/huggingface/peft), enabling users to leverage the familiar Peft interface to finetune ModelScope models.
1818

@@ -36,7 +36,7 @@ Key features:
3636

3737
Users can check the [documentation of Swift](docs/source/GetStarted/Introduction.md) to get detail tutorials.
3838

39-
### 🎉News
39+
### 🎉 News
4040

4141
- 🔥 2023.10.30: Support QA-LoRA and LongLoRA to decrease memory usage in training.
4242
- 🔥 2023.10.30: Support ROME(Rank One Model Editing) to add/modify knowledges, training is not needed!
@@ -48,10 +48,12 @@ Users can check the [documentation of Swift](docs/source/GetStarted/Introduction
4848
- 🔥 2023.9.25: Supported qwen-14b model series: qwen-14b, qwen-14b-chat. The corresponding shell script can be found at `scripts/qwen_14b`, `scripts/qwen_14b_chat`.
4949
- 2023.9.12: Supported training with MP+DDP to accelerate full-parameter fine-tuning speed. The corresponding shell script can be found at `scripts/qwen_7b_chat/full_mp_ddp/sft.sh`.
5050

51-
## LLM SFT Example
51+
## LLM SFT Example
5252
Press [this link](https://github.com/modelscope/swift/tree/main/examples/pytorch/llm) to view the detail documentation of these examples.
5353

5454
### Basic Usage
55+
Quickly fine-tune, infer with LLM, and build a Web-UI.
56+
#### Run using Python
5557
```bash
5658
git clone https://github.com/modelscope/swift.git
5759
cd swift
@@ -66,8 +68,10 @@ os.environ['CUDA_VISIBLE_DEVICES'] = '0'
6668

6769
import torch
6870

69-
from swift.llm import DatasetName, InferArguments, ModelType, SftArguments
70-
from swift.llm.run import infer_main, sft_main
71+
from swift.llm import (
72+
DatasetName, InferArguments, ModelType, SftArguments
73+
)
74+
from swift.llm.run import infer_main, sft_main, web_ui_main
7175

7276
model_type = ModelType.qwen_7b_chat_int4
7377
sft_args = SftArguments(
@@ -81,14 +85,44 @@ best_ckpt_dir = sft_main(sft_args)
8185
print(f'best_ckpt_dir: {best_ckpt_dir}')
8286
torch.cuda.empty_cache()
8387
infer_args = InferArguments(
84-
model_type=sft_args.model_type,
8588
ckpt_dir=best_ckpt_dir,
86-
dataset=sft_args.dataset,
89+
load_args_from_ckpt_dir=True,
8790
stream=True,
8891
show_dataset_sample=5)
8992
infer_main(infer_args)
93+
torch.cuda.empty_cache()
94+
web_ui_main(infer_args)
95+
```
96+
97+
#### Run using Swift CLI
98+
**SFT**:
99+
```bash
100+
# Experimental environment: A10, 3090, A100, ...
101+
# 10GB GPU memory
102+
CUDA_VISIBLE_DEVICES=0 swift sft --model_id_or_path qwen/Qwen-7B-Chat-Int4 --dataset blossom-math-zh
103+
104+
# Using DDP
105+
# Experimental environment: 2 * 3090
106+
# 2 * 10GB GPU memory
107+
CUDA_VISIBLE_DEVICES=0,1 \
108+
NPROC_PER_NODE=2 \
109+
swift sft \
110+
--model_id_or_path qwen/Qwen-7B-Chat-Int4 \
111+
--dataset blossom-math-zh \
112+
113+
# Using custom dataset
114+
CUDA_VISIBLE_DEVICES=0 swift sft --model_id_or_path qwen/Qwen-7B-Chat-Int4 --custom_train_dataset_path chatml.jsonl
90115
```
91116

117+
**Inference**:
118+
```bash
119+
CUDA_VISIBLE_DEVICES=0 swift infer --ckpt_dir 'xxx/vx_xxx/checkpoint-xxx'
120+
```
121+
122+
**Web-UI**:
123+
```bash
124+
CUDA_VISIBLE_DEVICES=0 swift web-ui --ckpt_dir 'xxx/vx_xxx/checkpoint-xxx'
125+
```
92126

93127
### Features
94128
- Supported SFT Methods: [lora](https://arxiv.org/abs/2106.09685), [qlora](https://arxiv.org/abs/2305.14314), full(full parameter fine-tuning)
@@ -125,7 +159,7 @@ infer_main(infer_args)
125159
- Chat: chatml(qwen), baichuan, chatglm2, chatglm3, llama, openbuddy-llama, default, internlm, xverse, skywork
126160

127161

128-
# Installation
162+
# 🛠️ Installation
129163

130164
SWIFT is running in Python environment. Please make sure your python version is higher than 3.8.
131165

@@ -151,7 +185,7 @@ SWIFT requires torch>=1.13.
151185
docker pull registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.8.0-py38-torch2.0.1-tf2.13.0-1.9.1
152186
```
153187

154-
# Getting Started
188+
# 🚀 Getting Started
155189

156190
SWIFT supports multiple tuners, as well as tuners provided by [PEFT](https://github.com/huggingface/peft). To use these tuners, simply call:
157191

@@ -289,7 +323,7 @@ output
289323
The config/weights stored in the output dir is the config of `extra_state_keys` and the weights of it. This is different from PEFT, which stores the weights and config of the `default` tuner.
290324

291325

292-
# Learn More
326+
# 🔍 Learn More
293327

294328
- [ModelScope library](https://github.com/modelscope/modelscope/)
295329

README_CN.md

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
中文&nbsp | &nbsp<a href="README.md">English</a>
1313
</p>
1414

15-
# 简介
15+
# 📖 简介
1616
SWIFT(Scalable lightWeight Infrastructure for Fine-Tuning)是一个可扩展的轻量级一站式训练、推理深度学习框架。它集成了各种高效的微调方法,如LoRA、QLoRA、阿里云自研的ResTuning-Bypass等,以及开箱即用的训练推理脚本,使开发者可以在单张商业级显卡上微调推理LLM&AIGC模型。此外,SWIFT与[PEFT](https://github.com/huggingface/peft)完全兼容,使开发者可以在ModelScope模型体系中使用PEFT的能力。
1717

1818
目前支持的方法:
@@ -34,7 +34,7 @@ SWIFT(Scalable lightWeight Infrastructure for Fine-Tuning)是一个可扩展
3434

3535
用户可以查看 [Swift官方文档](docs/source/GetStarted/Introduction.md) 来了解详细信息。
3636

37-
## 新闻
37+
## 🎉 新闻
3838

3939
- 🔥 2023.10.30: 支持 QA-LoRA 和 LongLoRA两种新的tuners
4040
- 🔥 2023.10.30: 支持使用ROME(Rank One Model Editing)来编辑模型,在无需训练的情况下即可给模型灌注新知识!
@@ -46,10 +46,12 @@ SWIFT(Scalable lightWeight Infrastructure for Fine-Tuning)是一个可扩展
4646
- 🔥 2023.9.25: 支持**qwen-14b**系列模型: qwen-14b, qwen-14b-chat. 对应的sh脚本可以查看`scripts/qwen_14b`, `scripts/qwen_14b_chat`.
4747
- 2023.9.12: 支持MP+DDP的方式训练, 加快全参数微调的速度, 对应的sh脚本可以查看`scripts/qwen_7b_chat/full_mp_ddp/sft.sh`.
4848

49-
## 大模型微调的例子
49+
## 大模型微调的例子
5050
可以[在这里](https://github.com/modelscope/swift/tree/main/examples/pytorch/llm) 查看LLM微调的使用文档。
5151

5252
### 简单使用
53+
快速对LLM进行微调, 推理并搭建Web-UI.
54+
#### 使用python运行
5355
```bash
5456
git clone https://github.com/modelscope/swift.git
5557
cd swift
@@ -64,8 +66,10 @@ os.environ['CUDA_VISIBLE_DEVICES'] = '0'
6466

6567
import torch
6668

67-
from swift.llm import DatasetName, InferArguments, ModelType, SftArguments
68-
from swift.llm.run import infer_main, sft_main
69+
from swift.llm import (
70+
DatasetName, InferArguments, ModelType, SftArguments
71+
)
72+
from swift.llm.run import infer_main, sft_main, web_ui_main
6973

7074
model_type = ModelType.qwen_7b_chat_int4
7175
sft_args = SftArguments(
@@ -79,12 +83,43 @@ best_ckpt_dir = sft_main(sft_args)
7983
print(f'best_ckpt_dir: {best_ckpt_dir}')
8084
torch.cuda.empty_cache()
8185
infer_args = InferArguments(
82-
model_type=sft_args.model_type,
8386
ckpt_dir=best_ckpt_dir,
84-
dataset=sft_args.dataset,
87+
load_args_from_ckpt_dir=True,
8588
stream=True,
8689
show_dataset_sample=5)
8790
infer_main(infer_args)
91+
torch.cuda.empty_cache()
92+
web_ui_main(infer_args)
93+
```
94+
95+
#### 使用Swift CLI运行
96+
**微调**:
97+
```bash
98+
# Experimental environment: A10, 3090, A100, ...
99+
# 10GB GPU memory
100+
CUDA_VISIBLE_DEVICES=0 swift sft --model_id_or_path qwen/Qwen-7B-Chat-Int4 --dataset blossom-math-zh
101+
102+
# 使用DDP
103+
# Experimental environment: 2 * 3090
104+
# 2 * 10GB GPU memory
105+
CUDA_VISIBLE_DEVICES=0,1 \
106+
NPROC_PER_NODE=2 \
107+
swift sft \
108+
--model_id_or_path qwen/Qwen-7B-Chat-Int4 \
109+
--dataset blossom-math-zh \
110+
111+
# 使用自己的数据集
112+
CUDA_VISIBLE_DEVICES=0 swift sft --model_id_or_path qwen/Qwen-7B-Chat-Int4 --custom_train_dataset_path chatml.jsonl
113+
```
114+
115+
**推理**:
116+
```bash
117+
CUDA_VISIBLE_DEVICES=0 swift infer --ckpt_dir 'xxx/vx_xxx/checkpoint-xxx'
118+
```
119+
120+
**Web-UI**
121+
```bash
122+
CUDA_VISIBLE_DEVICES=0 swift web-ui --ckpt_dir 'xxx/vx_xxx/checkpoint-xxx'
88123
```
89124

90125

@@ -123,7 +158,7 @@ infer_main(infer_args)
123158
- 对话: chatml(qwen), baichuan, chatglm2, chatglm3, llama, openbuddy-llama, default, internlm, xverse, skywork
124159

125160

126-
# 安装
161+
# 🛠️ 安装
127162

128163
SWIFT在Python环境中运行。请确保您的Python版本高于3.8。
129164

@@ -149,7 +184,7 @@ SWIFT依赖torch>=1.13。
149184
docker pull registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.8.0-py38-torch2.0.1-tf2.13.0-1.9.1
150185
```
151186

152-
# 快速开始
187+
# 🚀 快速开始
153188
SWIFT支持多个tuners,包括由[PEFT](https://github.com/huggingface/peft)提供的tuners。要使用这些tuners,只需调用:
154189
```python
155190
from swift import Swift, LoRAConfig
@@ -281,7 +316,7 @@ output
281316
存储在output目录中的config/weights是extra_state_keys的配置和权重。这与Peft不同,Peft存储了`default` tuner的config/weights。
282317

283318

284-
# Learn More
319+
# 🔍 Learn More
285320

286321
- [ModelScope库](https://github.com/modelscope/modelscope/)
287322

0 commit comments

Comments
 (0)