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

微调之后加载权重发现输出停不下来 #140

Closed
wilson9x1 opened this issue May 8, 2023 · 11 comments
Closed

微调之后加载权重发现输出停不下来 #140

wilson9x1 opened this issue May 8, 2023 · 11 comments

Comments

@wilson9x1
Copy link

wilson9x1 commented May 8, 2023

系统:
centos transformers 4.28.0.dev0
Python 3.10.11
decapoda-research--llama-7b-hf 4.27.0.dev0

我重新自己验证一下我的问题发现:

一) 直接使用,你们提供的权重,使用时正常的:python generate.py --model_path 'decapoda-research/llama-7b-hf' --lora_path 'Chinese-Vicuna/Chinese-Vicuna-lora-7b-belle-and-guanaco' --use_local '0' --use_typewriter '1'
image

二)使用自己微调的模型 。如何加载权重时候,发现一直输出问题:python finetune.py --data_path './sample/merge_sample.json' --output_path './loar-v/' --model_path 'decapoda-research/llama-7b-hf' --eval_steps 200 --save_steps 200 --test_size 1

python generate.py --model_path 'decapoda-research/llama-7b-hf' --lora_path './loar-v/' --use_local '0' --use_typewriter '1'
image

三)参考 #59
改tokenizer_config.json配置没还是存在问题。

模型直接不工作了。。

补充我的几个token值情况:
截屏2023-05-08 11 03 45

@LZY-the-boys
Copy link
Collaborator

你要确定下你自己训练的时候tokenizer是不是也是pad=0 bos=1 eos=2, 以及训练数据预处理后是不是eos结尾,一般来说这种情况是训练的时候eos没加,模型没学到如何结尾

@wilson9x1
Copy link
Author

@LZY-the-boys
在finetone.py 里面去观察这三个值
print(tokenizer.eos_token_id)
print(tokenizer.bos_token_id)
print(tokenizer._convert_token_to_id(tokenizer.bos_token))

开始时候print一下
截屏2023-05-08 11 19 07

结束时候print一下
截屏2023-05-08 11 18 47

最后结果都是pad=0 bos=1 eos=2,

截屏2023-05-08 11 21 03
截屏2023-05-08 11 21 14

@s1ghhh
Copy link

s1ghhh commented May 8, 2023

在生成阶段可以设置一下repetition_penalty,如:

    generation_config = GenerationConfig(
        temperature=temperature,
        top_p=top_p,
        top_k=top_k,
        num_beams=num_beams,
        repetition_penalty=1.2,
        **kwargs,
    )

    generate_params = {
        "input_ids": input_ids,
        "generation_config": generation_config,
        "return_dict_in_generate": True,
        "output_scores": True,
        "max_new_tokens": max_new_tokens,
    }

@wilson9x1
Copy link
Author

Repetition Penalty 在web界面上可以调整吧 默认设置是2 。
repetition_penalty:控制生成的文本中重复标记的惩罚力度。
你为什么还调整小了。。

@s1ghhh
Copy link

s1ghhh commented May 8, 2023

Repetition Penalty 在web界面上可以调整吧 默认设置是2 。 repetition_penalty:控制生成的文本中重复标记的惩罚力度。 你为什么还调整小了。。

我用的是alpaca-lora的代码,alpaca-lora默认是没设置repetition_penalty的

@wilson9x1
Copy link
Author

wilson9x1 commented May 8, 2023

@LZY-the-boys
看了一下训练集的情况。有10个样本 里面有3个 没有以2结尾
image

把这3个样本超过踢出去。也还是解决不了这个问题。绝了。

@wilson9x1
Copy link
Author

wilson9x1 commented May 9, 2023

@LZY-the-boys 我解决了我的问题。我参看了 alpace-lora的代码和这个issuse tloen/alpaca-lora#279

一共发现两个问题
1.如果你使用了decapoda-research/llama-7b-hf 就会有问题。因为他的版本不对 是 4.27的。
截屏2023-05-09 14 56 02
我改用了 下面的就可以正常跑alpace-lora代码。但是用了这个可能会导致GPU内存不够。所以我也准备去找官方的下载链接再试试看
7B - https://huggingface.co/yahma/llama-7b-hf
13B - https://huggingface.co/yahma/llama-13b-hf

2.https://github.com/Facico/Chinese-Vicuna/blob/master/finetune.py
代码这个位置应该存在bug:def tokenize(prompt):

全文中你没有使用tokenize。我看了一下这个代码在 alpace-lora使用,其实是在对最后的输出位置补充EOS。
所以你的训练集超过256个字节,那你的训练集一定存在EOS丢失问题。
截屏2023-05-09 15 01 40

@Facico
Copy link
Owner

Facico commented May 10, 2023

@wilson9x1 是的,我们当时使用的decapoda-research/llama-7b-hf可能比较早,后面的yahma的模型是修正过tokenizer的问题的。因为它们版本比较乱,我们在不同的机器上部署的时候也遇到了类似的问题,4.28.1的应该是可以和yahma对应的。

关于第二个问题,在数据比较短的时候(比如belle和guanaco的数据)其实不加eos是问题不大的。小于截断长度加eos,不小于不加确实合理一点。不过其实当截断长度开成2048都加eos问题也不大

@wilson9x1
Copy link
Author

感谢耐心解答

@Vicent0205
Copy link

llama 7b 的模型本身(未经过finetune)generate时候能够输出eos吗?

@waterluck
Copy link

@Facico 想请教下,如果是文本摘要这种输入一般很长的任务,超过截断长度要不要设置加eos呢,我现在看各个版本的llama finetune都是超过就不加eos, 而且训练的时候有很多样本是没有标签的, 训练来的模型有时候会说不出完整的句子。这种情况下厨了增大max_seq-len, 请问还有什么比较好的方法吗? 还是说这种长文本就设置一律加上eos呢

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

6 participants