本文主要是介绍【tensorrt】——PluginV2Layer must be V2Ext or V2IOExt or V2DynamicExt when there is no implicit batch d,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
tensorrt
1. tensorrt插件
- 用c++为tensorrt写了插件,继承自
IPluginV2
- 用
pybind11
进行python注册
namespace torch2trt {PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {py::class_<InterpolatePlugin>(m, "InterpolatePlugin") // 用 pybind11 封装一个 python 能调用的 c++ 类.def(py::init<std::vector<int64_t>, std::string, bool>(), py::arg("size"), py::arg("mode"), py::arg("align_corners")).def(py::init<const std::string &>(), py::arg("data")).def("getSerializationSize", &InterpolatePlugin::getSerializationSize).def("deserializeFromString", &InterpolatePlugin::deserializeFromString).def("serializeToString", [](const InterpolatePlugin& plugin) {std::string data = plugin.serializeToString();return py::bytes(data);});py::class_<GroupNormPlugin>(m, "GroupNormPlugin").def(py::init<int64_t, at::Tensor, at::Tensor, double>(), py::arg("num_groups"), py::arg("weight"), py::arg("bias"), py::arg("eps")).def(py::init<const std::string &>(), py::arg("data")).def("getSerializationSize", &GroupNormPlugin::getSerializationSize).def("deserializeFromString", &GroupNormPlugin::deserializeFromString).def("serializeToString", [](const GroupNormPlugin& plugin) {std::string data = plugin.serializeToString();return py::bytes(data);});}
} // namespace torch2trt
- 在python中进行使用
from torch2trt.plugins import InterpolatePlugin
PLUGIN_NAME = 'interpolate'
registry = trt.get_plugin_registry()
for c in registry.plugin_creator_list:print("plugin name:", c.name, "plugin namespace:", c.plugin_namespace)if c.name == PLUGIN_NAME and c.plugin_namespace == 'torch2trt':creator = cbreak
torch2trt_plugin = InterpolatePlugin(size=size, mode=mode, align_corners=align_corners) # python 封装的 c++ 类
intert = creator.deserialize_plugin(PLUGIN_NAME, torch2trt_plugin.serializeToString()) # 这两应该是一样的,为啥要用后面的这个。。。
报错:
[TensorRT] ERROR: interprate: PluginV2Layer must be V2Ext or V2IOExt or V2DynamicExt when there is no implicit batch dimension.
[TensorRT] ERROR: interprate: PluginV2Layer must be V2Ext or V2IOExt or V2DynamicExt when there is no implicit batch dimension.
[TensorRT] ERROR: Layer interprate failed validation
[TensorRT] ERROR: Network validation failed.
解决方案
参考:https://forums.developer.nvidia.com/t/add-plugins-to-network-in-c-api-with-explicit-batch-dimension-in-tensorrt-7/110076/3
Hi,You would need to update the plugin.
The plugin that we ship is derived from IPluginV2, however, the OSS plugin is IPluginV2Ext, so you use TRT OSS plugin code instead.Thanks
应该是我的插件类继承自IPluginV2
类的问题。后面再看怎么解决。
2. 验证
…
reference
- https://www.fatalerrors.org/a/0dpw0Do.html
- https://oldpan.me/archives/tensorrt-plugin-one-post-get-it
这篇关于【tensorrt】——PluginV2Layer must be V2Ext or V2IOExt or V2DynamicExt when there is no implicit batch d的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!