Skip to content

KTO使用自定义数据集报错 #4062

Closed
@waywooKwong

Description

@waywooKwong

问题已解决:自己构造的数据集 label 使用成了 str 的 "False"/"True",导致错误

Describe the bug

  1. 使用文档中的KTO示例代码可以跑通
  2. 仅更换数据集为本地路径构造的json,
    出现报错:RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn

Image

我的脚本代码:

nproc_per_node=1

CUDA_VISIBLE_DEVICES=6 \
NPROC_PER_NODE=$nproc_per_node \
MASTER_PORT=29501 \
swift rlhf \
    --rlhf_type kto \
    --model Qwen/Qwen2.5-0.5B-Instruct \
    --train_type lora \
    --dataset '/my_path/swift_kto_dataset_v3.json' \
    --num_train_epochs 1 \
    --per_device_train_batch_size 1 \
    --per_device_eval_batch_size 1 \
    --learning_rate 1e-4 \
    --lora_rank 4 \
    --lora_alpha 16 \
    --target_modules all-linear \
    --gradient_accumulation_steps $(expr 16 / $nproc_per_node) \
    --eval_steps 100 \
    --save_steps 100 \
    --save_total_limit 2 \
    --logging_steps 5 \
    --max_length 2048 \
    --output_dir output \
    --warmup_ratio 0.05 \
    --dataloader_num_workers 4 \
    --deepspeed zero2 \
    --dataset_num_proc 4 \
    --torch_dtype float16 

我的json数据格式:
其中label=0,label=1的数量相等,考虑有关数据集的隐患是:content内容重复度较高

Image

Your hardware and system info

python 3.10
cuda 12.4
datasets 3.0.0
deepspeed 0.16.7
ms-swift 3.4.0
trl 0.17.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions