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

基于13B的LLAMA模型fine-tune,loss特别大,而lr初始就是0,这是正常的吗? #32

Closed
alisyzhu opened this issue Apr 3, 2023 · 18 comments
Labels
bug Something isn't working

Comments

@alisyzhu
Copy link

alisyzhu commented Apr 3, 2023

基于13B的LLAMA模型,70w的数据,4个GPU进行fine-tune,epoch=1~3,但是每次记录的loss特别大,最开始的lr却是0,而eval_loss却是Nan
image
image
image
image

batch_size=256;
micro_batch_size=8;
eval_steps=200;
save_steps=200;
test_size = 10000;

@Facico
Copy link
Owner

Facico commented Apr 3, 2023

@alisyzhu 当然是不正常的,llama已经训练的很好了,loss一般在1附近

这里可能也有一个和你相似的问题,由于没有给后续回复也不清楚最后咋样了,你可以参照里面的建议,同时使用我们的各种实例代码排查一下

  • 1、tokenizer是否有问题(保证能正确编码):用该issue的示例代码试一试,tokenizer是否有问题
  • 2、模型是否有问题(保证能正常运行):你可以用13B的模型,结合我们13b的lora模型在对应的推理接口测一测(generate、interaction、chat),看看能否正常工作
  • 3、版本依赖的问题,我们在相关问题整理中附上了一份参考配置,其中peft和transformers库(带dev后缀),需要直接从github拉取。同时torch可以直接在pytorch官网找一份适合你cuda版本的命令安装。

如果1和2都没有问题,应该问题就差不多了。

@alisyzhu
Copy link
Author

alisyzhu commented Apr 3, 2023

@alisyzhu 当然是不正常的,llama已经训练的很好了,loss一般在1附近

这里可能也有一个和你相似的问题,由于没有给后续回复也不清楚最后咋样了,你可以参照里面的建议,同时使用我们的各种实例代码排查一下

  • 1、tokenizer是否有问题(保证能正确编码):用该issue的示例代码试一试,tokenizer是否有问题
  • 2、模型是否有问题(保证能正常运行):你可以用13B的模型,结合我们13b的lora模型在对应的推理接口测一测(generate、interaction、chat),看看能否正常工作
  • 3、版本依赖的问题,我们在相关问题整理中附上了一份参考配置,其中peft和transformers库(带dev后缀),需要直接从github拉取。同时torch可以直接在pytorch官网找一份适合你cuda版本的命令安装。

如果1和2都没有问题,应该问题就差不多了。

按照您的建议,测试了结果,应该就是tokenizer有问题,中英文都无法正确decode,
image

我是按照tools里提供的download_llama.py的脚本下载的模型,并进行转换为hf。而且测试安装的transformer的版本是dev的。
image

如果验证tokenizer不正确的话,请问如何使其正确呢?是要重新下载,知道这个测试脚本可以正常吗?

@Facico
Copy link
Owner

Facico commented Apr 3, 2023

看看这两个库版本是不是对的,tokenizers==0.13.2, sentencepiece==0.1.97

@LZY-the-boys
Copy link
Collaborator

还要看下你的hf checkpoint里边是否有tokenizer.model这个文件,大小是否在48M左右

@alisyzhu
Copy link
Author

alisyzhu commented Apr 3, 2023

看看这两个库版本是不是对的,tokenizers==0.13.2, sentencepiece==0.1.97

是的,刚才我有截图,可能在您那里没有显示。
transformers==4.28.0.dev0
tokenizers==0.13.2
sentencepiece==0.1.97
python=3.8.8
torch=2.0.0(最开始安装的是1.13.1,但是执行报错,就升级为2.0了)

@alisyzhu
Copy link
Author

alisyzhu commented Apr 3, 2023

还要看下你的hf checkpoint里边是否有tokenizer.model这个文件,大小是否在48M左右

image

有48M这么大吗?我这里显示只有492k

@alisyzhu
Copy link
Author

alisyzhu commented Apr 3, 2023

还要看下你的hf checkpoint里边是否有tokenizer.model这个文件,大小是否在48M左右

image

download_llama.sh的脚本下载显示就是大约488k的大小tokenizer.model,所以这种下载的tokenizer不对吗?

@LZY-the-boys
Copy link
Collaborator

这是正确的,口误(:

@Facico
Copy link
Owner

Facico commented Apr 3, 2023

@alisyzhu

从上面的你给的图来看,tokenizer对应编码是对的(你可以试试我给的样例程序中的输出作为输入,我猜编码是没有问题),不过模型并没有正常decode,decode得到的都是0,可能有下面情况

  • 1、peft、transformer库自己的问题(由于要从github直接拉去,可能会有问题),不过这个情况较小,因为我昨天刚在colab上试过是没问题的
  • 2、tokenizer其他参数的问题,比如eos token、pad token等设置的问题,你可以试试将模型除了模型之外文件从huggingface上下载并本地替换看是否有问题:https://huggingface.co/decapoda-research/llama-13b-hf/tree/main
  • 3、模型本身的问题,结合你上面的loss非常大,我觉得可能会出现问题。如果条件允许的话,可以直接从huggingface拉去试试(这个比较稳妥),因为另一个issue也是13b出现的问题,所以不知道download现在链接里的13b是不是有问题的(我们这边之前测是没问题的)

@alisyzhu
Copy link
Author

alisyzhu commented Apr 3, 2023

结合2和3的点,我直接从huggingface上全部重新下载13B的model,不采用download_llama.sh脚本的方式,也是也是使用的,是吧?如果是这样,我就从huggingface上重新下载试试 ~

@Facico
Copy link
Owner

Facico commented Apr 3, 2023

适用的,download_llama是考虑到有些人下载的比较慢的情况再提供的,如果直接从huggingface拉取很快的话肯定是ok的

@alisyzhu
Copy link
Author

alisyzhu commented Apr 4, 2023

我重新通过huggingface下载了13B的模型,目前70w,4GPU,loss和lr如下:
image
请问这样是符合训练预期的了吧?但是我看log里会有以下提示,这个是合理的吗?
image

@Facico
Copy link
Owner

Facico commented Apr 4, 2023

@alisyzhu 这个loss应该是正常了,上面的那个测试案例也是正常的吗?就是最后还是模型下载的问题?

这个warning应该是指你的显卡的问题,你可以搜一下你显卡对应的Compute Capability,如果小于7.5的话8-bit计算会慢一点。

@alisyzhu
Copy link
Author

alisyzhu commented Apr 4, 2023

显卡<7.5,慢点儿无所谓,只要能正常训练测试就可以了,主要是更换不了~
另外,我就是昨天看了您的建议,debug发现tokenizer的问题,所以从huggingface重新下载了模型,上午测试的decode也有正常结果了,就直接跑了一下13B+70w的,最开始loss就已经是1.0+,也和您昨天说的llama的对得上。

@Facico
Copy link
Owner

Facico commented Apr 4, 2023

OK

@alisyzhu
Copy link
Author

alisyzhu commented Apr 4, 2023

OK
感谢答疑,期待结果中 ~

@alisyzhu
Copy link
Author

alisyzhu commented Apr 4, 2023

finetune.py的代码没有改动,请问,test_size=1w的情况下,eval_loss是nan,是ok的吗?
image

@Facico
Copy link
Owner

Facico commented Apr 6, 2023

抱歉回复这么晚,该问题见这里

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants