QwenLM / Qwen

The official repo of Qwen (通义千问) chat & pretrained large language model proposed by Alibaba Cloud.
Apache License 2.0
13.59k stars 1.11k forks source link

使用QWenBase版本进行 SFT微调,需要更替tokenize么 #1140

Closed moondaiy closed 6 months ago

moondaiy commented 6 months ago

1.因为Base版本和Chat版本tokenizer是不同的(至少文件是不一样的 chat版本是 format 是 chatml,base版本是 raw),那么我现在计划使用在base版本上进行sft预训练。请问在训练的时候是否需要替换tokenizer(用chat版本的替换 base版本) ?

jklj077 commented 6 months ago

不需要,没让你换不要换。

moondaiy commented 6 months ago

不需要,没让你换不要换。

3ks 但是有一个问题 如果我用base版本进行 sft微调,那么会生成一个新的模型 那么加载这个模型也能成功,但是调用 model.chat 函数时候会有错误提示 不是 chatml的,我可以修改 tokenizer 中的 chatml 或者把chat版本中 tokenizer 相关文件 替换到新训的模型中。也能model.chat 函数调用,那么这样合理么?

jklj077 commented 6 months ago

这个要改的是generation_config.json哈,不用改tokenizer相关的。

moondaiy commented 6 months ago

这个要改的是generation_config.json哈,不用改tokenizer相关的。

我可以这样理解把,我训练了一个基于base版本的SFT模型(训练过程中 用的 tokenizer 是原始 base-7B中的),训练完毕后,然后进行merge,生成一个新的模型(SFT之后的) ,在使用这个新的模型的时候(model.chat),我需要把chat版本的generation_config.json 替换到 新模型中的generation_config.json (因为这时候他用的是base版本的generation_config.json ) 这样是OK的把。 base版本的generation_config.json 为: { "chat_format": "raw", "eos_token_id": 151643, "pad_token_id": 151643, "stop_words_ids": [[151643]], "max_new_tokens": 512, "do_sample": true, "top_k": 0, "top_p": 0.8, "transformers_version": "4.31.0" } chat版本的generation_config.json 为: { "chat_format": "chatml", "eos_token_id": 151643, "pad_token_id": 151643, "max_window_size": 24000, "max_new_tokens": 512, "do_sample": true, "top_k": 0, "top_p": 0.8, "repetition_penalty": 1.1, "transformers_version": "4.31.0" }

ambyerhan commented 4 months ago

有一个问题 如果我用base版本进行 sft微调,那么会生成一个新的模型 那么加载这个模型也能成功,但是调用 model.chat 函数时候会有错误提示 不是 chatml的,我可以修改 tokenizer 中的 chatml 或者把chat版本中 tokenizer 相关文件 替换到新训的模型中。也能model.c

这个要改的是generation_config.json哈,不用改tokenizer相关的。

有个疑问? 1)是否每次sft之后都要手动改一下base下面的generation_config.json? 2)如果是,那base模型我想再sft是不是generation_config.json还原回去(或者base时不考虑解码就无所谓?) 3)chat_format的值域是哪些呢?就raw和chatml?那是不是sft之后生成新的generation_config.json,然后把chat_format赋值chatml就好了?

辛苦,感谢~

jklj077 commented 4 months ago
  1. Yes
  2. No need
  3. Yes

Note those only apply to Qwen(1.0), which uses custom code to support the chat function. In Qwen1.5, the chat format is controled by chat template, since transformers has included the support.