Tencent / ncnn

ncnn is a high-performance neural network inference framework optimized for the mobile platform
Other
20.44k stars 4.16k forks source link

pnnx convert to ncnn failed #5057

Open zhongxiaoyu opened 1 year ago

zhongxiaoyu commented 1 year ago

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

(bk-sdm) :~/pnnx/build/install/bin$ ./pnnx ~/diffusers-ncnn/model/unet-fp16.pt inputshape=[1,4,32,32],[1],[1,77,768] pnnxparam = ~/diffusers_ncnn/model/unet_fp16.pnnx.param pnnxbin = /diffusers_ncnn/model/unet_fp16.pnnx.bin pnnxpy =/diffusers_ncnn/model/unet_fp16_pnnx.py pnnxonnx = /diffusers_ncnn/model/unet_fp16.pnnx.onnx ncnnparam =/diffusers_ncnn/model/unet_fp16.ncnn.param ncnnbin = ~/diffusers_ncnn/model/unet_fp16.ncnn.bin ncnnpy = ~/diffusers_ncnn/model/unet_fp16_ncnn.py fp16 = 1 optlevel = 2 device = cpu inputshape = [1,4,32,32]f32,[1]f32,[1,77,768]f32 inputshape2 = customop = moduleop = ############# pass_level0 inline module = diffusers.models.attention.BasicTransformerBlock inline module = diffusers.models.attention.FeedForward inline module = diffusers.models.attention.GEGLU inline module = diffusers.models.attention_processor.Attention inline module = diffusers.models.embeddings.TimestepEmbedding inline module = diffusers.models.embeddings.Timesteps inline module = diffusers.models.resnet.Downsample2D inline module = diffusers.models.resnet.ResnetBlock2D inline module = diffusers.models.resnet.Upsample2D inline module = diffusers.models.transformer_2d.Transformer2DModel inline module = diffusers.models.unet_2d_blocks.CrossAttnDownBlock2D inline module = diffusers.models.unet_2d_blocks.CrossAttnUpBlock2D open failed inline module = diffusers.models.attention.BasicTransformerBlock inline module = diffusers.models.attention.FeedForward inline module = diffusers.models.attention.GEGLU inline module = diffusers.models.attention_processor.Attention inline module = diffusers.models.embeddings.TimestepEmbedding inline module = diffusers.models.embeddings.Timesteps inline module = diffusers.models.resnet.Downsample2D inline module = diffusers.models.resnet.ResnetBlock2D inline module = diffusers.models.resnet.Upsample2D inline module = diffusers.models.transformer_2d.Transformer2DModel inline module = diffusers.models.unet_2d_blocks.CrossAttnDownBlock2D inline module = diffusers.models.unet_2d_blocks.CrossAttnUpBlock2D

Segmentation fault (core dumped)

model | 模型 | モデル

  1. original model https://huggingface.co/nota-ai/bk-sdm-tiny-2m/tree/main/unet

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

    1.convert to .pt model import os import torch from diffusers import StableDiffusionPipeline

    config

    device = "cuda" from_model = "nota-ai/bk-sdm-tiny-2m" to_model = "model" height, width = 512, 512

check

assert height % 8 == 0 and width % 8 == 0 height, width = height // 8, width // 8 os.makedirs(to_model, exist_ok=True)

load model

pipe = StableDiffusionPipeline.from_pretrained(from_model, torch_dtype=torch.float16) pipe = pipe.to(device)

jit unet

unet = torch.jit.trace(pipe.unet, (torch.tensor(torch.rand(1,4,height,width).to(device), dtype=torch.float16),torch.tensor(torch.rand(1).to(device), dtype=torch.float16),torch.tensor(torch.rand(1,77,768).to(device), dtype=torch.float16)),strict=False) unet.save(os.path.join(to_model,"unet-fp16.pt"))

2.convert to ncnn ./pnnx ~/model/unet-fp16.pt inputshape=[1,4,32,32],[1],[1,77,768]

zhongxiaoyu commented 1 year ago

为什么会出现open failed,最后直接Segmentation fault (core dumped)了

phpofred commented 1 month ago

找到原因了吗 @zhongxiaoyu