From 62f0d16b27081e3c1b47a5d8238c002167b16cc2 Mon Sep 17 00:00:00 2001 From: "yuze.zyz" Date: Wed, 15 Nov 2023 14:05:07 +0800 Subject: [PATCH 1/5] fix (cherry picked from commit 3d6f8ff1ddf9241cfbe7d4f06471dedbc555e035) --- README.md | 6 +++--- README_CN.md | 6 +++--- docs/source/GetStarted/ResTuning.md | 17 +++++++++-------- .../SWIFT\345\256\211\350\243\205.md" | 2 +- .../{ => GetStarted}/resources/xinference.jpg | Bin .../\344\275\277\347\224\250tuners.md" | 0 ...345\206\205\344\275\277\347\224\250PEFT.md" | 13 +++++++++++++ ...253\351\200\237\344\275\277\347\224\250.md" | 15 +++++++-------- ...206\350\204\232\346\211\213\346\236\266.md" | 0 ...250\347\275\262\346\214\207\345\215\227.md" | 2 +- docs/source/index.rst | 12 ++++++------ 11 files changed, 43 insertions(+), 30 deletions(-) rename docs/source/GetStarted/Installation.md => "docs/source/GetStarted/SWIFT\345\256\211\350\243\205.md" (96%) rename docs/source/{ => GetStarted}/resources/xinference.jpg (100%) rename docs/source/GetStarted/Use in train and infer.md => "docs/source/GetStarted/\344\275\277\347\224\250tuners.md" (100%) rename docs/source/GetStarted/Work with Peft.md => "docs/source/GetStarted/\345\234\250SWIFT\345\206\205\344\275\277\347\224\250PEFT.md" (96%) rename docs/source/GetStarted/Introduction.md => "docs/source/GetStarted/\345\277\253\351\200\237\344\275\277\347\224\250.md" (83%) rename docs/source/GetStarted/Examples.md => "docs/source/GetStarted/\350\256\255\347\273\203\346\216\250\347\220\206\350\204\232\346\211\213\346\236\266.md" (100%) rename docs/source/GetStarted/Deployment.md => "docs/source/GetStarted/\351\203\250\347\275\262\346\214\207\345\215\227.md" (99%) diff --git a/README.md b/README.md index 990beb9664..cabe4039d9 100644 --- a/README.md +++ b/README.md @@ -35,15 +35,15 @@ Key features: 2. Tuners provided by SWIFT can be combined together to allow exploration of multiple tuners on a model for best result. 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. 4. Support training and inference with scripts/CLI,meanwhile support inference with Web-UI. -5. Support model deployment(vllm/chatglm.cpp/xinference),Check [Official documentation](./docs/source/GetStarted/Deployment.md) for details. +5. Support model deployment(vllm/chatglm.cpp/xinference),Check [Official documentation](./docs/source/GetStarted/部署指南.md) for details. -Users can check the [documentation of Swift](docs/source/GetStarted/Introduction.md) to get detail tutorials. +Users can check the [documentation of Swift](docs/source/GetStarted/快速开始.md) to get detail tutorials. ### 🎉 News - 🔥 2023.11.11: **NEFTune** Supported, Use is with `Swift.prepare_model(model, NEFTuneConfig())` - 🔥 2023.11.11: Support training and inference with **CLI**, and inference with **Web-UI**. Check the [Run using Swift CLI](https://github.com/modelscope/swift/tree/main#run-using-swift-cli) chapter for details. -- 🔥 2023.11.11: Support model **deployment**(vllm/chatglm.cpp/xinference),Check [Official documentation](./docs/source/GetStarted/Deployment.md) for details. +- 🔥 2023.11.11: Support model **deployment**(vllm/chatglm.cpp/xinference),Check [Official documentation](./docs/source/GetStarted/部署指南.md) for details. - 🔥 2023.11.10: Support for **bluelm** series models: bluelm-7b, bluelm-7b-chat, bluelm-7b-32k, bluelm-7b-chat-32k. The corresponding shell script can be found in [bluelm_7b_chat](https://github.com/modelscope/swift/tree/main/examples/pytorch/llm/scripts/bluelm_7b_chat). - 🔥 2023.11.08: Support the finetuning of **xverse-65b** model, scripts can be found at: [xverse_65b](https://github.com/modelscope/swift/tree/main/examples/pytorch/llm/scripts/xverse_65b). - 🔥 2023.11.07: Support the finetuning of **yi-6b**, **yi-34b** model, scripts can be found at: [yi_6b](https://github.com/modelscope/swift/tree/main/examples/pytorch/llm/scripts/yi_6b), [yi_34b](https://github.com/modelscope/swift/tree/main/examples/pytorch/llm/scripts/yi_34b). diff --git a/README_CN.md b/README_CN.md index 2bac06ccab..aeac9905ca 100644 --- a/README_CN.md +++ b/README_CN.md @@ -33,15 +33,15 @@ SWIFT(Scalable lightWeight Infrastructure for Fine-Tuning)是一个可扩展 2. 在单次训练或推理中可以使用多个tuners 3. 支持调用`activate_adapter`或`deactivate_adapter`或`set_active_adapters`来使部分tuner激活或失活,用户可以在推理时同时加载多个独立的tuners在不同线程中并行使用。 4. 支持通过脚本方式和命令行方式开启训练和推理,同时支持Web-UI方式进行推理。 -5. 支持模型训练后的部署链路(vllm/chatglm.cpp/xinference),详情可以查看[官方文档](./docs/source/GetStarted/Deployment.md)。 +5. 支持模型训练后的部署链路(vllm/chatglm.cpp/xinference),详情可以查看[官方文档](./docs/source/GetStarted/部署指南.md)。 -用户可以查看 [Swift官方文档](docs/source/GetStarted/Introduction.md) 来了解详细信息。 +用户可以查看 [Swift官方文档](docs/source/GetStarted/快速开始.md) 来了解详细信息。 ## 🎉 新闻 - 🔥 2023.11.11: 支持**NEFTune**, 使用`Swift.prepare_model(model, NEFTuneConfig())`即可开启. - 🔥 2023.11.11: 支持**命令行**训练推理和**Web-UI**推理, 详情可以查看下方的`使用Swift CLI运行`章节. -- 🔥 2023.11.11: 支持模型训练后的**部署**链路(vllm/chatglm.cpp/xinference),详情可以查看[官方文档](./docs/source/GetStarted/Deployment.md). +- 🔥 2023.11.11: 支持模型训练后的**部署**链路(vllm/chatglm.cpp/xinference),详情可以查看[官方文档](./docs/source/GetStarted/部署指南.md). - 🔥 2023.11.10: 支持**bluelm**系列模型: bluelm-7b, bluelm-7b-chat, bluelm-7b-32k, bluelm-7b-chat-32k. 对应的sh脚本可以查看[bluelm_7b_chat](https://github.com/modelscope/swift/tree/main/examples/pytorch/llm/scripts/bluelm_7b_chat). - 🔥 2023.11.08: 支持**xverse-65b**模型的训练和推理流程,脚本在[xverse_65b](https://github.com/modelscope/swift/tree/main/examples/pytorch/llm/scripts/xverse_65b). - 🔥 2023.11.07: 支持**yi-6b**, **yi-34b**模型的训练和推理流程,脚本在[yi_6b](https://github.com/modelscope/swift/tree/main/examples/pytorch/llm/scripts/yi_6b), [yi_34b](https://github.com/modelscope/swift/tree/main/examples/pytorch/llm/scripts/yi_34b). diff --git a/docs/source/GetStarted/ResTuning.md b/docs/source/GetStarted/ResTuning.md index e0f9cd5708..21ce40f4b5 100644 --- a/docs/source/GetStarted/ResTuning.md +++ b/docs/source/GetStarted/ResTuning.md @@ -6,23 +6,24 @@ -Res-Tuning is a flexible and efficient tuning paradigm. We manage to free the design of tuners from the network architecture, facilitating flexible combination of various tuning strategies and further extend a memory-efficient bypass variant, which significantly reduces the memory consumption and multi-task inference cost. +Res-Tuning 是一种灵活高效的微调tuner。我们把tuner的设计从模型网络结构中解耦出来以便灵活地组合, +并进一步扩展实现了一种新的节省内存的旁路tuner,大大减少了显存消耗和多任务推理成本。 -The implementation is a pluggable tuner component for [SWIFT](https://github.com/modelscope/swift), designed to be user-friendly. +目前Res-Tuning在[SWIFT](https://github.com/modelscope/swift)中以可插拔的tuner算法组件提供,开发者可以直接使用它。 -### Catalog +### 支持的组件列表 - [x] Res-Adapter - [x] Res-Tuning-Bypass - [ ] Res-Prefix - [ ] Res-Prompt -### Usage +### 使用方式 #### Demo -- Run our interactive demo using [vision_example](https://github.com/modelscope/swift/blob/main/examples/pytorch/cv/notebook/swift_vision.ipynb). +- 可以使用我们提供的 [可视化例子](https://github.com/modelscope/swift/blob/main/examples/pytorch/cv/notebook/swift_vision.ipynb). -#### Init Tuner +#### 初始化Tuner ```Python from swift import ResTuningConfig @@ -40,7 +41,7 @@ config = ResTuningConfig( - target_modules: The target module to be replaced. - tuner_cfg: The configuration of the tuning module. -#### Load Model +#### 加载模型 ```Python from swift import Swift @@ -52,7 +53,7 @@ print(model(torch.ones(1, 3, 224, 224)).shape) ``` -### Citation +### 引用 ``` @inproceedings{jiang2023restuning, title={Res-Tuning: A Flexible and Efficient Tuning Paradigm via Unbinding Tuner from Backbone}, diff --git a/docs/source/GetStarted/Installation.md "b/docs/source/GetStarted/SWIFT\345\256\211\350\243\205.md" similarity index 96% rename from docs/source/GetStarted/Installation.md rename to "docs/source/GetStarted/SWIFT\345\256\211\350\243\205.md" index c6b4dca377..b6ad3ead8a 100644 --- a/docs/source/GetStarted/Installation.md +++ "b/docs/source/GetStarted/SWIFT\345\256\211\350\243\205.md" @@ -5,7 +5,7 @@ 可以使用pip进行安装: ```shell -pip install ms-swift +pip install ms-swift -U ``` ## 源代码安装 diff --git a/docs/source/resources/xinference.jpg b/docs/source/GetStarted/resources/xinference.jpg similarity index 100% rename from docs/source/resources/xinference.jpg rename to docs/source/GetStarted/resources/xinference.jpg diff --git a/docs/source/GetStarted/Use in train and infer.md "b/docs/source/GetStarted/\344\275\277\347\224\250tuners.md" similarity index 100% rename from docs/source/GetStarted/Use in train and infer.md rename to "docs/source/GetStarted/\344\275\277\347\224\250tuners.md" diff --git a/docs/source/GetStarted/Work with Peft.md "b/docs/source/GetStarted/\345\234\250SWIFT\345\206\205\344\275\277\347\224\250PEFT.md" similarity index 96% rename from docs/source/GetStarted/Work with Peft.md rename to "docs/source/GetStarted/\345\234\250SWIFT\345\206\205\344\275\277\347\224\250PEFT.md" index aadfa08023..a9f45d833d 100644 --- a/docs/source/GetStarted/Work with Peft.md +++ "b/docs/source/GetStarted/\345\234\250SWIFT\345\206\205\344\275\277\347\224\250PEFT.md" @@ -3,18 +3,31 @@ 为了支持习惯Peft的用户,Swift提供了对于Peft的兼容性。用户可以从swift中import peft组件: >PeftModel +> >PeftConfig +> >PeftModelForSeq2SeqLM +> >PeftModelForSequenceClassification +> >PeftModelForTokenClassification +> >PeftModelForCausalLM +> >PromptEncoderConfig +> >PromptTuningConfig +> >PrefixTuningConfig +> >PromptLearningConfig +> >LoraConfig +> >get_peft_config +> >get_peft_model_state_dict +> >get_peft_model 以上组件均可以从swift中import: diff --git a/docs/source/GetStarted/Introduction.md "b/docs/source/GetStarted/\345\277\253\351\200\237\344\275\277\347\224\250.md" similarity index 83% rename from docs/source/GetStarted/Introduction.md rename to "docs/source/GetStarted/\345\277\253\351\200\237\344\275\277\347\224\250.md" index 14f68b2d0c..1402553f0a 100644 --- a/docs/source/GetStarted/Introduction.md +++ "b/docs/source/GetStarted/\345\277\253\351\200\237\344\275\277\347\224\250.md" @@ -4,10 +4,12 @@ Swift是一个提供LLM模型轻量级训练和推理的开源框架。Swift提 总之,在这个框架中提供了以下特性: -- **具备SOTA特性的Efficient Tuners**:用于结合大模型实现轻量级(在商业级显卡上)训练和推理,并取得较好效果 +- **具备SOTA特性的Efficient Tuners**:用于结合大模型实现轻量级(在商业级显卡上,如GTX3080、GTX3090、GTX4090等)训练和推理,并取得较好效果 - **使用ModelScope Hub的Trainer**:基于`transformers trainer`提供,支持LLM模型的训练,并支持将训练后的模型上传到[ModelScope Hub](https://www.modelscope.cn/models)中 - **可运行的模型Examples**:针对热门大模型提供的训练脚本和推理脚本,并针对热门开源数据集提供了预处理逻辑,可直接运行使用 +SWIFT库的github地址是:https://github.com/modelscope/swift + # 快速开始 在本章节会介绍如何快速安装swift并设定好运行环境,并跑通一个用例。 @@ -15,16 +17,13 @@ Swift是一个提供LLM模型轻量级训练和推理的开源框架。Swift提 安装swift的方式非常简单,用户只需要在python>=3.8环境中运行: ```shell -pip install ms-swift +pip install ms-swift -U ``` -下面的代码使用LoRA在分类任务上训练了`bert-base-uncased`模型: - -**运行下面的代码前请额外安装modelscope: ** +SWIFT库提供了**LLM&AIGC模型的训练推理脚手架**,支持LLaMA、QWen、ChatGLM、Stable Diffusion等多种模型的直接训练和推理,并且集成了SWIFT库提供的tuners, +开发者可以直接使用。它们的位置在:https://github.com/modelscope/swift/tree/main/examples/pytorch/llm -```shell -pip install modelscope>=1.9.0 -``` +如果需要在自定义的训练流程中使用tuners,可以参考下面的代码。下面的代码使用LoRA在分类任务上训练了`bert-base-uncased`模型: ```python import os diff --git a/docs/source/GetStarted/Examples.md "b/docs/source/GetStarted/\350\256\255\347\273\203\346\216\250\347\220\206\350\204\232\346\211\213\346\236\266.md" similarity index 100% rename from docs/source/GetStarted/Examples.md rename to "docs/source/GetStarted/\350\256\255\347\273\203\346\216\250\347\220\206\350\204\232\346\211\213\346\236\266.md" diff --git a/docs/source/GetStarted/Deployment.md "b/docs/source/GetStarted/\351\203\250\347\275\262\346\214\207\345\215\227.md" similarity index 99% rename from docs/source/GetStarted/Deployment.md rename to "docs/source/GetStarted/\351\203\250\347\275\262\346\214\207\345\215\227.md" index 242610396f..e00b09018d 100644 --- a/docs/source/GetStarted/Deployment.md +++ "b/docs/source/GetStarted/\351\203\250\347\275\262\346\214\207\345\215\227.md" @@ -158,7 +158,7 @@ xinference -p 9997 在浏览器界面上选择Register Model选项卡,添加chatglm.cpp章节中转换成功的ggml模型: -![image.png](../resources/xinference.jpg) +![image.png](./resources/xinference.jpg) 注意: diff --git a/docs/source/index.rst b/docs/source/index.rst index a43858db64..622c3c1113 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -9,12 +9,12 @@ Swift DOCUMENTATION :maxdepth: 2 :caption: Get Started - GetStarted/Introduction.md - GetStarted/Installation.md - GetStarted/Use in train and infer.md - GetStarted/Examples.md - GetStarted/Work with Peft.md - GetStarted/Deployment.md + GetStarted/快速使用.md + GetStarted/SWIFT安装.md + GetStarted/使用tuners.md + GetStarted/训练推理脚手架.md + GetStarted/在SWIFT内使用PEFT.md + GetStarted/部署指南.md .. toctree:: :maxdepth: 2 From 0b9ae9083908bf98696d512dbe0565ba8e8dbcb3 Mon Sep 17 00:00:00 2001 From: "yuze.zyz" Date: Wed, 15 Nov 2023 14:15:03 +0800 Subject: [PATCH 2/5] fix doc --- docs/source/GetStarted/ResTuning.md | 2 ++ "docs/source/GetStarted/\344\275\277\347\224\250tuners.md" | 2 +- docs/source/index.rst | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/source/GetStarted/ResTuning.md b/docs/source/GetStarted/ResTuning.md index 21ce40f4b5..f4dd17e664 100644 --- a/docs/source/GetStarted/ResTuning.md +++ b/docs/source/GetStarted/ResTuning.md @@ -1,3 +1,5 @@ +# Res-Tuning组件 +
## [NeurIPS 2023] Res-Tuning: A Flexible and Efficient Tuning Paradigm via Unbinding Tuner from Backbone diff --git "a/docs/source/GetStarted/\344\275\277\347\224\250tuners.md" "b/docs/source/GetStarted/\344\275\277\347\224\250tuners.md" index 2209cecfc6..a306a01c4f 100644 --- "a/docs/source/GetStarted/\344\275\277\347\224\250tuners.md" +++ "b/docs/source/GetStarted/\344\275\277\347\224\250tuners.md" @@ -1,4 +1,4 @@ -# Swift API +# 使用Tuners ## 在训练中使用Swift diff --git a/docs/source/index.rst b/docs/source/index.rst index 622c3c1113..95c2ecf1e1 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -13,6 +13,7 @@ Swift DOCUMENTATION GetStarted/SWIFT安装.md GetStarted/使用tuners.md GetStarted/训练推理脚手架.md + GetStarted/ResTuning.md GetStarted/在SWIFT内使用PEFT.md GetStarted/部署指南.md From 491c12cd090b658b2cddf9a34ffc03f92a7bbc42 Mon Sep 17 00:00:00 2001 From: "yuze.zyz" Date: Wed, 15 Nov 2023 14:21:31 +0800 Subject: [PATCH 3/5] fix readme --- README.md | 2 +- README_CN.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cabe4039d9..1d387c2a7d 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Key features: 4. Support training and inference with scripts/CLI,meanwhile support inference with Web-UI. 5. Support model deployment(vllm/chatglm.cpp/xinference),Check [Official documentation](./docs/source/GetStarted/部署指南.md) for details. -Users can check the [documentation of Swift](docs/source/GetStarted/快速开始.md) to get detail tutorials. +Users can check the [documentation of SWIFT](docs/source/GetStarted/快速使用.md) to get detail tutorials. ### 🎉 News diff --git a/README_CN.md b/README_CN.md index aeac9905ca..df9a523ead 100644 --- a/README_CN.md +++ b/README_CN.md @@ -35,7 +35,7 @@ SWIFT(Scalable lightWeight Infrastructure for Fine-Tuning)是一个可扩展 4. 支持通过脚本方式和命令行方式开启训练和推理,同时支持Web-UI方式进行推理。 5. 支持模型训练后的部署链路(vllm/chatglm.cpp/xinference),详情可以查看[官方文档](./docs/source/GetStarted/部署指南.md)。 -用户可以查看 [Swift官方文档](docs/source/GetStarted/快速开始.md) 来了解详细信息。 +用户可以查看 [SWIFT官方文档](docs/source/GetStarted/快速使用.md) 来了解详细信息。 ## 🎉 新闻 From 30bb6c0c7221d8a5db221fcea19fa64e82d10a7b Mon Sep 17 00:00:00 2001 From: "yuze.zyz" Date: Wed, 15 Nov 2023 14:39:48 +0800 Subject: [PATCH 4/5] fix typo --- .../\345\277\253\351\200\237\344\275\277\347\224\250.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/docs/source/GetStarted/\345\277\253\351\200\237\344\275\277\347\224\250.md" "b/docs/source/GetStarted/\345\277\253\351\200\237\344\275\277\347\224\250.md" index 1402553f0a..e41d19fa97 100644 --- "a/docs/source/GetStarted/\345\277\253\351\200\237\344\275\277\347\224\250.md" +++ "b/docs/source/GetStarted/\345\277\253\351\200\237\344\275\277\347\224\250.md" @@ -4,7 +4,7 @@ Swift是一个提供LLM模型轻量级训练和推理的开源框架。Swift提 总之,在这个框架中提供了以下特性: -- **具备SOTA特性的Efficient Tuners**:用于结合大模型实现轻量级(在商业级显卡上,如GTX3080、GTX3090、GTX4090等)训练和推理,并取得较好效果 +- **具备SOTA特性的Efficient Tuners**:用于结合大模型实现轻量级(在商业级显卡上,如RTX3080、RTX3090、RTX4090等)训练和推理,并取得较好效果 - **使用ModelScope Hub的Trainer**:基于`transformers trainer`提供,支持LLM模型的训练,并支持将训练后的模型上传到[ModelScope Hub](https://www.modelscope.cn/models)中 - **可运行的模型Examples**:针对热门大模型提供的训练脚本和推理脚本,并针对热门开源数据集提供了预处理逻辑,可直接运行使用 From 9d9358aa5bb81517e082c1885c05d14d07c54d51 Mon Sep 17 00:00:00 2001 From: "yuze.zyz" Date: Thu, 16 Nov 2023 13:35:18 +0800 Subject: [PATCH 5/5] pre-commit passed --- ...45\206\205\344\275\277\347\224\250PEFT.md" | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git "a/docs/source/GetStarted/\345\234\250SWIFT\345\206\205\344\275\277\347\224\250PEFT.md" "b/docs/source/GetStarted/\345\234\250SWIFT\345\206\205\344\275\277\347\224\250PEFT.md" index a9f45d833d..23784ad881 100644 --- "a/docs/source/GetStarted/\345\234\250SWIFT\345\206\205\344\275\277\347\224\250PEFT.md" +++ "b/docs/source/GetStarted/\345\234\250SWIFT\345\206\205\344\275\277\347\224\250PEFT.md" @@ -3,31 +3,31 @@ 为了支持习惯Peft的用户,Swift提供了对于Peft的兼容性。用户可以从swift中import peft组件: >PeftModel -> +> >PeftConfig -> +> >PeftModelForSeq2SeqLM -> +> >PeftModelForSequenceClassification -> +> >PeftModelForTokenClassification -> +> >PeftModelForCausalLM -> +> >PromptEncoderConfig -> +> >PromptTuningConfig -> +> >PrefixTuningConfig -> +> >PromptLearningConfig -> +> >LoraConfig -> +> >get_peft_config -> +> >get_peft_model_state_dict -> +> >get_peft_model 以上组件均可以从swift中import: