Skip to content

Commit 772e26c

Browse files
update readme (#76)
1 parent 6fd1c17 commit 772e26c

File tree

4 files changed

+49
-78
lines changed

4 files changed

+49
-78
lines changed

README.md

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
# Introduction
1616

17-
SWIFT (Scalable lightWeight Infrastructure for Fine-Tuning) is an extensible framwork designed to faciliate lightweight model fine-tuning. 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 modles, 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.
17+
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

1919
Currently supported approches (and counting):
2020

@@ -23,20 +23,20 @@ Currently supported approches (and counting):
2323
3. Prompt Tuning: [Visual Prompt Tuning](https://arxiv.org/abs/2203.12119)
2424
4. Side: [Side-Tuning: A Baseline for Network Adaptation via Additive Side Networks](https://arxiv.org/abs/1912.13503)
2525
5. ResTuning-Bypass
26-
7. All tuners offered on [Peft](https://github.com/huggingface/peft)
26+
7. All tuners offered on [PEFT](https://github.com/huggingface/peft)
2727

2828
Key features:
2929

3030
1. By integrating the ModelScope library, models can be readily obatined via a model-id.
31-
2. Tuners provided by SWIFT be combined together to allow exploration of multiple tuners on a model for best result.
32-
3. Support calling `activate_adapter``deactivate_adapter` to activate/deactivate a single tuner. User can use one model with multiple tuners in different threads.
31+
2. Tuners provided by SWIFT can be combined together to allow exploration of multiple tuners on a model for best result.
32+
3. Support calling `activate_adapter` or `deactivate_adapter` or `set_active_adapters` to activate/deactivate tuners. User can inference with one model and multiple tuners in different threads independently.
3333

34-
Users can check the [documentation of Swift](./docs/Get Started/1.Introduction.md) to get detail tutorials.
34+
Users can check the [documentation of SWIFT](./docs/Get Started/1.Introduction.md) to get detail tutorials.
3535

3636
## LLM SFT Example
3737
[code link](https://github.com/modelscope/swift/tree/main/examples/pytorch/llm)
3838

39-
1. supported SFT methods: [lora](https://arxiv.org/abs/2106.09685), [qlora](https://arxiv.org/abs/2305.14314), full(full parameter fine-tuning)
39+
1. supported SFT methods: [LoRA](https://arxiv.org/abs/2106.09685), [QLoRA](https://arxiv.org/abs/2305.14314), full(full parameter fine-tuning)
4040
2. supported models:
4141
1. qwen series: qwen-7b, [qwen-7b-chat](https://github.com/QwenLM/Qwen-7B)
4242
2. qwen-vl series: qwen-vl, [qwen-vl-chat](https://github.com/QwenLM/Qwen-VL)
@@ -58,42 +58,39 @@ Users can check the [documentation of Swift](./docs/Get Started/1.Introduction.m
5858

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

61-
Please install SWIFT by the `pip` command:
61+
- Install SWIFT by the `pip` command:
6262

6363
```shell
6464
pip install ms-swift -U
6565
```
6666

67-
If you want to install SWIFT by source code, please run:
67+
- Install SWIFT by source code(for running sft/infer examples), please run:
6868

6969
```shell
7070
git clone https://github.com/modelscope/swift.git
7171
cd swift
7272
pip install -e .
7373
```
7474

75-
If you are using source code, please remember install requirements by:
76-
```shell
77-
pip install -r requirements/framework.txt
78-
```
79-
8075
SWIFT requires torch>=1.13.
8176

82-
We also recommend to use SWIFT in our docker image:
77+
- Use SWIFT in our docker image:
78+
8379
```shell
84-
docker pull registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.7.1-py38-torch2.0.1-tf1.15.5-1.8.0
80+
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
8581
```
8682

8783
# Getting Started
8884

89-
SWIFT supports multiple tuners, as well as tuners provided by [Peft](https://github.com/huggingface/peft). To use the these tuners, simply call:
85+
SWIFT supports multiple tuners, as well as tuners provided by [PEFT](https://github.com/huggingface/peft). To use these tuners, simply call:
9086

9187
```python
92-
from swift import Swift
88+
from swift import Swift, LoRAConfig
89+
config = LoRAConfig(...)
9390
model = Swift.prepare_model(model, config, extra_state_keys=['...'])
9491
```
9592

96-
The code snippet above initialized the tuner randomly. The input model is an instance of `torch.nn.Module`, config is a subclass instance of `SwiftConfig` or `PeftConfig`. extra_state_keys is
93+
The code snippet above initialized the tuner randomly. The input model is an instance of `torch.nn.Module`, the config is a subclass instance of `SwiftConfig` or `PeftConfig`. extra_state_keys is
9794
the extra module weights(like the linear head) to be trained and stored in the output dir.
9895

9996
You may combine multiple tuners by:
@@ -103,7 +100,7 @@ from swift import Swift, LoRAConfig, PromptConfig
103100
model = Swift.prepare_model(model, {'lora': LoRAConfig(...), 'prompt': PromptConfig(...)})
104101
```
105102

106-
You can all `save_pretrained` and `push_to_hub` after finetuning:
103+
Call `save_pretrained` and `push_to_hub` after finetuning:
107104

108105
```python
109106
from swift import push_to_hub
@@ -199,20 +196,8 @@ model_wrapped = Swift.prepare_model(model, lora_config)
199196
model_wrapped = Swift.from_pretrained(model, 'some-id-in-the-modelscope-modelhub')
200197
```
201198

202-
or:
203-
204-
```python
205-
from swift import LoraConfig, get_peft_model, PeftModel
206-
from peft import TaskType
207-
lora_config = LoraConfig(target_modules=['query', 'key', 'value'], task_type=TaskType.CAUSAL_LM)
208-
model_wrapped = get_peft_model(model, lora_config)
209-
210-
# or call from_pretrained to load weights in the modelhub
211-
model_wrapped = PeftModel.from_pretrained(model, 'some-id-in-the-modelscope-modelhub')
212-
```
213-
214199

215-
The saving strategy between Swift tuners and Peft tuners are slightly different. You can name a tuner of a SWIFT by:
200+
The saving strategy between Swift tuners and Peft tuners are slightly different. You can name a tuner by:
216201

217202
```python
218203
model = Swift.prepare_model(model, {'default': LoRAConfig(...)})
@@ -230,7 +215,7 @@ output
230215
|-- adapter_model.bin
231216
```
232217

233-
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.
218+
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.
234219

235220

236221
# Learn More

README_CN.md

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,28 @@
1313
</p>
1414

1515
# 简介
16-
SWIFT(Scalable lightWeight Infrastructure for Fine-Tuning)是一个可扩展的框架,旨在促进轻量级模型的微调。它集成了各种高效的微调方法的实现,采用了参数高效、内存高效和时间高效的方法。SWIFT可以无缝地集成到ModelScope生态系统中,并提供微调各种模型的能力,主要侧重于LLMs和视觉模型。此外,SWIFT与[Peft](https://github.com/huggingface/peft)完全兼容,使用户能够利用熟悉的Peft接口对ModelScope模型进行微调
16+
SWIFT(Scalable lightWeight Infrastructure for Fine-Tuning)是一个可扩展的轻量级一站式训练、推理深度学习框架。它集成了各种高效的微调方法,如LoRA、QLoRA、阿里云自研的ResTuning-Bypass等,以及开箱即用的训练推理脚本,使开发者可以在单张商业级显卡上微调推理LLM&AIGC模型。此外,SWIFT与[PEFT](https://github.com/huggingface/peft)完全兼容,使开发者可以在ModelScope模型体系中使用PEFT的能力
1717

18-
目前支持的方法(数量持续增加)
18+
目前支持的方法:
1919

2020
1. LoRA:[LORA: LOW-RANK ADAPTATION OF LARGE LANGUAGE MODELS](https://arxiv.org/abs/2106.09685)
2121
2. Adapter:[Parameter-Efficient Transfer Learning for NLP](http://arxiv.org/abs/1902.00751)
22-
3. Prompt Tuning: [Visual Prompt Tuning](https://arxiv.org/abs/2203.12119)
22+
3. Prompt: [Visual Prompt Tuning](https://arxiv.org/abs/2203.12119)
2323
4. Side: [Side-Tuning: A Baseline for Network Adaptation via Additive Side Networks](https://arxiv.org/abs/1912.13503)
2424
5. ResTuning-Bypass
25-
6. 所有在[Peft](https://github.com/huggingface/peft)上提供的tuners
25+
6. 所有在[PEFT](https://github.com/huggingface/peft)上提供的tuners
2626

27-
关键特点
28-
1. 通过集成ModelScope库,可以通过model id轻松获取模型。
29-
2. SWIFT提供的tuners可以组合在一起,以便在模型上探索多个tuners,以获得最佳结果。
30-
3. 支持调用`activate_adapter``deactivate_adapter`来使tuner激活或失活,用户可以在推理时用一个模型在不同线程中使用多种tuners而互不干扰
27+
主要能力
28+
1. 可以通过model-id使SWIFT或PEFT的方法使用ModelScope Hub中的模型
29+
2. 在单次训练或推理中可以使用多个tuners
30+
3. 支持调用`activate_adapter``deactivate_adapter``set_active_adapters`来使部分tuner激活或失活,用户可以在推理时同时加载多个独立的tuners在不同线程中并行使用
3131

3232
用户可以查看 [Swift官方文档](./docs/Get Started/1.Introduction.md) 来了解详细信息。
3333

3434
## 大模型微调的例子
3535
[code link](https://github.com/modelscope/swift/tree/main/examples/pytorch/llm)
3636

37-
1. 支持的SFT方法: [lora](https://arxiv.org/abs/2106.09685), [qlora](https://arxiv.org/abs/2305.14314), 全参数微调
37+
1. 支持的SFT方法: [LoRA](https://arxiv.org/abs/2106.09685), [QLoRA](https://arxiv.org/abs/2305.14314), 全参数微调
3838
2. 支持的模型:
3939
1. qwen 系列: qwen-7b, [qwen-7b-chat](https://github.com/QwenLM/Qwen-7B)
4040
2. qwen-vl 系列: qwen-vl, [qwen-vl-chat](https://github.com/QwenLM/Qwen-VL)
@@ -56,39 +56,36 @@ SWIFT(Scalable lightWeight Infrastructure for Fine-Tuning)是一个可扩展
5656

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

59-
请使用pip命令安装SWIFT
59+
- 方法1:使用pip命令安装SWIFT
6060

6161
```shell
6262
pip install ms-swift -U
6363
```
6464

65-
如果您想通过源代码安装SWIFT,请运行以下命令:
65+
- 方法2:通过源代码安装SWIFT(方便运行训练推理脚本),请运行以下命令:
6666

6767
```shell
6868
git clone https://github.com/modelscope/swift.git
6969
cd swift
7070
pip install -e .
7171
```
7272

73-
如果您在使用源代码,请记得通过以下方式安装所需的依赖项:
74-
```shell
75-
pip install -r requirements/framework.txt
76-
```
73+
SWIFT依赖torch>=1.13。
7774

78-
SWIFT requires torch>=1.13.
75+
- 方法3:在我们的Docker镜像中使用SWIFT
7976

80-
我们还建议在我们的Docker镜像中使用SWIFT
8177
```shell
82-
docker pull registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.7.1-py38-torch2.0.1-tf1.15.5-1.8.0
78+
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
8379
```
8480

8581
# 快速开始
86-
SWIFT支持多个tuners,包括由[Peft](https://github.com/huggingface/peft)提供的调谐器。要使用这些调谐器,只需调用:
82+
SWIFT支持多个tuners,包括由[PEFT](https://github.com/huggingface/peft)提供的tuners。要使用这些tuners,只需调用:
8783
```python
88-
from swift import Swift
84+
from swift import Swift, LoRAConfig
85+
config = LoRAConfig(...)
8986
model = Swift.prepare_model(model, config, extra_state_keys=['...'])
9087
```
91-
上面的代码片段随机初始化了tuner。输入模型是torch.nn.Module的一个实例,配置是SwiftConfig或PeftConfig的子类实例。extra_state_keys是要训练并存储在输出目录中的额外模块权重(如linear head)。
88+
上面的代码片段随机初始化了tuner。输入model是torch.nn.Module的一个实例,config是SwiftConfig或PeftConfig的子类实例。extra_state_keys是要训练并存储在输出目录中的额外模块权重(如linear head)。
9289

9390
您可以通过以下方式组合多个tuners:
9491
```python
@@ -105,7 +102,7 @@ push_to_hub('my-group/some-repo-id-modelscope', 'some-output-folder', token='som
105102
```
106103
假设`my-group/some-repo-id-modelscope`是Hub中的model-id,而`some-ms-token`是用于上传的令牌。
107104

108-
使用model-id进行后续推断
105+
使用model-id进行后续推理
109106

110107
```python
111108
from swift import Swift
@@ -139,7 +136,7 @@ model = Model.from_pretrained('modelscope/Llama-2-7b-ms', device_map='auto')
139136
model = SwiftModel.from_pretrained(model, 'my-group/swift_llama2', device_map='auto')
140137
```
141138

142-
这是一个使用transformers库创建模型,并使用SWIFT进行高效微调的示例。
139+
这是一个使用transformers库实例化模型,并使用SWIFT进行高效微调的示例。
143140

144141
```python
145142
from swift import Swift, LoRAConfig, AdapterConfig, PromptConfig
@@ -180,7 +177,7 @@ model.get_trainable_parameters()
180177
# 'trainable params: 838,776 || all params: 87,406,432 || trainable%: 0.9596273189597764'
181178
```
182179

183-
您可以在SWIFT中使用Peft提供的功能
180+
可以在SWIFT中使用PEFT提供的功能
184181

185182
```python
186183
from swift import LoraConfig, Swift
@@ -192,26 +189,14 @@ model_wrapped = Swift.prepare_model(model, lora_config)
192189
model_wrapped = Swift.from_pretrained(model, 'some-id-in-the-modelscope-modelhub')
193190
```
194191

195-
或者:
196-
197-
```python
198-
from swift import LoraConfig, get_peft_model, PeftModel
199-
from peft import TaskType
200-
lora_config = LoraConfig(target_modules=['query', 'key', 'value'], task_type=TaskType.CAUSAL_LM)
201-
model_wrapped = get_peft_model(model, lora_config)
202-
203-
# 或者使用from_pretrained从modelscope hub中加载权重。
204-
model_wrapped = PeftModel.from_pretrained(model, 'some-id-in-the-modelscope-modelhub')
205-
```
206-
207-
Swift tuners和Peft tuners之间的保存策略略有不同。您可以通过以下方式为Swift tuners命名:
192+
Swift tuners和Peft tuners之间的保存策略略有不同。可以通过以下方式为Swift tuners命名:
208193

209194
```python
210195
model = Swift.prepare_model(model, {'default': LoRAConfig(...)})
211196
model.save_pretrained('./output')
212197
```
213198

214-
在输出目录中,您将会得到以下类似的目录结构
199+
在output目录中将会得到以下类似的目录结构
215200

216201
```text
217202
output
@@ -222,14 +207,14 @@ output
222207
|-- adapter_model.bin
223208
```
224209

225-
存储在输出目录中的config/weights是extra_state_keys的配置和权重。这与Peft不同,Peft存储了default调谐器的权重和配置
210+
存储在output目录中的config/weights是extra_state_keys的配置和权重。这与Peft不同,Peft存储了`default` tuner的config/weights
226211

227212

228213
# Learn More
229214

230215
- [ModelScope库](https://github.com/modelscope/modelscope/)
231216

232-
ModelScope库是ModelScope项目的模型库,包含大量热门模型
217+
ModelScope库是ModelScope项目的模型库,包含了各模态热门的深度学习模型
233218

234219
- [将自己的模型贡献给ModelScope](https://modelscope.cn/docs/ModelScope%E6%A8%A1%E5%9E%8B%E6%8E%A5%E5%85%A5%E6%B5%81%E7%A8%8B%E6%A6%82%E8%A7%88)
235220

docs/Modules/2.lora.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# LoRA
22

3-
LoRA是[LoRA: Low-Rank Adaptation of Large Language Models](https://arxiv.org/abs/2106.09685) 论文提供的轻量级训练组件。LoRA可以添加到Linear、Embedding、Conv2d等算子上生效
3+
LoRA是[LoRA: Low-Rank Adaptation of Large Language Models](https://arxiv.org/abs/2106.09685) 论文提供的轻量级训练组件。LoRA可以添加到Linear、Embedding、Conv2d、Quantized-Linear等算子上生效
44

55
>```python
66
>LoRAConfig (

examples/pytorch/llm/src/llm_sft.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
Seq2SeqTrainingArguments, Swift, get_logger)
1616
from swift.utils import (add_version_to_work_dir, broadcast_string,
1717
check_json_format, compute_nlg_metrics,
18-
data_collate_fn, get_dist_setting, is_ddp_plus_mp,
19-
is_dist, is_master, parse_args, plot_images,
20-
print_example, print_model_info, seed_everything,
21-
show_layers, sort_by_max_length, stat_dataset)
18+
data_collate_fn, find_all_linear_for_lora,
19+
get_dist_setting, is_ddp_plus_mp, is_dist, is_master,
20+
parse_args, plot_images, print_example,
21+
print_model_info, seed_everything, show_layers,
22+
sort_by_max_length, stat_dataset)
2223

2324
logger = get_logger()
2425

0 commit comments

Comments
 (0)