modelscope / ms-swift

Use PEFT or Full-parameter to finetune 350+ LLMs or 100+ MLLMs. (LLM: Qwen2.5, Llama3.2, GLM4, Internlm2.5, Yi1.5, Mistral, Baichuan2, DeepSeek, Gemma2, ...; MLLM: Qwen2-VL, Qwen2-Audio, Llama3.2-Vision, Llava, InternVL2, MiniCPM-V-2.6, GLM4v, Xcomposer2.5, Yi-VL, DeepSeek-VL, Phi3.5-Vision, ...)
https://swift.readthedocs.io/zh-cn/latest/Instruction/index.html
Apache License 2.0
4.01k stars 355 forks source link

关于temperature与do_sample参数的默认设置 #2308

Closed Betty-J closed 4 days ago

Betty-J commented 6 days ago

您好,我在微调时设置了--do_sample false,但在微调后的模型配置文件 sft_args 中发现"temperature": 1.0,这与命令行参数中描述的并不一致。

截屏2024-10-22 10 45 45

其中 --predict_with_generate为默认设置False

同时在推理时若设置--do_sample false会提示:ValueError: [UserWarning('do_sample is set to False. However, temperature is set to 0.1 -- this flag is only used in sample-based generation modes. You should set do_sample=True or unset temperature.')

Jintao-Huang commented 6 days ago

设置do_sample false的时候, 你是不是还设置了temperature 0.1

Betty-J commented 6 days ago

设置do_sample false的时候, 你是不是还设置了temperature 0.1

并没有设置temperature参数,它是默认的None,而且我在微调后的模型配置文件中发现temperature对应的实际数值是1.0。 截屏2024-10-22 13 22 21

这是我完整的finetune设置

SIZE_FACTOR=8 MAX_PIXELS=602112 CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 NPROC_PER_NODE=8 swift sft \
    --model_type qwen2-vl-2b-instruct \
    --model_id_or_path ./Qwen2-VL-2B-Instruct \
    --sft_type lora \
    --tuner_backend peft \
    --sequence_parallel_size 1 \
    --template_type AUTO \
    --dtype bf16 \
    --seed 42 \
    --output_dir ./20241021 \
    --dataset train \
    --val_dataset val \
    --num_train_epochs 50 \
    --max_length 2048 \
    --system 'You are a helpful assistant.' \
    --check_dataset_strategy warning \
    --lora_rank 32 \
    --lora_alpha 32 \
    --lora_dtype bf16 \
    --lora_lr_ratio 16.0 \
    --lora_target_modules ALL \
    --gradient_checkpointing true \
    --batch_size 1 \
    --weight_decay 0.1 \
    --gradient_accumulation_steps 16 \
    --warmup_ratio 0.05 \
    --eval_steps 200 \
    --save_steps 200 \
    --save_total_limit 3 \
    --logging_steps 5 \
    --learning_rate 4e-5 \
    --use_flash_attn true \
    --do_sample false \

加载这个微调后的模型进行推理时报了上述ValueError,infer中也设置了 --do_sample false

Jintao-Huang commented 6 days ago

那 0.1是哪来的呢

Betty-J commented 6 days ago

那 0.1是哪来的呢

没定位到哪里设置的,没有显式设置,而且为什么设置--do_sample false 会出现 temperature 1.0 呢

Jintao-Huang commented 5 days ago

那 0.1是哪来的呢

没定位到哪里设置的,没有显式设置,而且为什么设置--do_sample false 会出现 temperature 1.0 呢

不设置会出现警告的

Jintao-Huang commented 5 days ago

当do_sample为false, 会将temperature设置为默认值, 来避免出现警告

Betty-J commented 4 days ago

当do_sample为false, 会将temperature设置为默认值, 来避免出现警告

感谢回复