PaddlePaddle / PaddleNLP

👑 Easy-to-use and powerful NLP and LLM library with 🤗 Awesome model zoo, supporting wide-range of NLP tasks from research to industrial applications, including 🗂Text Classification, 🔍 Neural Search, ❓ Question Answering, ℹ️ Information Extraction, 📄 Document Intelligence, 💌 Sentiment Analysis etc.
https://paddlenlp.readthedocs.io
Apache License 2.0
12.01k stars 2.93k forks source link

模型推理结果不稳定 #1377

Closed BlueSkyBubble closed 1 year ago

BlueSkyBubble commented 2 years ago

在paddle模型预测过程中,虽然使用了model.eval(),但每次模型的推理结果仍然不相同,比如PaddleNLP/examples/text_matching/ernie_matching/predict_pairwise.py,训练好模型后,通过如下命令每次执行这个predict.py文件得到的结果都不相同。

unset CUDA_VISIBLE_DEVICES
python -u -m paddle.distributed.launch --gpus "0" \
    predict_pairwise.py \
    --device gpu \
    --params_path "./checkpoints/model_20000/model_state.pdparams"\
    --batch_size 128 \
    --max_seq_length 64 \
    --input_file 'test.tsv'

请问这是哪里的问题?

hermitgreen commented 2 years ago

我在使用ernie1.0的时候发现了同样的问题,大概在小数点5位以后出现精度不对齐情况

tianxin1860 commented 2 years ago

你好,可以 share 一下多次预测的结果对比图?

sunhaha123 commented 2 years ago

sentence_transformers也是如此,醉了

tianxin1860 commented 2 years ago

您好,我本地验分别验证了 ERNIE-Gram Point-wise、Pair-wise 2种训练范式的下推理结果,多次推理结果完全一致,具体数值如下:

基于 ERNIE-Gram 的 Point-wise 范式 2 次推理结果 image

基于 ERNIE-Gram 的 Pair-wise 范式 2 次推理结果 image

本地测试环境如下:

paddlepaddle-gpu   2.2.0
paddlenlp develop 分支

可否提供多次推理结果不一致的可复现环境,我们可以帮助定位问题。具体包括:

1. 使用的训练代码、启动脚本
2. 使用的预测代码、启动脚本
3. 多次推理结果不一致所加载的模型参数
4. 测试数据
5. PaddlePaddle 版本号
6. PaddleNLP 版本号
tianxin1860 commented 2 years ago

@BlueSkyBubble @hermitgreen @sunhaha123

sunhaha123 commented 2 years ago

@tianxin1860 是 nlp_example\text_matching\sentence_transformers , 2 3 4

,其次想问下nlp_example\text_matching\simbert 为什么没有train.py,谢谢?

tianxin1860 commented 2 years ago

SimBERT 模型目前提供基于开源模型的预测能力,训练策略暂未集成。@sunhaha123

Steffy-zxf commented 2 years ago

@sunhaha123 是否能够提供最小复现代码?

sunhaha123 commented 2 years ago

@Steffy-zxf 70595f2f77aef0799fe0cf40774af1b9_145167285-8e084cdb-0efb-48bd-a985-c76ca4609778 这个图片我在aistudio里直接运行的,什么都没改。就是sentences_transform这个文件内下的模型,我看是可能因为导入了from model import SentenceTransformer。

ZeyuChen commented 2 years ago

@HarderThenHarder 明天我们的工程师会回复您这个问题。@Steffy-zxf 明天重点关注下哈

Steffy-zxf commented 2 years ago

@HarderThenHarder @sunhaha123 你好!请确认下训练后保存的模型参数是否被正确加载,如以下代码

    if args.init_from_ckpt and os.path.isfile(args.init_from_ckpt):
        state_dict = paddle.load(args.init_from_ckpt)
        model.set_dict(state_dict)
HarderThenHarder commented 2 years ago

Fine-Tuning模型应该是被正确加载了的: image 您方便给个如流号吗,我通过如流联系您。

Steffy-zxf commented 2 years ago

@HarderThenHarder 你好, 我的如流号叫做 张雪菲。

hermitgreen commented 2 years ago

@BlueSkyBubble @hermitgreen @sunhaha123

https://github.com/PaddlePaddle/PaddleNLP/issues/1604

jeffzhengye commented 2 years ago

这个bug 解决了没有,我也发现QuestionMatching 里面的inference结果不一样。 LQ那个数据集,test 推理跑了几次,每次acc都不一样。acc: 0.86576 acc: 0.86632, acc: 0.86512 虽然相隔不大

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 60 days with no activity. 当前issue 60天内无活动,被标记为stale。

github-actions[bot] commented 1 year ago

This issue was closed because it has been inactive for 14 days since being marked as stale. 当前issue 被标记为stale已有14天,即将关闭。