Additional operator information values (#9153)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/9153

Closes https://github.com/pytorch/pytorch/pull/9153

Modified the values reported by the benchmarking platform to include tensor_shape and op_args. These values have a different naming scheme to values like flops and latency.

Reviewed By: sf-wind

Differential Revision: D8729791

fbshipit-source-id: f050200be01c6d0794bf5faaa6e8cef12a00affe
This commit is contained in:
Brad Stocks
2018-07-16 17:25:27 -07:00
committed by Facebook Github Bot
parent 7df48d0444
commit c4bff25282

View File

@ -7,6 +7,8 @@
namespace caffe2 {
const std::string NetObserverReporterPrint::IDENTIFIER = "Caffe2Observer ";
static std::string get_op_args(PerformanceInformation p);
static std::string get_tensor_shapes(PerformanceInformation p);
void NetObserverReporterPrint::report(
NetBase* net,
@ -27,6 +29,9 @@ void NetObserverReporterPrint::report(
{"flops", {{"value", "-1"}, {"unit", "flops"}}}};
} else if (p.first != "NET_DELAY") {
// for operator perf
std::string shape_str = get_tensor_shapes(p.second);
std::string args_str = get_op_args(p.second);
caffe2_perf[p.first] = {
{"latency",
{{"value", caffe2::to_string(p.second.latency * 1000)},
@ -36,7 +41,9 @@ void NetObserverReporterPrint::report(
"value",
caffe2::to_string(p.second.flops),
},
{"unit", "flops"}}}};
{"unit", "flops"}}},
{"tensor_shapes", {{"info_string", shape_str}, {"unit", ""}}},
{"op_args", {{"info_string", args_str}, {"unit", ""}}}};
}
}
@ -67,4 +74,52 @@ void NetObserverReporterPrint::report(
LOG(INFO) << buffer.str();
}
}
static std::string get_tensor_shapes(PerformanceInformation p) {
std::string shape_str;
std::stringstream shape_stream;
if (!p.tensor_shapes.empty()) {
shape_stream << "[";
for (int i = 0; i < p.tensor_shapes.size(); i++) {
shape_stream << "[";
for (int j = 0; j < p.tensor_shapes[i].dims_size(); j++) {
shape_stream << p.tensor_shapes[i].dims(j) << ", ";
}
shape_stream << "], ";
}
shape_stream << "]";
shape_str = shape_stream.str();
} else {
shape_str = "[]";
}
return shape_str;
}
static std::string get_op_args(PerformanceInformation p) {
std::string args_str;
if (!p.args.empty()) {
std::stringstream args;
args << "[";
for (int i = 0; i < p.args.size(); i++) {
args << "{" << p.args[i].name() << ": ";
if (p.args[i].has_i()) {
args << p.args[i].i();
} else if (p.args[i].has_s()) {
args << p.args[i].s();
} else if (p.args[i].has_n()) {
args << &p.args[i].n();
} else if (p.args[i].has_f()) {
args << p.args[i].f();
} else {
args << "None";
}
args << "}, ";
}
args << "]";
args_str = args.str();
} else {
args_str = "[]";
}
return args_str;
}
}