Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]Feat/refactor3 #2030

Open
wants to merge 122 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
e7b9580
first commit
tastelikefeet Sep 11, 2024
d52a58a
Merge commit '2d1aba96281c8f646881427fa857388b07fdcbef' into feat/ref…
tastelikefeet Sep 11, 2024
2906d4f
remove aigc module, and remove hub files
tastelikefeet Sep 11, 2024
f04db7d
commit missing file
tastelikefeet Sep 11, 2024
6072eb7
remove rome
tastelikefeet Sep 11, 2024
4092b71
add a hub file to load all hub related operations
tastelikefeet Sep 11, 2024
4bf3acf
model refactoring, wip, now move safe_snapshot_downlaod to single fil…
tastelikefeet Sep 11, 2024
d813b61
wip, begin to use class to instead of register
tastelikefeet Sep 12, 2024
072e25a
give up class
tastelikefeet Sep 12, 2024
ff6ca11
wip
tastelikefeet Sep 13, 2024
0929e37
Merge commit 'e46cda27abc5122402394b50e03b3d61ec04d0dc' into feat/ref…
tastelikefeet Sep 13, 2024
56285a9
merge main
tastelikefeet Sep 13, 2024
9a0ca82
refactor model.py
tastelikefeet Sep 13, 2024
1a5d9fe
move datasets and infer to single packages
tastelikefeet Sep 13, 2024
3cb932e
refactor preprocessor, wip
tastelikefeet Sep 14, 2024
800c86a
Merge commit '3028145d966d3dac038a2f844e2d3aca022d1348' into feat/ref…
tastelikefeet Sep 15, 2024
55d2d7b
refactor preprocessor, unfinished
tastelikefeet Sep 15, 2024
ced4d0d
Merge commit 'd12f9bce106580c4719083608fb18041686258ff' into feat/ref…
tastelikefeet Sep 16, 2024
f623f42
refactor preprocessor
tastelikefeet Sep 16, 2024
d690794
split dataset loader and register into two single files
tastelikefeet Sep 16, 2024
2bd4d1e
split register and loader into two files and refactor the dataset loa…
tastelikefeet Sep 16, 2024
f6980c3
refactor datasets, turn query/response to messages, and wrap all prep…
tastelikefeet Sep 17, 2024
08bd05b
refactor args, split them into multiple classes
tastelikefeet Sep 18, 2024
75ebd2e
refactor arguments, split to difference dataclasses
tastelikefeet Sep 20, 2024
6308520
commit missing files
tastelikefeet Sep 20, 2024
d7eb06f
refactor template:
tastelikefeet Sep 21, 2024
58d39bf
1. create some plugin files
tastelikefeet Sep 22, 2024
69745aa
move optimizers to plugin
tastelikefeet Sep 22, 2024
23496e2
Support tuner plugin
tastelikefeet Sep 22, 2024
4e50bbb
Support trainer plugin
tastelikefeet Sep 22, 2024
168b433
args with no compile error
tastelikefeet Sep 23, 2024
9cfd43e
dataset compile passed
tastelikefeet Sep 23, 2024
38c6791
fix imports of most modified files
tastelikefeet Sep 23, 2024
7c88723
1. fix imports
tastelikefeet Sep 23, 2024
c48578a
pass dtype and device to template.encode
tastelikefeet Sep 23, 2024
057e035
fix imports
tastelikefeet Sep 23, 2024
53447b7
refactor inference, unfinished, need to merge pt/vllm/lmdeploy stream…
tastelikefeet Sep 23, 2024
f62447f
wip
tastelikefeet Sep 23, 2024
7ca7dbe
unfinished work for inference, wrap and split long functions to classes
tastelikefeet Sep 24, 2024
5e231c7
inference seems ok to run ...
tastelikefeet Sep 24, 2024
1f7a739
fix imports
tastelikefeet Sep 24, 2024
ece80f6
fix runtime error
tastelikefeet Sep 24, 2024
6afda57
run, wip
tastelikefeet Sep 24, 2024
25b7433
replace dataset creation function
tastelikefeet Sep 24, 2024
e3ed386
first case ok
tastelikefeet Sep 24, 2024
9df553f
wip etst
tastelikefeet Sep 24, 2024
b9cc1ce
wip, mm ok for some datasets
tastelikefeet Sep 24, 2024
3f6d6c1
fix some running problems
tastelikefeet Sep 25, 2024
ca2593a
split template from other folders
tastelikefeet Sep 25, 2024
c38b426
fix
tastelikefeet Sep 25, 2024
8942e5c
move get_template to base
tastelikefeet Sep 25, 2024
645ec7f
fix template
tastelikefeet Sep 26, 2024
55d2491
fix docs
tastelikefeet Sep 26, 2024
2ed507b
fix
tastelikefeet Sep 26, 2024
6146861
fix
tastelikefeet Sep 27, 2024
592c78d
fix
tastelikefeet Sep 27, 2024
a80705c
fix
tastelikefeet Sep 27, 2024
929d022
fix
tastelikefeet Sep 28, 2024
b25d238
fix
tastelikefeet Sep 29, 2024
c43450b
fix
tastelikefeet Sep 29, 2024
93c282c
fix
tastelikefeet Sep 29, 2024
2e68a4b
lint pass
Jintao-Huang Oct 4, 2024
39aed86
refactor3 (#2191)
Jintao-Huang Oct 4, 2024
bb1eced
refactor args (#2193)
Jintao-Huang Oct 4, 2024
ae4de6d
remove model_type, use model_arch (#2195)
Jintao-Huang Oct 5, 2024
5b224ca
update llama model_type & update_template (ing) (#2197)
Jintao-Huang Oct 6, 2024
c77e670
update template (#2201)
Jintao-Huang Oct 7, 2024
70320ec
move agent (#2206)
Jintao-Huang Oct 8, 2024
b381467
refactor loss scale to fit train other parts
tastelikefeet Oct 8, 2024
8d0df03
support mergekit
tastelikefeet Oct 9, 2024
ffcb916
update template (#2215)
Jintao-Huang Oct 9, 2024
41041df
update
Jintao-Huang Oct 10, 2024
794240f
update template
Jintao-Huang Oct 10, 2024
47a33a5
update
Jintao-Huang Oct 10, 2024
55583d5
update template
Jintao-Huang Oct 10, 2024
893e3d8
update
Jintao-Huang Oct 10, 2024
e21abca
fix loss scale
tastelikefeet Oct 10, 2024
ad0abd6
update
Jintao-Huang Oct 10, 2024
0fe18b8
Merge remote-tracking branch 'refs/remotes/origin/feat/refactor3' int…
Jintao-Huang Oct 10, 2024
43edaea
update
Jintao-Huang Oct 10, 2024
2afad8e
update
Jintao-Huang Oct 10, 2024
1a9aef1
update vllm infer
Jintao-Huang Oct 11, 2024
20d8bc7
update
Jintao-Huang Oct 11, 2024
55ff83c
update
Jintao-Huang Oct 11, 2024
fb54b31
update
Jintao-Huang Oct 11, 2024
1685615
update
Jintao-Huang Oct 11, 2024
7ba7b8c
update
Jintao-Huang Oct 12, 2024
81feb78
update
Jintao-Huang Oct 12, 2024
ffd3c5d
update
Jintao-Huang Oct 12, 2024
db56eb2
fix imports
tastelikefeet Oct 12, 2024
1c48680
Merge commit 'ffd3c5d5312bbdc3adf71ee6b157eef66ad7a28c' into feat/ref…
tastelikefeet Oct 12, 2024
39ccc61
fix
tastelikefeet Oct 12, 2024
f634d3c
update torch_dtype model_type
Jintao-Huang Oct 12, 2024
6000ebf
update
Jintao-Huang Oct 12, 2024
53b5e5f
Merge remote-tracking branch 'refs/remotes/origin/feat/refactor3' int…
Jintao-Huang Oct 12, 2024
5e79c46
fix
tastelikefeet Oct 12, 2024
68ecc8e
update
Jintao-Huang Oct 14, 2024
ed06221
update
Jintao-Huang Oct 14, 2024
20029cc
support vllm infer
Jintao-Huang Oct 15, 2024
16e21b8
update
Jintao-Huang Oct 15, 2024
7931ee1
support lmdeploy infer
Jintao-Huang Oct 15, 2024
db692d2
lint pass
Jintao-Huang Oct 15, 2024
9fdb7b7
support lmdeploy
Jintao-Huang Oct 15, 2024
1efebe7
update
Jintao-Huang Oct 15, 2024
a3a75a2
fix
Jintao-Huang Oct 15, 2024
762f6b0
fix
Jintao-Huang Oct 16, 2024
02f9891
update
Jintao-Huang Oct 16, 2024
939643a
update
Jintao-Huang Oct 17, 2024
797ece3
support batched pt infer
Jintao-Huang Oct 17, 2024
72e270a
update
Jintao-Huang Oct 18, 2024
a0afc51
update
Jintao-Huang Oct 18, 2024
d31cb0c
update
Jintao-Huang Oct 18, 2024
e2a024c
update
Jintao-Huang Oct 18, 2024
53142c3
update
Jintao-Huang Oct 18, 2024
5bf4125
support stream logprobs
Jintao-Huang Oct 18, 2024
27d4e28
update
Jintao-Huang Oct 18, 2024
3bce7be
fix pt logprobs stream
Jintao-Huang Oct 18, 2024
2459dc1
update
Jintao-Huang Oct 19, 2024
d67423c
support pt lora
Jintao-Huang Oct 20, 2024
dc719ee
update infer cli
Jintao-Huang Oct 20, 2024
205b13e
update
Jintao-Huang Oct 20, 2024
e38d15d
update dataset
Jintao-Huang Oct 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ recursive-include swift/utils *.py
recursive-include swift/llm/data *.*
recursive-include swift/llm/ds_config *.json
recursive-include requirements *.txt
recursive-include swift/llm/agent *.json
recursive-include swift/llm/template/agent *.json
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ You can contact us and communicate with us by adding our group:
- 2024.04.29: Supports inference and fine-tuning of InternVL-Chat-V1.5 model. For best practice, you can refer to [here](https://github.com/modelscope/swift/tree/main/docs/source_en/Multi-Modal/internvl-best-practice.md).
- 🔥2024.04.26: Support **LISA** and **unsloth** training! Specify `--lisa_activated_layers=2` to use LISA(to reduce the memory cost to 30 percent!), specify `--tuner_backend unsloth` to use unsloth to train a huge model(full or lora) with lesser memory(30 percent or lesser) and faster speed(5x)!
- 🔥2024.04.26: Support the fine-tuning and inference of Qwen1.5-110B and Qwen1.5-110B-Chat model, use [this script](https://github.com/modelscope/swift/blob/main/examples/pytorch/llm/scripts/qwen1half_110b_chat/lora_ddp_ds/sft.sh) to start training!
- 2024.04.24: Support for inference and fine-tuning of Phi3 series models. Including: [phi3-4b-4k-instruct](examples/pytorch/llm/scripts/phi3_4b_4k_instruct/lora), phi3-4b-128k-instruct.
- 2024.04.24: Support for inference and fine-tuning of Phi3 series models. Including: [phi3-4b-4k-instruct](legacy/pytorch/llm/scripts/phi3_4b_4k_instruct/lora), phi3-4b-128k-instruct.
- 2024.04.22: Support for inference, fine-tuning, and deployment of **chinese-llama-alpaca-2** series models. This includes:chinese-llama-2-1.3b, chinese-llama-2-7b, chinese-llama-2-13b, chinese-alpaca-2-1.3b, chinese-alpaca-2-7b and chinese-alpaca-2-13b along with their corresponding 16k and 64k long text versions.
- 2024.04.22: Support for inference and fine-tuning of Llama3 GPTQ-Int4, GPTQ-Int8, and AWQ series models. Support for inference and fine-tuning of chatglm3-6b-128k, Openbuddy-Llama3.
- 2024.04.20: Support for inference, fine-tuning, and deployment of **Atom** series models. This includes: Atom-7B and Atom-7B-Chat. use [this script](https://github.com/modelscope/swift/blob/main/examples/pytorch/llm/scripts/atom_7b_chat/lora/sft.sh) to train.
Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ SWIFT具有丰富全面的文档,请查看我们的文档网站:
- 2024.04.29: 支持InternVL-Chat-V1.5的推理与微调, 最佳实践可以查看[这里](https://github.com/modelscope/swift/tree/main/docs/source/Multi-Modal/internvl最佳实践.md).
- 🔥2024.04.26: 支持**LISA** 和 **unsloth**训练!指定 `--lisa_activated_layers=2` 来开启LISA(显存使用降低至全参训练的30%),指定 `--tuner_backend unsloth` 来使用unsloth,用更少的显存(30%或更少)更快的速度(5x)训练一个超大模型!
- 🔥2024.04.26: 支持Qwen1.5-110B和Qwen1.5-110B-Chat模型的推理与微调, 使用[这个脚本](https://github.com/modelscope/swift/blob/main/examples/pytorch/llm/scripts/qwen1half_110b_chat/lora_ddp_ds/sft.sh)来开始训练!
- 2024.04.24: 支持Phi3系列模型的推理与微调. 包括: [phi3-4b-4k-instruct](examples/pytorch/llm/scripts/phi3_4b_4k_instruct/lora), phi3-4b-128k-instruct.
- 2024.04.24: 支持Phi3系列模型的推理与微调. 包括: [phi3-4b-4k-instruct](legacy/pytorch/llm/scripts/phi3_4b_4k_instruct/lora), phi3-4b-128k-instruct.
- 2024.04.22: 支持**chinese-llama-alpaca-2**系列模型的推理与微调和部署等. 包括:chinese-llama-2-1.3b, chinese-llama-2-7b, chinese-llama-2-13b, chinese-alpaca-2-1.3b, chinese-alpaca-2-7b和chinese-alpaca-2-13b以及对应的16k和64k长文本模型.
- 2024.04.22: 支持Llama3 GPTQ-Int4, GPTQ-Int8, AWQ系列模型的推理与微调. 支持chatglm3-6b-128k, Openbuddy-llama3的推理与微调.
- 2024.04.20: 支持**Atom**系列模型的推理, 微调和部署等. 包括: Atom-7B and Atom-7B-Chat. 使用[这个脚本](https://github.com/modelscope/swift/blob/main/examples/pytorch/llm/scripts/atom_7b_chat/lora/sft.sh)来开始训练!
Expand Down
4 changes: 4 additions & 0 deletions TEST_POINTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- 所有的examples需要测试
- 所有的模型上传下载和数据集load
- Internlm-xcomposer2 hook
- tagengo-gpt4 vqa-v2 gqa grit
279 changes: 0 additions & 279 deletions docs/source/AIGC/AnimateDiff微调推理文档.md

This file was deleted.

3 changes: 2 additions & 1 deletion docs/source/GetStarted/使用tuners.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ tuner是指附加在模型上的额外结构部分,用于减少训练参数量
11. Vision Prompt Tuning: [Visual Prompt Tuning](https://arxiv.org/abs/2203.12119)
12. Side: [Side-Tuning: A Baseline for Network Adaptation via Additive Side Networks](https://arxiv.org/abs/1912.13503)
13. Res-Tuning: [Res-Tuning: A Flexible and Efficient Tuning Paradigm via Unbinding Tuner from Backbone](https://arxiv.org/abs/2310.19859) < [arXiv](https://arxiv.org/abs/2310.19859) | [Project Page](https://res-tuning.github.io/) | [Usage](ResTuning.md) >
14. [PEFT](https://github.com/huggingface/peft)提供的tuners, 如IA3, AdaLoRA等
14. ReFT: [ReFT: Representation Finetuning for Language Models](https://arxiv.org/pdf/2404.03592)
15. [PEFT](https://github.com/huggingface/peft)提供的tuners, 如IA3, AdaLoRA等

## 在训练中使用

Expand Down
4 changes: 3 additions & 1 deletion docs/source/Instruction/LLM微调文档.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,12 @@ import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'

from swift.llm import (
get_model_tokenizer, get_template, inference, ModelType, get_default_template_type
get_model_tokenizer, get_template, ModelType, get_default_template_type, TransformersFramework, InferArguments
)
from swift.tuners import Swift

infer_framework = TransformersFramework()

ckpt_dir = 'vx-xxx/checkpoint-100'
model_type = ModelType.qwen_7b_chat
template_type = get_default_template_type(model_type)
Expand Down
1 change: 1 addition & 0 deletions docs/source/Instruction/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
6. [命令行参数](命令行参数.md)
7. [支持的模型和数据集](支持的模型和数据集.md)
8. [自定义与拓展](自定义与拓展.md)
9. [常见问题](LLM&VLM训练、推理、部署、评测常见问题.md)
7 changes: 1 addition & 6 deletions docs/source/Instruction/命令行参数.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,7 @@
- `--gpu_memory_fraction`: 默认为`None`. 该参数旨在指定显卡最大可用显存比例的情况下运行训练,用于极限测试.
- `--train_dataset_mix_ratio`: 默认为`0.`. 该参数定义了如何进行数据集打混训练. 指定该参数时, 会混合训练集的`train_dataset_mix_ratio`倍数的`train_dataset_mix_ds`指定的通用知识数据集. 该参数已废弃, 请使用`--dataset`进行数据集混合.
- `--train_dataset_mix_ds`: 默认为`['ms-bench']`. 用于防止知识遗忘的通用知识数据集. 该参数已废弃, 请使用`--dataset`进行数据集混合.
- `--use_loss_scale`: 默认为`False`. 生效时会将Agent的部分字段(Action/Action Input部分)的loss权重加强以强化CoT, 对普通SFT场景没有任何效果.
- `--loss_scale_config_path` 选项指定自定义的 loss_scale 配置,适用于在启用 use_loss_scale 时,例如在 Agent 训练中放大 Action 和其他关键 ReAct 字段的损失权重。
- 在配置文件中,您可以使用字典格式来设置 loss_scale。每个键代表一个特定字段名,其关联的值设定了该字段及其后续内容的损失缩放倍数。例如,通过设定 `"Observation:": [2, 0]`,当response包含 `xxxx Observation:error` 时,`Observation:` 字段loss将增加到两倍,`error` 部分的loss则不计入。除了字面匹配,配置也支持正则表达式规则,以实现更灵活的匹配,如模式 '<.*?>':[2.0] 将针对所有尖括号括起来的部分损失增加到两倍。字段匹配与正则匹配所对应的损失缩放倍数,分别由长度为2和1的列表表示。
- 同时支持匹配query对整段response设置loss_scale, 这在处理像[Agent-FLAN](https://arxiv.org/abs/2403.12881)论文中描述的固定多轮对话查询时极其有用,如果query中包含了预定义键的任一项,相应的响应将采用关联的 loss_scale 值。,你可以参考`swift/llm/agent/agentflan.json`
- 默认情况下,我们为 Action:, Action Input:, Thought:, Final Answer:, 和 Observation: 等字段预设了损失缩放值。我们为[alpha-umi](https://arxiv.org/pdf/2401.07324)和[Agent-FLAN](https://arxiv.org/abs/2403.12881)也提供了默认配置,你可以设置为`alpha-umi`和`agent-flan`来使用。默认的配置文件位于`swift/llm/agent`下
- 匹配规则的应用优先级,从高到低为:query字段 > response特定字段 > 正则表达式匹配规则。
- `--loss_scale`: 默认为`default`. 目前支持`default`(无scale), `agentflan`(针对agentflan格式数据集提供了不同的loss weights), `react`(针对Action/Action Input/Final Answer等), 用户也可以通过plugin功能定制自己的loss scale.
- `--custom_register_path`: 默认为`None`. 传入`.py`文件, 用于注册模板、模型和数据集.
- `--custom_dataset_info`: 默认为`None`, 传入外置dataset_info.json的路径、json字符串或者dict. 用于拓展数据集. 格式参考: https://github.com/modelscope/swift/blob/main/swift/llm/data/dataset_info.json
- `--device_map_config`: 手动配置模型的device_map, 默认为`None`. 你可以传入本地路径(.json), json字符串或者dict.
Expand Down
Loading
Loading