ms-swift icon indicating copy to clipboard operation
ms-swift copied to clipboard

GRPO使用自定义预处理器加载的多模态数据集时卡死无法训练

Open caseclose opened this issue 1 year ago • 2 comments

使用mllm.py中自定义preprocessor类来使用自定义的数据集,但是在训练的时候出现卡住的情况。

这是我自定义的数据集的预处理器:

class UIR1Preprocessor(ResponsePreprocessor):

    def preprocess(self, row: Dict[str, Any]) -> Dict[str, Any]:
        query = row.get('instruction', '')
        print(f"Query is : {query}")
        query = (f'{query} Output the thinking process in <think> </think> and '
                 'final answer (number) in <answer> </answer> tags.')
        row.update({'query': query})
        solution = row.get('bbox', '')
        row.update({'solution': solution})
        images = row.get('image_filename', '')
        images = os.path.join('./train_imgs', images)
        row.update({'images': images})
        return super().preprocess(row)


register_dataset(
    DatasetMeta(
        dataset_path='./train.json',
        dataset_name='UI-R1-Train',
        preprocess_func=UIR1Preprocessor(),
        tags=['vision', 'grpo']))

数据集文件train.json的格式如下:

[
    {
        "img_filename": "mobile_1ca5b944-293a-46a1-af95-eb35bc8a0b2a.png",
        "bbox": [
            879,
            75,
            1478,
            344
        ],
        "instruction": "view world clock",
        "data_type": "icon",
        "data_source": "ios",
        "action": "click"
    },
    {
        "img_filename": "mobile_6949b916-64c8-431f-8842-a29a9a557641.png",
        "bbox": [
            1077,
            78,
            1169,
            193
        ],
        "instruction": "select source language",
        "data_type": "icon",
        "data_source": "ios",
        "action": "click"
    },
...
]

在训练脚本中使用 --dataset 参数进行引用,没有使用dataset_info.json的数据集注册方式。

CUDA_VISIBLE_DEVICES=0,1,2,3,4,5 \
NPROC_PER_NODE=6 \
swift rlhf \
    --rlhf_type grpo \
    --model ./Qwen2.5-VL-3B-Instruct \
    --external_plugins examples/train/grpo/plugin/plugin.py \
    --reward_funcs xxxx \
    --use_vllm true \
    --vllm_mode server \
    --vllm_server_host 127.0.0.1 \
    --vllm_server_port 8000 \
    --train_type full \
    --torch_dtype bfloat16 \
    --dataset 'UI-R1-Train' \
    --max_completion_length 1024 \
    --num_train_epochs 1 \
    --per_device_train_batch_size 8 \
    --per_device_eval_batch_size 8 \
    --learning_rate 1e-6 \
    --gradient_accumulation_steps 2 \
    --save_strategy 'steps' \
    --eval_strategy 'steps' \
    --eval_steps 1000 \
    --save_steps 1000 \
    --save_total_limit 5 \
    --logging_steps 1 \
    --output_dir output/GRPO_UI-R1-Train \
    --warmup_ratio 0.01 \

在训练时出现卡死的情况:

Image

目前想使用vscode中launch.json的debug方式定位bug的位置,但是可能由于封装的原因,发现 class UIR1Preprocessor(ResponsePreprocessor) 类即使打断点也无法在该处停下,难以定位错误。

想问下我的自定义数据集的操作是否有某些错误或者遗漏,以及如何进入到我自定义的preprocessor类中进行调试。感谢!

caseclose avatar Jun 10 '25 12:06 caseclose

你好,请问你解决了吗,我也在这里卡死了

liuxuexun avatar Aug 13 '25 09:08 liuxuexun

我是数据格式出现问题导致的,修改了数据格式之后就好了

caseclose avatar Aug 14 '25 08:08 caseclose