Skip to content

Commit 13bac84

Browse files
dbortfacebook-github-bot
authored andcommitted
Print executor_runner outputs using EValue's new operator<<() (#481)
Summary: Pull Request resolved: #481 D49574853 added a smart `operator<<()` for `EValue`. Instead of assuming that all outputs are fb32 tensors, use the new printer to print each output `EValue`. By default it will only print the first and last three entries in a list, so extend it to print the first and last 100 entries. ghstack-source-id: 201868940 exported-using-ghexport Reviewed By: kirklandsign Differential Revision: D49607604 fbshipit-source-id: a0903bef0b945bf7b5802b6548a0087f7b6e995b
1 parent 6914003 commit 13bac84

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

examples/executor_runner/executor_runner.cpp

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
* all fp32 tensors.
1818
*/
1919

20+
#include <iostream>
2021
#include <memory>
2122

2223
#include <gflags/gflags.h>
2324

2425
#include <executorch/extension/data_loader/file_data_loader.h>
26+
#include <executorch/extension/evalue_util/print_evalue.h>
2527
#include <executorch/runtime/executor/method.h>
2628
#include <executorch/runtime/executor/program.h>
2729
#include <executorch/runtime/platform/log.h>
@@ -169,29 +171,13 @@ int main(int argc, char** argv) {
169171

170172
// Print the outputs.
171173
std::vector<EValue> outputs(method->outputs_size());
174+
ET_LOG(Info, "%zu outputs: ", outputs.size());
172175
status = method->get_outputs(outputs.data(), outputs.size());
173176
ET_CHECK(status == Error::Ok);
174-
for (EValue& output : outputs) {
175-
// TODO(T159700776): This assumes that all outputs are fp32 tensors. Add
176-
// support for other EValues and Tensor dtypes, and print tensors in a more
177-
// readable way.
178-
auto output_tensor = output.toTensor();
179-
auto data_output = output_tensor.const_data_ptr<float>();
180-
181-
ssize_t max_print_element_count = 10000;
182-
if (output_tensor.numel() > max_print_element_count) {
183-
ET_LOG(
184-
Info,
185-
"Output tensor is too large, printing first %ld elements out of %ld",
186-
max_print_element_count,
187-
output_tensor.numel());
188-
} else {
189-
max_print_element_count = output_tensor.numel();
190-
}
191-
192-
for (size_t j = 0; j < max_print_element_count; ++j) {
193-
ET_LOG(Info, "%f", data_output[j]);
194-
}
177+
// Print the first and last 100 elements of long lists of scalars.
178+
std::cout << torch::executor::util::evalue_edge_items(100);
179+
for (int i = 0; i < outputs.size(); ++i) {
180+
std::cout << "Output " << i << ": " << outputs[i] << std::endl;
195181
}
196182

197183
// Dump the profiling data to the specified file.

examples/executor_runner/targets.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def define_common_targets():
1515
deps = [
1616
"//executorch/runtime/executor:program",
1717
"//executorch/extension/data_loader:file_data_loader",
18+
"//executorch/extension/evalue_util:print_evalue",
1819
"//executorch/util:util",
1920
],
2021
external_deps = [

0 commit comments

Comments
 (0)