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

predictor.run()报错 #8997

Closed
2017040264 opened this issue May 9, 2022 · 31 comments
Closed

predictor.run()报错 #8997

2017040264 opened this issue May 9, 2022 · 31 comments
Assignees

Comments

@2017040264
Copy link

建立 issue 时,为快速解决问题,请您根据使用情况给出如下信息:

  • 标题:predictor.run()运行失败
  • 版本、环境信息:
       1)Paddle Lite 版本:v2.11-rc
       2)Host 环境:Win10 ,手机是 红米note10pro
  • 模型信息
       1)NLP——对联生成
    2)https://aistudio.baidu.com/aistudio/projectdetail/3963474?contributionType=1&shared=1
  • 复现信息:! paddle_lite_opt --model_file=./trained_model/net.pdmodel --param_file=./trained_model/net.pdiparams --optimize_out=./trained_model/v1_opt
  • 问题描述:报错如下:

92705f43172e6eddfd2dc67cded9689

我检查了一下,是predictor.run()运行失败运行失败。模型的输入有两个,我是这样写的代码:
1652059281(1)

@paddle-bot-old
Copy link

paddle-bot-old bot commented May 9, 2022

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网文档常见问题历史Issue来寻求解答。祝您生活愉快~

Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the APIFAQ and Github Issue to get the answer.Have a nice day!

@2017040264
Copy link
Author

搞不明白那里出错了,请大佬们指教!

@2017040264
Copy link
Author

1652060801(1)

@chenjiaoAngel
Copy link
Collaborator

image

这个错误看起来是某个文件没有找到运行出错

@2017040264
Copy link
Author

那个[QT]错误好像不影响运行,主要是最下边那个

@chenjiaoAngel
Copy link
Collaborator

请问原始模型在哪呢?另外,这个模型的输入数据类型好像是int64 int32,需要设置正确的数据类型。boolean setData(float[] data); 这个接口用的是float 类型

@chenjiaoAngel
Copy link
Collaborator

Java API:https://paddle-lite.readthedocs.io/zh/develop/api_reference/java_api_doc.html#setdata
设置数据类型时:Tensor = predictor.getInput(0); data_ptr = tensor.mutable_data<int64_t>(); 或者data_ptr = tensor.mutable_data<int32_t>();

@2017040264
Copy link
Author

Java API:https://paddle-lite.readthedocs.io/zh/develop/api_reference/java_api_doc.html#setdata 设置数据类型时:Tensor = predictor.getInput(0); data_ptr = tensor.mutable_data<int64_t>(); 或者data_ptr = tensor.mutable_data<int32_t>();

看明白我的数据类型存在问题了,但是data_ptr = tensor.mutable_data<int32_t>();这个操作不会弄,是在setData(float[])之后操作吗?有没有比较完整的demo可以参考呢?

@chenjiaoAngel
Copy link
Collaborator

你在tensor.java 文件中添加int64 setData 接口支持就行
/** * Set the tensor int data. * * @param buf the int array buffer which will be copied into tensor. * @return true if set data successfully. */ public boolean setData(long[] buf) { if (readOnly) { return false; } return nativeSetData(buf); }

@chenjiaoAngel
Copy link
Collaborator

参考这个文件:https://github.com/PaddlePaddle/Paddle-Lite/blob/develop/lite/api/android/jni/src/com/baidu/paddle/lite/Tensor.java#L117
添加setData(long[] buf) 支持
public boolean setData(long[] buf) { if (readOnly) { return false; } return nativeSetData(buf); }
默认支持float/byte/int32_t 三种数据类型

@chenjiaoAngel
Copy link
Collaborator

Java API 接口没有开放此类型支持,已提PR 修复:#8999

@2017040264
Copy link
Author

参考这个文件:https://github.com/PaddlePaddle/Paddle-Lite/blob/develop/lite/api/android/jni/src/com/baidu/paddle/lite/Tensor.java#L117 添加setData(long[] buf) 支持 public boolean setData(long[] buf) { if (readOnly) { return false; } return nativeSetData(buf); } 默认支持float/byte/int32_t 三种数据类型

我在Ai studio平台上使用int32类型的数据也可以得到输出(输出是int64)的。我必须要把输入也改成int64或者把输出改成int32吗?

@2017040264
Copy link
Author

参考这个文件:https://github.com/PaddlePaddle/Paddle-Lite/blob/develop/lite/api/android/jni/src/com/baidu/paddle/lite/Tensor.java#L117 添加setData(long[] buf) 支持 public boolean setData(long[] buf) { if (readOnly) { return false; } return nativeSetData(buf); } 默认支持float/byte/int32_t 三种数据类型

这样我得重新编译那个paddle lite源码吧?

@2017040264
Copy link
Author

参考这个文件:https://github.com/PaddlePaddle/Paddle-Lite/blob/develop/lite/api/android/jni/src/com/baidu/paddle/lite/Tensor.java#L117 添加setData(long[] buf) 支持 public boolean setData(long[] buf) { if (readOnly) { return false; } return nativeSetData(buf); } 默认支持float/byte/int32_t 三种数据类型

我在Ai studio平台上使用int32类型的数据也可以得到输出(输出是int64)的。我必须要把输入也改成int64或者把输出改成int32吗?
输入信息:
1652088968
输出:
1652088968(1)

@chenjiaoAngel
Copy link
Collaborator

这个根据模型进行选择,如果模型输入是int32, 输出是int64。那输入数据类型设置int32,输出设置int64 就行

@2017040264
Copy link
Author

这个根据模型进行选择,如果模型输入是int32, 输出是int64。那输入数据类型设置int32,输出设置int64 就行

这是不是说,我的报错不是因为数据类型的问题,因为int32是已经支持的。

@chenjiaoAngel
Copy link
Collaborator

嗯,这个paddle 模型地址,能提供下吗?我们本地也看看

@2017040264
Copy link
Author

嗯,这个paddle 模型地址,能提供下吗?我们本地也看看

项目地址:这里 基本是按照你们官方项目写的 『NLP经典项目集』05:新年到,飞桨带你对对联

建议fork一下我的项目,然后重新生成一下.nb文件。(精度不用管,能跑通就行)(目前我猜测可能是模型的输入有俩,如果只有一个可能就可以了;还有就是beam search束宽要设置为1)

@chenjiaoAngel
Copy link
Collaborator

不用整个复杂的项目,你提供训练后保存的paddle 原始模型就行。

@2017040264
Copy link
Author

不用整个复杂的项目,你提供训练后保存的paddle 原始模型就行。

链接:https://pan.baidu.com/s/1V71UQdmi3umpl5I1-bT42A
提取码:cfl6

@2017040264
Copy link
Author

不用整个复杂的项目,你提供训练后保存的paddle 原始模型就行。

链接:https://pan.baidu.com/s/1V71UQdmi3umpl5I1-bT42A 提取码:cfl6

x=paddle.to_tensor([[0 , 566, 566, 489, 42 , 165, 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ]],dtype=paddle.int32)
y=paddle.to_tensor([7],dtype=paddle.int32)

@chenjiaoAngel
Copy link
Collaborator

模型转换失败了:
image
这个模型的输入应该是int64 吧,因为 lookup_table_v2 OP 的输入Ids 要求int64_t

@chenjiaoAngel
Copy link
Collaborator

提供的模型里添加caliber 转换了,但运行有问题,目前挂在RNN 实现,正在处理中。
image
建议将模型输入修改为int64,这样可以减少caliber 算子

@chenjiaoAngel
Copy link
Collaborator

image

OPT 后的模型:

image

RNN的SequenceLength 输入数据类型应该是int32_t

@2017040264
Copy link
Author

因为 lookup_table_v2 OP 的输入Ids 要求int64_t

这个转换是.model转成.nb吗?我没遇到这个问题

@2017040264
Copy link
Author

模型转换失败了: image 这个模型的输入应该是int64 吧,因为 lookup_table_v2 OP 的输入Ids 要求int64_t

在ai studio里面,输入int32也是可以得到结果的。

@2017040264
Copy link
Author

image

OPT 后的模型:
image

RNN的SequenceLength 输入数据类型应该是int32_t

转之前是int32,转之后变成float,是转错了还是?...

@chenjiaoAngel
Copy link
Collaborator

问题已修复,rnn OP 中部分中间态没有初始化引起,已提PR 修复:#9005

@chenjiaoAngel
Copy link
Collaborator

那个是转换错误,kernel pick 时,没有设定input tensor 数据类型,使用了默认的float ,导致多插入了caliber 算子

@2017040264
Copy link
Author

那个是转换错误,kernel pick 时,没有设定input tensor 数据类型,使用了默认的float ,导致多插入了caliber 算子

好的,谢谢,强!

另外问一下,我是不是得等paddlelite版本更新后,才能用上新的(修复问题)的opt工具啊

@chenjiaoAngel
Copy link
Collaborator

嗯嗯,是的

@qili93 qili93 closed this as completed Feb 5, 2024
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

3 participants