diff --git a/paddle/fluid/inference/tensorrt/convert/generic_and_custom_plugin_creater.cc b/paddle/fluid/inference/tensorrt/convert/generic_and_custom_plugin_creater.cc index a889fc9fa3147..da64a8fbb6811 100644 --- a/paddle/fluid/inference/tensorrt/convert/generic_and_custom_plugin_creater.cc +++ b/paddle/fluid/inference/tensorrt/convert/generic_and_custom_plugin_creater.cc @@ -70,9 +70,17 @@ class CustomPluginCreater : public OpConverter { std::list> ints_attrs; std::list> floats_attrs; - for (auto &attr_name : op_attrs_names) { + for (auto &attr_name_and_type : op_attrs_names) { + auto attr_name = + attr_name_and_type.substr(0, attr_name_and_type.find_first_of(":")); nvinfer1::PluginField plugindata; - plugindata.name = attr_name.c_str(); + + // NOTE: to avoid string rewrite by iterator, deep copy here + std::vector plugin_attr_name(attr_name.length() + 1, 0); + snprintf( + plugin_attr_name.data(), attr_name.length() + 1, attr_name.c_str()); + plugindata.name = plugin_attr_name.data(); + if (op_desc.GetAttrType(attr_name) == framework::proto::AttrType::INT) { int_attrs.push_back(PADDLE_GET_CONST(int, attrs.at(attr_name))); plugindata.data = &int_attrs.back(); diff --git a/paddle/fluid/inference/tensorrt/convert/test_custom_plugin_creater.cc b/paddle/fluid/inference/tensorrt/convert/test_custom_plugin_creater.cc index eee4d0c12edbe..ba85108aee539 100644 --- a/paddle/fluid/inference/tensorrt/convert/test_custom_plugin_creater.cc +++ b/paddle/fluid/inference/tensorrt/convert/test_custom_plugin_creater.cc @@ -23,13 +23,13 @@ PD_BUILD_OP(custom_op) .Inputs({"Input"}) .Outputs({"Output"}) .Attrs({ - "float_attr", - "int_attr", - "bool_attr", - "string_attr", - "ints_attr", - "floats_attr", - "bools_attr", + "float_attr: float", + "int_attr: int", + "bool_attr: bool", + "string_attr: std::string", + "ints_attr: std::vector", + "floats_attr: std::vector", + "bools_attr: std::vector", }); namespace paddle {