Skip to content

Commit b14852d

Browse files
committed
Merge branch 'develop' of https://github.com/PaddlePaddle/PaddleFormers into 1203
2 parents 674841d + 0b2113c commit b14852d

File tree

156 files changed

+15301
-7927
lines changed

Some content is hidden

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

156 files changed

+15301
-7927
lines changed

.github/workflows/model-unittest-gpu.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
work_dir: ${{ github.workspace }}
5252
FLAGS_dynamic_static_unified_comm: "True"
5353
python_version: "3.10"
54+
PIP_CACHE_DIR: /home/.cache/pip
5455
paddle_whl: https://paddle-qa.bj.bcebos.com/paddle-pipeline/Develop-TagBuild-Training-Linux-Gpu-Cuda12.6-Cudnn9.5-Trt10.5-Mkl-Avx-Gcc11-SelfBuiltPypiUse/latest/paddlepaddle_gpu-0.0.0-cp310-cp310-linux_x86_64.whl
5556
run: |
5657
container_name=${TASK}-$(date +%Y%m%d-%H%M%S)
@@ -76,6 +77,7 @@ jobs:
7677
-e HF_PROXY_PATH=${work_dir}/../../../proxy_huggingface \
7778
-e AISTUDIO_PROXY_PATH=${work_dir}/../../../proxy_aistudio \
7879
-e PF_HOME=/home/models/ \
80+
-e PIP_CACHE_DIR \
7981
-w /workspace --privileged ${IMAGE_NAME}
8082
8183
- name: Download Code
@@ -112,15 +114,16 @@ jobs:
112114
run: |
113115
docker exec -t $container_name /bin/bash -c '
114116
ldconfig
115-
pip config set global.cache-dir "/home/.cache/pip"
117+
mkdir -p /home/.cache/pip
118+
pip cache dir
116119
set -e
117120
rm -rf /root/.cache/aistudio/
118121
cd /workspace/PaddleFormers && git config --global --add safe.directory $PWD
119122
echo "work_dir = ${work_dir}"
120123
cp -r ${work_dir}/../../../models ./models
121124
echo "Check whether the local model file exists:"
122125
ls -l ./models
123-
timeout 60m bash scripts/regression/ci_model_unittest.sh ${paddle_whl} false ${AGILE_COMPILE_BRANCH}
126+
timeout 60m bash -x scripts/regression/ci_model_unittest.sh ${paddle_whl} false ${AGILE_COMPILE_BRANCH}
124127
'
125128
126129
- name: Upload Products

.github/workflows/unittest-gpu.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ jobs:
5555
work_dir: ${{ github.workspace }}
5656
FLAGS_dynamic_static_unified_comm: "True"
5757
python_version: "3.10"
58+
PIP_CACHE_DIR: /home/.cache/pip
5859
paddle_whl: https://paddle-qa.bj.bcebos.com/paddle-pipeline/Develop-TagBuild-Training-Linux-Gpu-Cuda12.6-Cudnn9.5-Trt10.5-Mkl-Avx-Gcc11-SelfBuiltPypiUse/latest/paddlepaddle_gpu-0.0.0-cp310-cp310-linux_x86_64.whl
5960
run: |
6061
container_name=${TASK}-$(date +%Y%m%d-%H%M%S)
@@ -83,6 +84,7 @@ jobs:
8384
-e "AISTUDIO_PROXY_PATH=$work_dir/../../../proxy_aistudio" \
8485
-e "HF_DATASETS_CACHE=$work_dir/../../../paddlenlp/huggingface/datasets" \
8586
-e "TRANSFORMERS_CACHE=$work_dir/../../../paddlenlp/huggingface" \
87+
-e PIP_CACHE_DIR \
8688
-w /github/workspace --privileged $IMAGE_NAME
8789
8890
- name: Download Code
@@ -117,7 +119,8 @@ jobs:
117119
run: |
118120
docker exec -t $container_name /bin/bash -c '
119121
ldconfig
120-
pip config set global.cache-dir "/home/.cache/pip"
122+
mkdir -p /home/.cache/pip
123+
pip cache dir
121124
set -e
122125
rm -rf /root/.cache/aistudio/
123126
cd /github/workspace/PaddleFormers && git config --global --add safe.directory $PWD
@@ -127,7 +130,7 @@ jobs:
127130
cp -r ${work_dir}/../../../models ./models
128131
echo "Check whether the local model file exists:"
129132
ls -l ./models
130-
timeout 50m bash scripts/unit_test/ci_unittest.sh ${paddle_whl} false ${PYTEST_EXECUTE_FLAG_FILE} ${AGILE_COMPILE_BRANCH}
133+
timeout 50m bash -x scripts/unit_test/ci_unittest.sh ${paddle_whl} false ${PYTEST_EXECUTE_FLAG_FILE} ${AGILE_COMPILE_BRANCH}
131134
'
132135
- name: Copy coverage.xml out of container
133136
run: |

Makefile

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,26 @@ unit-test:
4646

4747
.PHONY: install
4848
install:
49-
pip install --pre paddlepaddle -i https://www.paddlepaddle.org.cn/packages/nightly/cpu/
50-
pip install -r requirements-dev.txt
51-
pip install -r requirements.txt
49+
@echo "Checking CUDA version and selecting pip source..."
50+
@if ! command -v nvcc >/dev/null 2>&1; then \
51+
echo "ERROR: nvcc (CUDA) not found. Please install CUDA before proceeding."; \
52+
exit 1; \
53+
fi; \
54+
cuda_version=$$(nvcc --version | grep release | awk '{print $$5}' | sed 's/,//'); \
55+
echo "Detected CUDA version: $$cuda_version"; \
56+
if [ "$$cuda_version" = "12.6" ]; then \
57+
PADDLE_SOURCE="https://www.paddlepaddle.org.cn/packages/nightly/cu126/"; \
58+
elif [ "$$cuda_version" = "12.9" ]; then \
59+
PADDLE_SOURCE="https://www.paddlepaddle.org.cn/packages/nightly/cu129/"; \
60+
elif [ "$$cuda_version" = "13.0" ]; then \
61+
PADDLE_SOURCE="https://www.paddlepaddle.org.cn/packages/nightly/cu130/"; \
62+
else \
63+
PADDLE_SOURCE=""; \
64+
echo "Unknown CUDA version."; \
65+
fi; \
66+
echo "Using pip source: $$PADDLE_SOURCE"; \
67+
pip install -r requirements-dev.txt \
68+
pip install -r requirements.txt --extra-index-url "$$PADDLE_SOURCE"; \
5269
pre-commit install
5370

5471

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,22 @@ Requires Python 3.8+ and [PaddlePaddle](https://www.paddlepaddle.org.cn/install/
4242

4343
```bash
4444
# Install via pip
45-
pip install paddleformers
45+
# cuda12.6
46+
pip install paddleformers --extra-index-url https://www.paddlepaddle.org.cn/packages/nightly/cu126/
47+
# cuda12.9
48+
pip install paddleformers --extra-index-url https://www.paddlepaddle.org.cn/packages/nightly/cu129/
49+
# cuda13.0
50+
pip install paddleformers --extra-index-url https://www.paddlepaddle.org.cn/packages/nightly/cu130/
4651

4752
# Install development version
4853
git clone https://github.com/PaddlePaddle/PaddleFormers.git
4954
cd PaddleFormers
50-
pip install -e .
55+
# cuda12.6
56+
pip install -e . --extra-index-url https://www.paddlepaddle.org.cn/packages/nightly/cu126/
57+
# cuda12.9
58+
pip install -e . --extra-index-url https://www.paddlepaddle.org.cn/packages/nightly/cu129/
59+
# cuda13.0
60+
pip install -e . --extra-index-url https://www.paddlepaddle.org.cn/packages/nightly/cu130/
5161
```
5262

5363
## Quickstart
@@ -89,4 +99,4 @@ trainer.train()
8999
We welcome all contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
90100

91101
## License
92-
This repository's source code is available under the [Apache 2.0 License](LICENSE).
102+
This repository's source code is available under the [Apache 2.0 License](LICENSE).

docs/zh/datasets_format_zh.md

Lines changed: 127 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@
22

33
## 数据流文件格式支持
44

5-
当前预训练、后训练数据流只支持`jsonl`格式的数据
5+
当前预训练、后训练数据流支持`jsonl``json``parquet`格式的数据
66

77
## 1. 预训练数据流
88

99
### 1.1. 在线数据流
1010

11-
预训练数据流中,每条数据都是一个字典,包含以下字段:
11+
#### 1.1.1. erniekit格式
1212

13-
- `text` : `str, List(str)`, 预训练文本。
13+
使用 `erniekit` 格式需要在 `train(/eval)_dataset_type` 处指定为 `erniekit`
14+
15+
erniekit格式:每条数据都是一个字典,包含以下字段:
16+
17+
- `text` : `str, List(str)`
1418

1519
样例数据:
1620

17-
```text
21+
```json
1822
{"text": ["一个需要连续输入值的分类问题的示例是房屋价格预测。房屋的价格通常基于诸如平方英尺、位置、卧室和浴室数量以及像后院或车库等功能这样的因素定价。为了准确预测房屋价格,这些标准必须作为连续输入值输入到分类模型中。"]}
1923
...
2024
```
@@ -26,6 +30,21 @@ wget https://paddleformers.bj.bcebos.com/datasets/pt_data.tar.gz
2630
mkdir -p data/pt && tar -xf pt_data.tar.gz -C data/pt/
2731
```
2832

33+
#### 1.1.2. messages格式
34+
35+
使用 `messages` 格式需要在 `train(/eval)_dataset_type` 处指定为 `messages`
36+
37+
messages格式:每条数据都是一个字典,包含以下字段:
38+
39+
- `messages` : `List(Dict)`
40+
41+
样例数据:
42+
43+
```json
44+
{"messages": {"role": "assistant", "content": "一个需要连续输入值的分类问题的示例是房屋价格预测。房屋的价格通常基于诸如平方英尺、位置、卧室和浴室数量以及像后院或车库等功能这样的因素定价。为了准确预测房屋价格,这些标准必须作为连续输入值输入到分类模型中。"}}
45+
...
46+
```
47+
2948
### 1.2. 离线数据流
3049

3150
我们也可以选择使用离线的比特预训练数据流,更节省内存。
@@ -117,9 +136,9 @@ mkdir -p data/sft && tar -xf alpaca_demo.gz -C data/sft/ --strip-components=1
117136
```
118137

119138

120-
### chatml格式
139+
### messages格式
121140

122-
使用 `chatml` 格式需要在 `train(/eval)_dataset_type` 处指定为 `chatml`
141+
使用 `messages` 格式需要在 `train(/eval)_dataset_type` 处指定为 `messages`
123142

124143
SFT数据流中,每条数据都是一个字典,包含以下字段:
125144

@@ -168,7 +187,7 @@ Notes:
168187
]
169188
```
170189

171-
为了方便测试,我们也提供了 `chatml` function call SFT 数据集可以直接使用:
190+
为了方便测试,我们也提供了 `messages` function call SFT 数据集可以直接使用:
172191
```bash
173192
wget https://paddleformers.bj.bcebos.com/datasets/sft_function_call_demo.tar.gz
174193

@@ -226,9 +245,9 @@ wget https://bj.bcebos.com/paddlenlp/datasets/examples/ultrafeedback_binarized.t
226245
mkdir -p data/dpo && tar -zxf ultrafeedback_binarized.tar.gz -C data/dpo/ --strip-components=1
227246
```
228247

229-
### chatml 格式
248+
### messages 格式
230249

231-
使用 `chatml` 格式需要在 `train(/eval)_dataset_type` 处指定为 `chatml`
250+
使用 `messages` 格式需要在 `train(/eval)_dataset_type` 处指定为 `messages`
232251

233252
DPO数据流中,每条数据都是一个字典,包含以下字段:
234253
- `messages` : `List(dict)`, 对话历史列表。
@@ -303,9 +322,107 @@ DPO数据流中,每条数据都是一个字典,包含以下字段:
303322
}
304323
```
305324

306-
为了方便测试,我们也提供了 `chatml` function call DPO 数据集可以直接使用:
325+
为了方便测试,我们也提供了 `messages` function call DPO 数据集可以直接使用:
307326
```bash
308327
wget https://paddleformers.bj.bcebos.com/datasets/dpo_function_call_1k.tar.gz
309328

310329
mkdir -p data/dpo_fc && tar -zxf dpo_function_call_1k.tar.gz -C data/dpo_fc/
311330
```
331+
332+
## 4. 多模 SFT数据流
333+
334+
### erniekit格式
335+
336+
使用 `erniekit` 格式需要在 `train(/eval)_dataset_type` 处指定为 `erniekit`
337+
338+
SFT数据流中,每条数据都是一个字典,包含以下字段:
339+
340+
* `text_info`: 纯文本的列表,每个元素包含一个 `text` 和一个 `tag`
341+
* `text`: 来自使用者的问题或系统回复的文字内容
342+
* `tag`: 遮挡标签 (`no_mask`=包含在训练中, `mask`=排除)
343+
* `image_info`: 图像组成的列表,每个元素包含一个 `image_url` 和一个 `matched_text_index`
344+
* `image_url`: 线上下载图像的网址或本地存取图像的路径
345+
* `matched_text_index`: `text_info` 中匹配文字的索引
346+
* 预设值: `matched_text_index=0` 表示图像与第一个文字匹配,并将其放置在第一个文字之前
347+
* `is_system(optional)`: 系统标志 (1=系统配置 0=无系统配置)
348+
* 系统配置 = 如果 `is_system=1`,则为 `text_info[0]`
349+
350+
注意:
351+
* 通过将 `image_info` 替换为 `video_info` 来支持视频数据
352+
* 请确保 `mask``no_mask``text_info` 中交替出现
353+
354+
这是一个 SFT VL 数据集的多图像示例:
355+
356+
```json
357+
{
358+
"image_info": [
359+
{"matched_text_index": 0, "image_url": "./DoclingMatix/218/0.png"},
360+
{"matched_text_index": 0, "image_url": "./DoclingMatix/218/1.png"}
361+
],
362+
"text_info": [
363+
{"text": "What is the purpose of the resolution discussed in the text?", "tag": "mask"},
364+
{"text": "The purpose of the resolution is to approve the redevelopment contract of the Philadelphia Redevelopment Authority for the redevelopment and urban renewal of a portion of the Haddington Urban Renewal Area, Unit Nos. 2 and 3, and to authorize the Redevelopment Authority to execute the redevelopment contract with Danielle M. Carson-Varns.", "tag": "no_mask"},
365+
{"text": "Who introduced Resolution No. 160204 to the City Council?", "tag": "mask"},
366+
{"text": "Councilmember Blackwell introduced Resolution No. 160204 to the City Council.", "tag": "no_mask"},
367+
...
368+
]
369+
}
370+
```
371+
372+
这是一个 SFT VL 数据集的单视频示例:
373+
```json
374+
{
375+
"video_info": [
376+
{"matched_text_index": 0, "image_url": "./NExTVideo/1027/4789497818.mp4"}
377+
],
378+
"text_info": [
379+
{"text": "how does the man sit on the grass?\nA. kneel\nB. one leg in the air\nC. sitting on bicycle seat\nD. legs spread out\nE. squatting down\n Answer with the option's letter from the given choices directly.", "tag": "mask"},
380+
{"text": "D", "tag": "no_mask"}
381+
]
382+
}
383+
```
384+
385+
这是一个 SFT VL 数据集的系统配置示例:
386+
```json
387+
{
388+
"is_system": 1,
389+
"text_info": [
390+
{"text": "Your role as ...", "tag": "mask"},
391+
{"text": "好的", "tag": "no_mask"},
392+
{"text": "What is written...", "tag": "mask"},
393+
{"text": "<think>So I've got...", "tag": "no_mask"},
394+
...
395+
]
396+
"image_info": [...]
397+
}
398+
```
399+
400+
为了方便测试,我们也提供了用于快速训练的demo数据,请根据您的需要下载[数据](https://paddleformers.bj.bcebos.com/datasets/DoclingMatix.tar.gz),并将其解压缩到`tests/fixtures/dummy/sft-vl/`
401+
402+
```shell
403+
wget https://paddleformers.bj.bcebos.com/datasets/DoclingMatix.tar.gz
404+
tar -xf DoclingMatix.tar.gz -C tests/fixtures/dummy/sft-vl/ --strip-components=1
405+
```
406+
407+
### messages格式
408+
409+
使用 `messages` 格式需要在 `train(/eval)_dataset_type` 处指定为 `messages`
410+
411+
多模messages格式需要在纯文messages格式的基础上加上`images``videos``audios`几个key,用于传入多模态资源的`url`或者`path`,同时在`messages`中插入`<image>``<video>``<audio>`标签来表述插入多模态数据的位置:
412+
413+
纯文:
414+
```json
415+
{"messages": [{"role": "assistant", "content": "预训练的文本在这里"}]}
416+
```
417+
加入图片:
418+
```json
419+
{"messages": [{"role": "assistant", "content": "<image>是一只小狗,<image>是一只小猫"}], "images": ["/xxx/x.jpg", "/xxx/x.png"]}
420+
```
421+
加入音频:
422+
```json
423+
{"messages": [{"role": "assistant", "content": "<audio>描述了今天天气真不错"}], "audios": ["/xxx/x.wav"]}
424+
```
425+
加入图片与视频:
426+
```json
427+
{"messages": [{"role": "assistant", "content": "<image>是一个大象,<video>是一只狮子在跑步"}], "images": ["/xxx/x.jpg"], "videos": ["/xxx/x.mp4"]}
428+
```

docs/zh/template.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## 指定训练使用的template
2+
3+
| 参数 | 类型 | 描述 |
4+
| --- | --- | --- |
5+
| `template_backend` | str | 指定为`custom`表示使用自定义的template,`jinja`表示使用apply_chat_template方法进行拼接,不适合多轮对话,不推荐使用 |
6+
| `template` | str | (只在 `template_backend``custom` 时生效)指定训练用的 template
7+
| `split_multi_turn` | bool | 只在 `template_backend``jinja` 时生效)`True`表示将多轮数据拆成多条数据进行训练,`False`表示每次只学习最后一轮的回复 |
8+
| `encode_one_turn` | str | 只在 `template_backend``jinja` 时生效)`True`表示将多轮对话进行拆分,分别对每一轮对话套用`apply_chat_template``False`表示直接对整段对话套用`apply_chat_template` |
9+
10+
## 自定义template
11+
`paddleformers/datasets/template/template.py`文件中,通过`register_template`实现自定义template
12+
13+
## 多模plugin接入流程
14+
15+
`paddleformers/datasets/template/mm_plugin.py` 文件中实现各种多模预处理的处理,基类是`BasePlugin`,已经实现了各种图片、视频、音频的预处理操作,如果需要自定义plugin,需要继承`BasePlugin`实现自定义的类,如`Qwen2VLPlugin`。在自定义的类中实现各种多模数据预处理的操作,并在`PLUGINS`里面注册template名字和类名的对应关系

examples/config/dpo/full_function_call.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
### data
2-
train_dataset_type: chatml
3-
eval_dataset_type: chatml
2+
train_dataset_type: messages
3+
eval_dataset_type: messages
44
train_dataset_path: ./tests/fixtures/dummy/dpo/function-call-train.jsonl
55
train_dataset_prob: "1.0"
66
eval_dataset_path: ./tests/fixtures/dummy/dpo/function-call-eval.jsonl
77
eval_dataset_prob: "1.0"
88
max_seq_len: 8192
99
packing: false
1010
mix_strategy: concat
11+
split_multi_turn: True
1112

1213
### model
1314
model_name_or_path: Qwen/Qwen3-0.6B-Base

0 commit comments

Comments
 (0)