ncnn icon indicating copy to clipboard operation
ncnn copied to clipboard

layer `torch.roll` not exists or registered, with pnnx to ncnn

Open WuJune opened this issue 1 year ago • 1 comments

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

❯ python ./pnnx/cpu_demo/scunet_demo_ncnn.py 
layer torch.roll not exists or registered
[1]    80513 segmentation fault (core dumped)  python ./pnnx/cpu_demo/scunet_demo_ncnn.py

model | 模型 | モデル

  1. original model https://github.com/cszn/SCUNet

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

  1. pnnx version: pnnx-20240603 os: fedora 40 convert script:
import torch
import pnnx
from pathlib import Path

import torch

from models.network_scunet import SCUNet as net

device = "cpu"

n_channels = 3

model = net(in_nc=n_channels, config=[4, 4, 4, 4, 4, 4, 4], dim=64)

model.load_state_dict(torch.load("./model_zoo/scunet_color_real_psnr.pth"), strict=True)

for k, v in model.named_parameters():
    v.requires_grad = False
model = model.to(device)

folder_path = Path("pnnx/cpu_demo/")
folder_path.mkdir(exist_ok=True, parents=True)

_input = torch.rand(1, 3, 480, 640).to(device)

opt_model = pnnx.export(
    model, str((folder_path / "scunet_demo.pt").absolute()), _input, device="cpu"
)

# result = opt_model(img_L)

# print(result)

3.infer with ncnn

❯ python ./pnnx/cpu_demo/scunet_demo_ncnn.py 
layer torch.roll not exists or registered
[1]    80513 segmentation fault (core dumped)  python ./pnnx/cpu_demo/scunet_demo_ncnn.py

4.some fragments in scunet_demo.pnnx.param

Tensor.reshape           Tensor.reshape_380       1 1 154 155 shape=(1,512,640,32) $input=154 #154=(1,64,8,80,8,32)f32 #155=(1,512,640,32)f32
torch.roll               torch.roll_1406          1 1 155 156 dims=(1,2) shifts=(4,4) $input=155 #155=(1,512,640,32)f32 #156=(1,512,640,32)f32
pnnx.Expression          pnnx_expr_7583           2 1 131 156 157 expr=add(@0,@1) #131=(1,512,640,32)f32 #156=(1,512,640,32)f32 #157=(1,512,640,32)f32
nn.LayerNorm             m_down2.1.trans_block.ln1 1 1 214 215 elementwise_affine=True eps=1.000000e-05 normalized_shape=(64) @bias=(64)f32 @weight=(64)f32 #214=(1,256,320,64)f32 #215=(1,256,320,64)f32
torch.roll               torch.roll_1407          1 1 215 216 dims=(1,2) shifts=(-4,-4) $input=215 #215=(1,256,320,64)f32 #216=(1,256,320,64)f32
Tensor.reshape           Tensor.reshape_388       1 1 216 217 shape=(1,32,8,40,8,64) $input=216 #216=(1,256,320,64)f32 #217=(1,32,8,40,8,64)f32

5.some fragments in scunet_demo.ncnn.param

Reshape                  reshape_564              1 1 99 100 0=32 1=640 2=512
torch.roll               torch.roll_1404          1 1 100 101
BinaryOp                 add_9                    2 1 70 101 102 0=0
Reshape                  reshape_592              1 1 213 214 0=32 1=640 2=512
torch.roll               torch.roll_1406          1 1 214 215
BinaryOp                 add_21                   2 1 184 215 216 0=0

WuJune avatar Jul 08 '24 09:07 WuJune

https://github.com/Tencent/ncnn/pull/5623

nihui avatar Aug 12 '24 08:08 nihui

fixed, please update your pnnx package

nihui avatar Apr 11 '25 11:04 nihui

fixed, please update your pnnx package

Sorry for the late reply; thanks for your contribution!

WuJune avatar Apr 22 '25 16:04 WuJune