Skip to content
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

special token未能输出 #7080

Open
1 task done
katouHui opened this issue Feb 26, 2025 · 6 comments
Open
1 task done

special token未能输出 #7080

katouHui opened this issue Feb 26, 2025 · 6 comments
Labels
solved This problem has been already solved

Comments

@katouHui
Copy link

Reminder

  • I have read the above rules and searched the existing issues.

System Info

INFO 02-26 15:55:11 init.py:190] Automatically detected platform cuda.

  • llamafactory version: 0.9.2.dev0
  • Platform: Linux-5.15.0-91-generic-x86_64-with-glibc2.35
  • Python version: 3.11.0
  • PyTorch version: 2.5.1+cu124 (GPU)
  • Transformers version: 4.49.0
  • Datasets version: 3.2.0
  • Accelerate version: 1.2.1
  • PEFT version: 0.12.0
  • TRL version: 0.9.6
  • DeepSpeed version: 0.16.2
  • vLLM version: 0.7.2

Reproduction

Put your message here.

我的数据集为包含近1000条,输出格式为 **<...>.....</...>....**的数据,想通过微调Qwen模型使其能够输出<...>标签,直接进行微调的已经尝试过,现在需要将<...>作为special token的形式进行微调,微调结束并将模型合并之后进行推理,结果中并没有包含<...>标签,参考#6630#6749 等方法尝试无果,因此来咨询一下,希望能得到您的回复。

训练过程
训练代码:llamafactory-cli train examples/train_lora/deepseek_v3.yaml
具体的配置文件如下:

### model
model_name_or_path: /data/models/Qwen2.5-1.5B-Instruct

stage: sft
do_train: true
finetuning_type: lora
lora_target: all
deepspeed: ./examples/deepspeed/ds_z3_config.json
# lora_rank: 16
# lora_alpha: 32

dataset: deepseek750_v1
template: qwen
packing: false
cutoff_len: 32768
overwrite_cache: true
preprocessing_num_workers: 16

output_dir: ./saves/qwen2.5-1.5B_v3/
logging_steps: 1
save_steps: 30
plot_loss: true
overwrite_output_dir: true

per_device_train_batch_size: 1
gradient_accumulation_steps: 2
learning_rate: 5.00e-5
num_train_epochs: 7
lr_scheduler_type: cosine
warmup_ratio: 0.1
bf16: true

new_special_tokens: "<think>,</think>"
skip_special_tokens: false

merge过程
训练代码:llamafactory-cli export examples/merge_lora/qwen_deep_v3.yaml
具体的配置文件如下:

### model
model_name_or_path: /data/models/Qwen2.5-1.5B-Instruct
adapter_name_or_path: ./saves/qwen2.5-1.5B_v3
template: qwen
trust_remote_code: true

new_special_tokens: "<think>,</think>"
skip_special_tokens: false
### export
export_dir: output/deep_1.5_merge_v3
export_size: 1
export_device: auto
export_legacy_format: false

推理过程
推理代码:CUDA_VISIBLE_DEVICES=0,1,2,3 python scripts/vllm_infer.py --model_name_or_path ./output/deep_1.5_merge_v3 --dataset deepseek750_dev

推理结果中 只有这个标签"label": "<|im_end|>\n"
也参照一些issue通过调参等方式进一步尝试,但依旧不会输出special token
麻烦占用您的一部分时间,指点一下我该如何去修改,才能让微调之后的模型能够准确地输出special_token

Others

No response

@katouHui katouHui added bug Something isn't working pending This problem is yet to be addressed labels Feb 26, 2025
@hiyouga
Copy link
Owner

hiyouga commented Feb 26, 2025

训练时候没有添加 resize_vocab 参数,tokenizer 不识别

@hiyouga hiyouga closed this as completed Feb 26, 2025
@hiyouga hiyouga added solved This problem has been already solved and removed bug Something isn't working pending This problem is yet to be addressed labels Feb 26, 2025
@lifeng7777
Copy link

训练时候没有添加 resize_vocab 参数,tokenizer 不识别

我看到代码里有:
def patch_tokenizer(tokenizer: "PreTrainedTokenizer", model_args: "ModelArguments") -> None:
…………
if num_added_tokens > 0 and not model_args.resize_vocab:
model_args.resize_vocab = True
logger.warning_rank0("New tokens have been added, changed resize_vocab to True.")
所以resize_vocab这个参数应该不影响训练?我训练的时候看到这条warning了觉得会自动设置为True,但是我最终的模型也没法推理新的token。官方能否出一个新增token训练/merge/推理的脚本呢

@hiyouga hiyouga reopened this Feb 26, 2025
@Alice1998
Copy link

希望这个【官方能否出一个新增token训练/merge/推理的脚本】+1,十分感谢!

以及想要确认一下,在现在的代码中,
lora训练的时候使用
new_special_tokens: xxx, xxx
additional_target: embed_tokens,lm_head
resize_vocab: true

在lora merge的时候使用
new_special_tokens: xxx, xxx
resize_vocab: true

那么merge之后的新模型的embed_tokens,lm_head是训练后的吧,还是base model的呢?
搜索了之前的帖子,没有找到解答

@lifeng7777
Copy link

lifeng7777 commented Feb 28, 2025

补充一点,即使加了additional_target: embed_tokens,lm_head和resize_vocab: true参数进行lora训练,得到的adapter_config.json文件里面,target_modules中也没有embed_tokens,lm_head,我用别的框架训练的时候,target_modules中是有这两个参数的。
{ "alpha_pattern": {}, "auto_mapping": null, "base_model_name_or_path": "/xxxxx/Qwen2.5-7B-Instruct", "bias": "none", "fan_in_fan_out": false, "inference_mode": true, "init_lora_weights": true, "layer_replication": null, "layers_pattern": null, "layers_to_transform": null, "loftq_config": {}, "lora_alpha": 16, "lora_dropout": 0.0, "megatron_config": null, "megatron_core": "megatron.core", "modules_to_save": [ "embed_tokens", "lm_head" ], "peft_type": "LORA", "r": 8, "rank_pattern": {}, "revision": null, "target_modules": [ "k_proj", "gate_proj", "down_proj", "up_proj", "q_proj", "v_proj", "o_proj" ], "task_type": "CAUSAL_LM", "use_dora": false, "use_rslora": false }

@hiyouga
Copy link
Owner

hiyouga commented Feb 28, 2025

@lifeng7777 modules_to_save 里面不是有吗

@qubingxin
Copy link

@katouHui 你好,请问你直接微调带<……>的数据,模型输出能输出该特殊标签吗? 我这里遇到了同样的问题,请问你是怎么解决的?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solved This problem has been already solved
Projects
None yet
Development

No branches or pull requests

5 participants