Skip to content

Commit f82100d

Browse files
committed
Merge branch 'main' into release/1.1
* main: fix internlm-20b-chat model_id (#88) Add internlm agent (#86) add mm_notebook (#85) Replace with loralib and add unload lora interface (#83) Add sphinx doc builder (#77) add notebook (#81) update feat: merge lora (#82) fix unpatch_lora (#80) Fix bug: LoRA not work with diffusers>0.20.0 (#73) update readme (#76) Feat 0919 (#78) fix bug: internlm-20b (#75) Fix bug 0917 (#74) update publish workflow bump version to 1.1.0
2 parents 331e2c5 + 11383fe commit f82100d

File tree

108 files changed

+2750
-1710
lines changed

Some content is hidden

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

108 files changed

+2750
-1710
lines changed

.dev_scripts/build_docs.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pip install -r requirements/docs.txt
2+
cd docs
3+
rm -rf build
4+
5+
# update api rst
6+
#rm -rf source/api/
7+
#sphinx-apidoc --module-first -o source/api/ ../modelscope/
8+
make html

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ replace.sh
124124
result.png
125125
result.jpg
126126
result.mp4
127-
runs/
127+
output/
128128
*.out
129129

130130
# Pytorch

README.md

Lines changed: 27 additions & 42 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,77 +23,74 @@ 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/source/GetStarted/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)
43-
3. baichuan series: baichuan-7b, baichuan-13b, baichuan-13b-chat, baichuan2-7b, baichuan2-7b-chat, baichuan2-13b, baichuan2-13b-chat
44-
4. chatglm2 series: chatglm2-6b, chatglm2-6b-32k
45-
5. llama series: llama2-7b, llama2-7b-chat, llama2-13b, llama2-13b-chat, llama2-70b, llama2-70b-chat
46-
6. openbuddy-llama series: openbuddy-llama2-13b, openbuddy-llama-65b, openbuddy-llama2-70b
47-
7. internlm series: internlm-7b, internlm-7b-chat, internlm-7b-chat-8k
48-
8. other: polylm-13b, seqgpt-560m
43+
3. baichuan series: baichuan-7b, baichuan-13b, baichuan-13b-chat, baichuan2-7b, [baichuan2-7b-chat](https://modelscope.cn/models/baichuan-inc/Baichuan2-7B-Chat/summary), baichuan2-13b, baichuan2-13b-chat
44+
4. chatglm2 series: [chatglm2-6b](https://modelscope.cn/models/ZhipuAI/chatglm2-6b/summary), chatglm2-6b-32k
45+
5. llama series: llama2-7b, llama2-7b-chat, llama2-13b, llama2-13b-chat, llama2-70b, [llama2-70b-chat](https://modelscope.cn/models/modelscope/Llama-2-70b-chat-ms/summary)
46+
6. openbuddy-llama series: openbuddy-llama2-13b, openbuddy-llama-65b, [openbuddy-llama2-70b](https://modelscope.cn/models/OpenBuddy/openbuddy-llama2-70b-v10.1-bf16/summary)
47+
7. internlm series: internlm-7b, internlm-7b-chat, internlm-7b-chat-8k, [internlm-20b](https://modelscope.cn/models/Shanghai_AI_Laboratory/internlm-20b/summary), [internlm-20b-chat](https://modelscope.cn/models/Shanghai_AI_Laboratory/internlm-chat-20b/summary)
48+
8. other: [polylm-13b](https://modelscope.cn/models/damo/nlp_polylm_13b_text_generation/summary), [seqgpt-560m](https://modelscope.cn/models/damo/nlp_seqgpt-560m/summary)
4949
3. supported features: quantization, DDP, model parallelism(device map), gradient checkpointing, gradient accumulation, pushing to modelscope hub, custom datasets, multimodal and agent SFT, mutli-round chat, ...
5050
4. supported datasets:
51-
1. NLP: alpaca-en(gpt4), alpaca-zh(gpt4), finance-en, multi-alpaca-all, code-en, instinwild-en, instinwild-zh, cot-en, cot-zh, firefly-all-zh, poetry-zh, instruct-en, gpt4all-en, cmnli-zh, jd-zh, dureader-robust-zh, medical-en, medical-zh, medical-mini-zh, sharegpt-en, sharegpt-zh
51+
1. NLP: [alpaca-en](https://modelscope.cn/datasets/AI-ModelScope/alpaca-gpt4-data-en/summary)(gpt4), [alpaca-zh](https://modelscope.cn/datasets/AI-ModelScope/alpaca-gpt4-data-zh/summary)(gpt4), finance-en, multi-alpaca-all, code-en, instinwild-en, instinwild-zh, cot-en, cot-zh, firefly-all-zh, poetry-zh, instruct-en, gpt4all-en, cmnli-zh, [jd-zh](https://modelscope.cn/datasets/DAMO_NLP/jd/summary), [dureader-robust-zh](https://modelscope.cn/datasets/modelscope/DuReader_robust-QG/summary), medical-en, medical-zh, medical-mini-zh, sharegpt-en, sharegpt-zh, [code-python-zh](https://modelscope.cn/datasets/codefuse-ai/CodeExercise-Python-27k/summary), [advertise-gen](https://modelscope.cn/datasets/lvjianjin/AdvertiseGen/summary)
5252
2. agent: [damo-agent-zh](https://modelscope.cn/datasets/damo/MSAgent-Bench/summary), damo-agent-mini-zh
53-
3. multi-modal: coco-en
54-
4. other: cls-fudan-news-zh, ner-jave-zh
53+
3. multi-modal: [coco-en](https://modelscope.cn/datasets/modelscope/coco_2014_caption/summary)
54+
4. other: [cls-fudan-news-zh](https://modelscope.cn/datasets/damo/zh_cls_fudan-news/files), [ner-jave-zh](https://modelscope.cn/datasets/damo/zh_ner-JAVE/summary)
5555
5. supported templates: chatml(qwen), baichuan, chatglm2, llama, openbuddy-llama, default, default-generation
5656

5757
# Installation
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

0 commit comments

Comments
 (0)