pytorch/caffe2/onnx/helper.cc
Yinghai Lu 39d50ef4f6 Export complete subgraph io info when calling onnxGetBackendCompatibility (#14827)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/14827

We need to send complete IO info when doing `onnxGetBackendCompatibility` to backend like Glow. Previously we are missing some info because sometimes we generate more than one nodes from one C2 op. This fixes the issue.

Reviewed By: jackm321

Differential Revision: D13352049

fbshipit-source-id: 8d8ac70656a0ac42f3a0ccecad61456a4f3b2435
2018-12-05 23:52:06 -08:00

58 lines
1.4 KiB
C++

#include "caffe2/onnx/helper.h"
#include "caffe2/core/logging.h"
#include "caffe2/core/operator.h"
namespace caffe2 { namespace onnx {
std::string DummyName::NewDummyName() {
while (true) {
const std::string name = c10::str("OC2_DUMMY_", counter_++);
auto ret = used_names_.insert(name);
if (ret.second) {
return name;
}
}
}
void DummyName::Reset(const std::unordered_set<std::string> &used_names) {
used_names_ = used_names;
counter_ = 0;
}
::ONNX_NAMESPACE::TypeProto ExtraTypeProto(
const ::ONNX_NAMESPACE::TensorProto& tensor) {
::ONNX_NAMESPACE::TypeProto t;
auto* tensor_type = t.mutable_tensor_type();
tensor_type->set_elem_type(tensor.data_type());
auto* shape = tensor_type->mutable_shape();
for (const auto d : tensor.dims()) {
shape->add_dim()->set_dim_value(d);
}
return t;
}
NodeProto MakeNode(
const std::string& type,
const std::vector<std::string>& inputs,
const std::vector<std::string>& outputs,
const std::vector<AttributeProto>& attributes,
const std::string& name) {
NodeProto node;
if (!name.empty()) {
node.set_name(name);
}
node.set_op_type(type);
for (const auto& input: inputs) {
node.add_input(input);
}
for (const auto& output: outputs) {
node.add_output(output);
}
for (const auto& attr: attributes) {
node.add_attribute()->CopyFrom(attr);
}
return node;
}
}}