Libtorch中的bug

这篇文件记录了使用libtorch过程中运到的一些bug

module->get_parameters()

使用下面的调用方式:

const torch::OrderedDict<std::string, torch::jit::script::NamedParameter> param = module->get_parameters();

报下面的错误:

/usr/include/c++/5/ext/new_allocator.h:120:4: error: use of deleted function ‘torch::OrderedDict<std::basic_string<char>, torch::jit::script::NamedParameter>::Item::Item(const torch::OrderedDict<std::basic_string<char>, torch::jit::script::NamedParameter>::Item&)’{ ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }

需要看下get_parameters()的返回类型:

const torch::OrderedDict<std::string, NamedParameter>& get_parameters() const {
return parameters;
}

get_parameters()返回的是const类型的引用,不能使用一个引用赋值给一个对象,应该使用下面的调用方式:

const torch::OrderedDict<std::string, torch::jit::script::NamedParameter>& param = module->get_parameters();

这里论述下面的两个问题:

关于const的使用

关于引用、对象的使用

libtorch和pytorch的版本问题

高版本的pytorch trace生成的model不能用低版本的litorch load, 否则报下面的异常:

terminate called after throwing an instance of 'c10::Error'
what(): tag == RecordTags::FOOTER ASSERT FAILED at /pytorch/caffe2/serialize/inline_container.h:234, please report a bug to PyTorch. File footer has wrong record type. Is this file corrupted? (readAndV
alidateFileFooter at /pytorch/caffe2/serialize/inline_container.h:234)
frame #0: std::function<std::string ()>::operator()() const + 0x11 (0x7f95aad91b81 in /data/source/libtorch/lib/libc10.so)
frame #1: c10::Error::Error(c10::SourceLocation, std::string const&) + 0x2a (0x7f95aad9144a in /data/source/libtorch/lib/libc10.so)
frame #2: <unknown function> + 0x682b0e (0x7f95d7c91b0e in /data/source/libtorch/lib/libtorch.so.1)
frame #3: <unknown function> + 0x686833 (0x7f95d7c95833 in /data/source/libtorch/lib/libtorch.so.1)
frame #4: <unknown function> + 0x67b5f9 (0x7f95d7c8a5f9 in /data/source/libtorch/lib/libtorch.so.1)
frame #5: torch::jit::load(std::istream&) + 0x7c (0x7f95d7c9018c in /data/source/libtorch/lib/libtorch.so.1)
frame #6: torch::jit::load(std::string const&) + 0x130 (0x7f95d7c903b0 in /data/source/libtorch/lib/libtorch.so.1)
frame #7: init_model(std::shared_ptr<torch::jit::script::Module>&, std::string) + 0x50 (0x43d9d0 in ./pycvt)
frame #8: main + 0x8f (0x452862 in ./pycvt)
frame #9: __libc_start_main + 0xf0 (0x7f95aa433830 in /lib/x86_64-linux-gnu/libc.so.6)
frame #10: _start + 0x29 (0x43c4b9 in ./pycvt)

已放弃

qiyi-ffmpeg链接libtorch

主要功能文件如下:

  1. vf_qrestore.c filter功能实现文件,ffmpeg调用转换得到数据类型后调用qrestore_wrapper

  2. qrestore_wrapper.cpp 使用c规则包裹C++函数供ffmpeg编译,编译生成qrestore_wrapper.a

  3. qrestore.cpp 使用c++实现质量恢复供包裹函数wrapper调用,编译生成qrestore.a

测试简单版本vf_qrestore.c和wrapper没有问题

qiiyi-ffmpeg编译

./configure --enable-cross-compile --enable-yasm  --enable-static   --enable-nonfree --enable-gpl   --disable-filter=intertrustwm --disable-filter=iqiyiwm --disable-filter=css   --disable-optimizations --extra-cflags="-I/home/maxliu/eclipse_201908-workspace/wrappertest/src -I/home/maxliu/eclipse_201908-workspace/Qrestore/src" --extra-ldflags="-L/data/source/libtorch/lib -L/home/maxliu/eclipse_201908-workspace/wrappertest/src -L/home/maxliu/eclipse_201908-workspace/Qrestore/src/build" --extra-libs='-lCppAddWrapper -lCppAdd -lstqrestore_wrapper -lstqrestore -ltorch -lc10_cuda -lc10 -llibcudart-5d6d23a3.so.8.0.61 -llibgomp-7bcb08ae.so.1 -llibnvrtc-56d4825a.so.8.0.61 -lnvrtc-builtins -llibnvToolsExt-422e3301.so.1 -llibtorch.so.1 -lstdc++' --prefix=/usr/local/ffmpeg_new_master

--extra-libs='-lCppAddWrapper -lCppAdd-lCppAddWrapper-lCppAdd顺序不能颠倒

configure_qiyi_simple.sh通过,编译Error:

gcc is unable to create an executable file.
If gcc is a cross-compiler, use the --enable-cross-compile option.
Only do this if you know what cross compiling means.
C compiler test failed.

编译pytorch source

[ 68%] Linking CXX shared library ../lib/libcaffe2.so
[ 68%] Built target caffe2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Failed to run 'bash ../tools/build_pytorch_libs.sh --use-cuda --use-fbgemm --use-nnpack --use-mkldnn --use-qnnpack caffe2'

编译pytorch source需要cuDNN > 7, ATen 模块至少需要6以上版本,所以最好更新cudnn到比较高的版本

Artifact Reduction Project conda-using-skill

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×