Skip to content

Lora 训练,merge 后,tokenizer.json 变大,推理生成乱码 #3502

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

Closed
SipingXu opened this issue Mar 14, 2025 · 2 comments
Closed

Lora 训练,merge 后,tokenizer.json 变大,推理生成乱码 #3502

SipingXu opened this issue Mar 14, 2025 · 2 comments

Comments

@SipingXu
Copy link

SipingXu commented Mar 14, 2025

Describe the bug
Lora 训练 QwQ-32B,merge LoRA 后,tokenizer.json 变大,推理生成乱码

Your hardware and system info
昇腾 910B4 * 8
Driver version: 24.1.0.3
CANN version: 8.1.RC1
torch 2.5.1
torch-npu 2.5.1.dev20250228
deepspeed 0.14.5
ms_swift 3.2.0

SFT 命令:
nohup swift sft
--model $MODEL_PATH
--sequence_parallel_size $SEQUENCE_PARALLEL_SIZE
--torch_dtype 'bfloat16'
--model_type 'qwq'
--template 'qwq'
--init_weights 'True'
--dataset $DATASET
--dataloader_num_workers $NPROC_PER_NODE
--torch_dtype 'bfloat16'
--num_train_epochs 8
--gradient_checkpointing
--per_device_train_batch_size 1
--per_device_eval_batch_size 1
--gradient_accumulation_steps 1
--learning_rate 1e-4
--train_type 'lora'
--lora_rank 64
--lora_alpha 128
--target_regex ".*.(q_proj|k_proj|v_proj|o_proj)"
--lora_dtype 'bfloat16'
--init_weights true
--eval_steps 10000
--save_steps 500
--save_total_limit 2
--split_dataset_ratio 0
--logging_steps 10
--max_length 6144
--truncation_strategy 'right'
--output_dir $CHECKPOINT_PATH
--logging_dir $LOG_DIR
--report_to 'tensorboard'
--output_dir $CHECKPOINT_PATH
--warmup_ratio 0.01
--max_grad_norm 1.0
--deepspeed "$BASE_DIR/conf/zero3_offload.json"
$RESUME_OPTS
>> $LOG_FILE 2>&1 &

Export 命令:
swift export
--adapters $CHECKPOINT_PATH
--merge_lora true
--device_map 'cpu'
--output_dir "$OUTPUT_PATH" \

@Jintao-Huang
Copy link
Collaborator

这个估计是tokenizers版本的问题,swift直接使用tokenizer.save_pretrained接口来存储

@SipingXu
Copy link
Author

transformers 4.44 后,依赖的 tokenizers 会把 merges 写成二维数组导致的。

使用 swift-3.0.3 merge 就没有问题没有问题 (swift 3.0.3 以后的版本,trl >=0.13 -> transformers >=4.46)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants