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

ConvTranspse算子执行发生段错误 #3067

Open
SheepHuan opened this issue Oct 30, 2024 · 2 comments
Open

ConvTranspse算子执行发生段错误 #3067

SheepHuan opened this issue Oct 30, 2024 · 2 comments
Labels
duplicate This issue or pull request already exists memory

Comments

@SheepHuan
Copy link

SheepHuan commented Oct 30, 2024

平台(如果交叉编译请再附上交叉编译目标平台):

Platform(Include target platform as well if cross-compiling):

# (base) root@be662baf462f:/workspace/MNN/build# cat /etc/*release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.3 LTS"
PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.3 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

# (base) root@be662baf462f:/workspace/MNN/build# lscpu
Architecture:            x86_64
  CPU op-mode(s):        32-bit, 64-bit
  Address sizes:         46 bits physical, 48 bits virtual
  Byte Order:            Little Endian
CPU(s):                  56
  On-line CPU(s) list:   0-55
Vendor ID:               GenuineIntel
  Model name:            Intel(R) Xeon(R) Gold 5120 CPU @ 2.20GHz
    CPU family:          6
    Model:               85
    Thread(s) per core:  2
    Core(s) per socket:  14
    Socket(s):           2
    Stepping:            4
    CPU max MHz:         3200.0000
    CPU min MHz:         1000.0000
    BogoMIPS:            4400.00
    Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs b
                         ts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_
                         deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single pti intel_ppin ssbd mba ibrs ibpb stibp tpr_shadow vnmi flexpriority ept 
                         vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsav
                         ec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts pku ospke md_clear flush_l1d arch_capabilities
Virtualization features: 
  Virtualization:        VT-x
Caches (sum of all):     
  L1d:                   896 KiB (28 instances)
  L1i:                   896 KiB (28 instances)
  L2:                    28 MiB (28 instances)
  L3:                    38.5 MiB (2 instances)
NUMA:                    
  NUMA node(s):          2
  NUMA node0 CPU(s):     0-13,28-41
  NUMA node1 CPU(s):     14-27,42-55
Vulnerabilities:         
  Itlb multihit:         KVM: Mitigation: VMX disabled
  L1tf:                  Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable
  Mds:                   Mitigation; Clear CPU buffers; SMT vulnerable
  Meltdown:              Mitigation; PTI
  Mmio stale data:       Mitigation; Clear CPU buffers; SMT vulnerable
  Retbleed:              Mitigation; IBRS
  Spec store bypass:     Mitigation; Speculative Store Bypass disabled via prctl and seccomp
  Spectre v1:            Mitigation; usercopy/swapgs barriers and __user pointer sanitization
  Spectre v2:            Mitigation; IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS Not affected
  Srbds:                 Not affected
  Tsx async abort:       Mitigation; Clear CPU buffers; SMT vulnerable

Github版本:

Github Version:

2.9.6版本, commit: a74551b

编译方式:

Compiling Method

# 请在这里粘贴cmake参数或使用的cmake脚本路径以及完整输出
(base) root@be662baf462f:/workspace/MNN/build# cmake .. -DMNN_BUILD_CONVERTER=ON -DMNN_BUILD_BENCHMARK=ON
-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- The ASM compiler identification is GNU
-- Found assembler: /usr/bin/cc
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- 
-- 3.19.0.0
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Performing Test protobuf_HAVE_BUILTIN_ATOMICS
-- Performing Test protobuf_HAVE_BUILTIN_ATOMICS - Success
-- Use Threadpool, forbid openmp
-- >>>>>>>>>>>>>
-- MNN BUILD INFO:
--      System: Linux
--      Processor: x86_64
--      Version: 2.9.6
--      Metal: OFF
--      OpenCL: OFF
--      OpenGL: OFF
--      Vulkan: OFF
--      ARM82: ON
--      oneDNN: OFF
--      TensorRT: OFF
--      CoreML: OFF
--      NNAPI: OFF
--      CUDA: OFF
--      OpenMP: OFF
--      BF16: OFF
--      ThreadPool: ON
--      Hidden: TRUE
--      Build Path: /workspace/MNN/build
--      CUDA PROFILE: OFF
-- WIN_USE_ASM: 
-- x86_64: Open SSE
-- MNN_AVX512:OFF
-- Onnx: 
-- Configuring done
-- Generating done
-- Build files have been written to: /workspace/MNN/build

编译日志:

Build Log:

...
[ 98%] Built target testModel.out
[ 98%] Linking CXX executable testTrain.out
[ 98%] Built target testTrain.out
[ 98%] Linking CXX executable GetMNNInfo
[ 98%] Built target GetMNNInfo
[ 98%] Linking CXX executable modelCompare.out
[ 98%] Linking CXX executable testModelWithDescribe.out
[ 98%] Built target modelCompare.out
[ 98%] Linking CXX executable backendTest.out
[ 98%] Built target testModelWithDescribe.out
[ 98%] Built target backendTest.out
[ 98%] Linking CXX executable MNNV2Basic.out
[ 98%] Built target MNNV2Basic.out
[ 98%] Linking CXX executable SequenceModuleTest.out
[ 98%] Built target SequenceModuleTest.out
[ 98%] Linking CXX executable benchmarkExprModels.out
[ 98%] Built target benchmarkExprModels.out
[ 98%] Linking CXX executable ModuleBasic.out
[ 98%] Built target ModuleBasic.out
[ 98%] Linking CXX executable fuseTest
[ 99%] Linking CXX executable mobilenetTest.out
[ 99%] Built target fuseTest
[ 99%] Built target mobilenetTest.out
[ 99%] Linking CXX executable LoRA
[ 99%] Built target LoRA
[ 99%] Linking CXX executable mergeInplaceForCPU
[ 99%] Built target mergeInplaceForCPU
[ 99%] Linking CXX executable benchmark.out
[ 99%] Built target benchmark.out
[ 99%] Linking CXX executable timeProfile.out
[ 99%] Built target timeProfile.out
[ 99%] Linking CXX shared library libMNNConvertDeps.so
[ 99%] Built target MNNConvertDeps
[ 99%] Building CXX object tools/converter/CMakeFiles/MNNDump2Json.dir/source/MNNDump2Json.cpp.o
[ 99%] Building CXX object tools/converter/CMakeFiles/TestPassManager.dir/source/TestPassManager.cpp.o
[ 99%] Building CXX object tools/converter/CMakeFiles/MNNConvert.dir/source/MNNConverter.cpp.o
[ 99%] Building CXX object tools/converter/CMakeFiles/TestConvertResult.dir/source/TestConvertResult.cpp.o
[ 99%] Building CXX object tools/converter/CMakeFiles/MNNRevert2Buffer.dir/source/MNNRevert2Buffer.cpp.o
[ 99%] Linking CXX executable ../../MNNDump2Json
[ 99%] Linking CXX executable ../../MNNRevert2Buffer
[ 99%] Linking CXX executable ../../MNNConvert
[ 99%] Linking CXX executable ../../TestConvertResult
[ 99%] Built target MNNDump2Json
[ 99%] Built target MNNRevert2Buffer
[ 99%] Built target MNNConvert
[ 99%] Built target TestConvertResult
[100%] Linking CXX executable ../../TestPassManager
[100%] Built target TestPassManager

问题描述

Pytorch模型代码

这是我的pytorch定义的模型结构,我后续的模型都是基于这个导出的。

import torch.nn as nn
import torch
class BasicConv(nn.Module):

    def __init__(self, in_channels, out_channels, deconv=False, is_3d=False, bn=True, relu=True, **kwargs):
        super(BasicConv, self).__init__()

        self.relu = relu
        self.use_bn = bn
        if is_3d:
            if deconv:
                self.conv = nn.ConvTranspose3d(in_channels, out_channels, bias=False, **kwargs)
            else:
                self.conv = nn.Conv3d(in_channels, out_channels, bias=False, **kwargs)
            self.bn = nn.BatchNorm3d(out_channels)
        else:
            if deconv:
                self.conv = nn.ConvTranspose2d(in_channels, out_channels, bias=False, **kwargs)
            else:
                self.conv = nn.Conv2d(in_channels, out_channels, bias=False, **kwargs)
            self.bn = nn.BatchNorm2d(out_channels)

    def forward(self, x):
        x = self.conv(x)
        if self.use_bn:
            x = self.bn(x)
        if self.relu:
            x = nn.LeakyReLU()(x)#, inplace=True)
        return x


# 这个ONNX转成MNN,运行benchmark会报错
model1 = BasicConv(32, 16, deconv=True, 
                  is_3d=True,
                  bn=True,
                  relu=True, 
                  kernel_size=(4, 4, 4), 
                  padding=(1, 1, 1), 
                  stride=(2, 2, 2))
x1 = torch.randn([1,32,12,30,40])

out = model1(x1)
torch.onnx.export(
    model1,
    x1,
    'ckpt/basic1.onnx',
)


# 这个ONNX转成MNN,运行benchmark不会报错
model2 = BasicConv(48, 24, deconv=True, is_3d=True, bn=True,
                                relu=True, kernel_size=(4, 4, 4), padding=(1, 1, 1), stride=(2, 2, 2))
x2 = torch.randn([1,48,6,15,20])

out = model2(x2)
torch.onnx.export(
    model2,
    x2,
    'ckpt/basic2.onnx',
)

MNNConvert

# 转换basic1模型
(base) root@be662baf462f:/workspace/MNN/build# ./MNNConvert -f ONNX --modelFile /workspace/MobileHumanPose3D/ckpt/basic1.onnx --MNNModel basic1.mnn --saveStaticModel 
Can't open file:/sys/devices/system/cpu/cpufreq/ondemand/affected_cpus
CPU Group: [ 35  49  10  39  7  29  19  47  37  5  27  55  17  45  20  3  25  53  15  43  33  1  23  51  13  41  31  21  34  8  48  38  6  28  18  46  36  4  26  54  16  44  11  2  24  52  14  42  32  0  22  50  12  40  9  30 ], 1000000 - 3200000
The device supports: i8sdot:0, fp16:0, i8mm: 0, sve2: 0
Don't has bizCode, use MNNTest for default
Start to Convert Other Model Format To MNN Model..., target version: 2.9
[12:20:39] /workspace/MNN/tools/converter/source/onnx/onnxConverter.cpp:46: ONNX Model ir version: 8
[12:20:39] /workspace/MNN/tools/converter/source/onnx/onnxConverter.cpp:47: ONNX Model opset version: 17
Start to Optimize the MNN Net...
inputTensors : [ onnx::ConvTranspose_0, ]
outputTensors: [ 9, ]
gen Static Model ... 
Converted Success!


# 转换basic2模型
(base) root@be662baf462f:/workspace/MNN/build# ./MNNConvert -f ONNX --modelFile /workspace/MobileHumanPose3D/ckpt/basic2.onnx --MNNModel basic2.mnn --saveStaticModel 
Can't open file:/sys/devices/system/cpu/cpufreq/ondemand/affected_cpus
CPU Group: [ 35  49  10  39  7  29  19  47  37  5  27  55  17  45  20  3  25  53  15  43  33  1  23  51  13  41  31  21  34  8  48  38  6  28  18  46  36  4  26  54  16  44  11  2  24  52  14  42  32  0  22  50  12  40  9  30 ], 1000000 - 3200000
The device supports: i8sdot:0, fp16:0, i8mm: 0, sve2: 0
Don't has bizCode, use MNNTest for default
Start to Convert Other Model Format To MNN Model..., target version: 2.9
[12:22:44] /workspace/MNN/tools/converter/source/onnx/onnxConverter.cpp:46: ONNX Model ir version: 8
[12:22:44] /workspace/MNN/tools/converter/source/onnx/onnxConverter.cpp:47: ONNX Model opset version: 17
Start to Optimize the MNN Net...
inputTensors : [ onnx::ConvTranspose_0, ]
outputTensors: [ 9, ]
gen Static Model ... 
Converted Success!

运行benchmark.out

# benchmark.out运行basic1.mnn出现段错误
(base) root@be662baf462f:/workspace/MNN/build# cp basic1.mnn models/basic.mnn ;  ./benchmark.out models/ 10 0 0 1 0
MNN benchmark
Forward type: CPU thread=1 precision=0 sparsity=0 sparseBlockOC=1 testQuantizedModel=0
--------> Benchmarking... loop = 10, warmup = 0
[-INFO-]: precision!=2, use fp32 inference.
Can't open file:/sys/devices/system/cpu/cpufreq/ondemand/affected_cpus
CPU Group: [ 35  49  10  39  7  29  19  47  37  5  27  55  17  45  20  3  25  53  15  43  33  1  23  51  13  41  31  21  34  8  48  38  6  28  18  46  36  4  26  54  16  44  11  2  24  52  14  42  32  0  22  50  12  40  9  30 ], 1000000 - 3200000
The device supports: i8sdot:0, fp16:0, i8mm: 0, sve2: 0
Segmentation fault (core dumped)

# benchmark.out运行basic2.mnn,正确的返回了测试结果
(base) root@be662baf462f:/workspace/MNN/build# cp basic2.mnn models/basic.mnn ;  ./benchmark.out models/ 10 0 0 1 0
MNN benchmark
Forward type: CPU thread=1 precision=0 sparsity=0 sparseBlockOC=1 testQuantizedModel=0
--------> Benchmarking... loop = 10, warmup = 0
[-INFO-]: precision!=2, use fp32 inference.
Can't open file:/sys/devices/system/cpu/cpufreq/ondemand/affected_cpus
CPU Group: [ 35  49  10  39  7  29  19  47  37  5  27  55  17  45  20  3  25  53  15  43  33  1  23  51  13  41  31  21  34  8  48  38  6  28  18  46  36  4  26  54  16  44  11  2  24  52  14  42  32  0  22  50  12  40  9  30 ], 1000000 - 3200000
The device supports: i8sdot:0, fp16:0, i8mm: 0, sve2: 0
[ - ] basic.mnn                   max = 3159.436 ms  min =  563.146 ms  avg = 1024.928 ms

附件

包含了basic1.onnx,basic2.onnxbasic1.mnn,basic2.mnn
onnxs_and_mnns.zip

@jxt1234
Copy link
Collaborator

jxt1234 commented Oct 31, 2024

我这都能测试通过,应该和
#3061
是类似的问题,占用内存过大。第一个模型占了接近7G内存

@jxt1234 jxt1234 added the duplicate This issue or pull request already exists label Oct 31, 2024
@jxt1234 jxt1234 added the memory label Dec 23, 2024
@jxt1234
Copy link
Collaborator

jxt1234 commented Dec 23, 2024

ConvTranspose 内存占用已经降下来了,不过 conv3d 还待优化

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists memory
Projects
None yet
Development

No branches or pull requests

2 participants