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

加载 PNNX 导出的模型时出现 layer aten::exp not exists or registered #4101

Closed
csukuangfj opened this issue Jul 30, 2022 · 10 comments
Closed

Comments

@csukuangfj
Copy link
Contributor

error log | 日志或报错信息 | ログ

layer aten::exp not exists or registered

layer pnnx.Expression not exists or registered

model | 模型 | モデル

  1. original model

针对 https://github.com/k2-fsa/icefall/blob/master/egs/librispeech/ASR/pruned_transducer_stateless2/decoder.py
当使用 torch.jit.trace() 时,可以成功导出成 torchscript model, 命名为 decoder_jit_trace.pt.

how to reproduce | 复现步骤 | 再現方法

源码编译 master 分支的 PNNX, 然后运行:

src/pnnx /path/to/decoder_jit_trace.pt

生成如下文件:

-rw-r--r-- 1 kuangfangjun root  503K Jul 30 20:58 icefall/decoder_jit_trace.ncnn.bin
-rw-r--r-- 1 kuangfangjun root   615 Jul 30 20:58 icefall/decoder_jit_trace.ncnn.param
-rw-r--r-- 1 kuangfangjun root 1005K Jul 30 20:58 icefall/decoder_jit_trace.pnnx.bin
-rw-r--r-- 1 kuangfangjun root   956 Jul 30 20:58 icefall/decoder_jit_trace.pnnx.param
-rw-r--r-- 1 kuangfangjun root   605 Jul 30 20:58 icefall/decoder_jit_trace_ncnn.py
-rw-r--r-- 1 kuangfangjun root  2.5K Jul 30 20:58 icefall/decoder_jit_trace_pnnx.py

decoder_jit_trace.ncnn.param 的内容如下:

7767517
9 9
Input                    in0                      0 1 in0
MemoryData               pnnx_unique_0            0 1 1
aten::exp                pnnx_10                  1 1 1 2
Embed                    embed_0                  1 1 in0 3 0=512 1=500 2=0 3=256000
BinaryOp                 mul_0                    2 1 3 2 4 0=2
Permute                  permute_2                1 1 4 5 0=1
ConvolutionDepthWise1D   convdw1d_4               1 1 5 6 0=512 1=2 2=1 3=1 4=0 5=0 6=1024 7=512
Permute                  permute_3                1 1 6 7 0=1
ReLU                     relu_1                   1 1 7 out0

然后使用从 master 编译的python 版本 ncnn 读取上面生成的 ncnn 模型

import ncnn

decoder = ncnn.Net()
decoder.load_param("/path/to/decoder_jit_trace.ncnn.param")

会出现如下错误:

layer aten::exp not exists or registered

然后就是 Segmentation fault


针对 https://github.com/k2-fsa/icefall/blob/master/egs/librispeech/ASR/pruned_transducer_stateless2/conformer.py
重复上面的方法,会出现如下错误:

layer pnnx.Expression not exists or registered

导致上述错误的 param 文件,部分内容如下:
(注意,在下半部分出现了 pnnx.Expression pnnx_expr_2155 1 1 21 23)

7767517
1387 1759
Input                    in0                      0 1 in0
Input                    in1                      0 1 in1
ExpandDims               unsqueeze_300            1 1 in0 2 -23303=1,0
Convolution              conv_75                  1 1 2 3 0=8 1=3 11=3 12=1 13=1 14=1 2=1 3=1 4=1 5=1 6=72
Split                    splitncnn_0              1 2 3 4 5
BinaryOp                 sub_0                    1 1 4 6 0=1 1=1 2=1.000000e+00
Sigmoid                  sigmoid_0                1 1 6 7
BinaryOp                 mul_1                    2 1 5 7 8 0=2
Convolution              conv_76                  1 1 8 9 0=32 1=3 11=3 12=1 13=2 14=0 2=1 3=2 4=0 5=1 6=2304
Split                    splitncnn_1              1 2 9 10 11
BinaryOp                 sub_2                    1 1 10 12 0=1 1=1 2=1.000000e+00
Sigmoid                  sigmoid_1                1 1 12 13
BinaryOp                 mul_3                    2 1 11 13 14 0=2
Convolution              conv_77                  1 1 14 15 0=128 1=3 11=3 12=1 13=2 14=0 2=1 3=2 4=0 5=1 6=36864
Split                    splitncnn_2              1 2 15 16 17
BinaryOp                 sub_4                    1 1 16 18 0=1 1=1 2=1.000000e+00
Sigmoid                  sigmoid_2                1 1 18 19
BinaryOp                 mul_5                    2 1 17 19 20 0=2
Split                    splitncnn_3              1 2 20 21 22
pnnx.Expression          pnnx_expr_2155           1 1 21 23
Permute                  transpose_239            1 1 22 24 0=0
Tensor.reshape           view_shape_0             2 1 24 23 25
MemoryData               encoder_embed.out_norm   0 1 26
InnerProduct             linear_78                1 1 25 27 0=512 1=1 2=1245184
Split                    splitncnn_4              1 2 27 28 29
BinaryOp                 pow_6                    1 1 28 30 0=6 1=1 2=2.000000e+00
aten::exp                pnnx_60                  1 1 26 31
Reduction                mean_176                 1 1 30 32 0=3 1=0 -23303=1,-1 4=1 5=1
BinaryOp                 add_7                    2 1 32 31 33 0=0
BinaryOp                 pow_8                    1 1 33 34 0=6 1=1 2=-5.000000e-01
BinaryOp                 mul_9                    2 1 29 34 35 0=2
Split                    splitncnn_5              1 3 35 36 37 38
@DataXujing
Copy link

我在YOLOv6n通过 torchscript->pnnx->ncnn也遇到了相同的问题

@csukuangfj
Copy link
Contributor Author

还是自己看代码,自己解决吧

@sungh66
Copy link

sungh66 commented Aug 11, 2022

大佬们解决了吗,我也遇到了这个问题

@csukuangfj
Copy link
Contributor Author

大佬们解决了吗,我也遇到了这个问题

这个要修改 pnnx 的源代码. pnnx 目前不支持 把 aten::exp 转成 ncnn 中的 UnaryOp.

@csukuangfj
Copy link
Contributor Author

大佬们解决了吗,我也遇到了这个问题

你可以参考 csukuangfj#1 这个,添加对 aten::exp
的处理。

但是,可能在转换的过程中,你的模型里面,还有 pnnx 未支持的 op, 你自己还要再改 pnnx 的源代码.

@Clara2333333
Copy link

我在YOLOv6n通过 torchscript->pnnx->ncnn也遇到了相同的问题

你好,请问你后来解决了吗,yolov6n能部署到安卓上吗

@DataXujing
Copy link

我在YOLOv6n通过 torchscript->pnnx->ncnn也遇到了相同的问题

你好,请问你后来解决了吗,yolov6n能部署到安卓上吗

这是我的处理方式:

https://github.com/DataXujing/ncnn_android_yolov6#1%E6%A8%A1%E5%9E%8B%E8%BD%ACncnn

@Clara2333333
Copy link

我在YOLOv6n通过 torchscript->pnnx->ncnn也遇到了相同的问题

你好,请问你后来解决了吗,yolov6n能部署到安卓上吗

这是我的处理方式:

https://github.com/DataXujing/ncnn_android_yolov6#1%E6%A8%A1%E5%9E%8B%E8%BD%ACncnn

非常感谢!我去试试!!!

@Clara2333333
Copy link

我在YOLOv6n通过 torchscript->pnnx->ncnn也遇到了相同的问题

你好,请问你后来解决了吗,yolov6n能部署到安卓上吗

这是我的处理方式:

https://github.com/DataXujing/ncnn_android_yolov6#1%E6%A8%A1%E5%9E%8B%E8%BD%ACncnn

您好,打扰啦~请问为什么最后生成的是四个文件呢yolov6n.param,yolov6n.bin,yolov6_opt.param和yolov6n_opt.bin,之前在Android studio部署中见过前两个,请问yolov6_opt.param和yolov6n_opt.bin是什么呢,是如何调用的呢

@nihui
Copy link
Member

nihui commented May 16, 2023

aten::exp 支持了

@nihui nihui closed this as completed May 16, 2023
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

5 participants