From 8c8d9652ab85b84f8b1b00cbdc9a9569fdd0f86c Mon Sep 17 00:00:00 2001 From: Jorge Pineda Date: Fri, 31 May 2024 12:06:33 -0700 Subject: [PATCH] Enable operator<< for Half tensor (#3779) Summary: Pull Request resolved: https://github.com/pytorch/executorch/pull/3779 Useful for debugging `Half` i.e. `fp16` models, when we have `EValue`s that are `Half` dtype and we do the following: ``` std::cout << "===== INPUT =====" << std::endl; for (EValue& v : inputs) { std::cout << v << std::endl; } std::cout << "===== OUTPUT =====" << std::endl; for (EValue& v : outputs) { std::cout << v << std::endl; } ``` ## Before ``` ===== INPUT ===== tensor(sizes=[1, 3, 96, 72], []) ===== OUTPUT ===== tensor(sizes=[1, 2, 96, 72], []) ``` ## After ``` ===== INPUT ===== tensor(sizes=[1, 3, 96, 72], [0.279785, 0.271484, 0.364746, ..., 0.150391, 0.836426, 0.019043]) ===== OUTPUT ===== tensor(sizes=[1, 2, 96, 72], [18.2344, -10.0938, 1.35059, ..., -33.6875, 4.07422, -22.5312]) ``` ghstack-source-id: 228461839 Reviewed By: copyrightly Differential Revision: D57977366 fbshipit-source-id: a9ba1c11f75af85dcf7c91b9b06b4ec3333455bc --- extension/evalue_util/print_evalue.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extension/evalue_util/print_evalue.cpp b/extension/evalue_util/print_evalue.cpp index efef4c414f..21180cf5d2 100644 --- a/extension/evalue_util/print_evalue.cpp +++ b/extension/evalue_util/print_evalue.cpp @@ -158,7 +158,7 @@ void print_tensor(std::ostream& os, exec_aten::Tensor tensor) { break; switch (tensor.scalar_type()) { - ET_FORALL_REAL_TYPES_AND(Bool, PRINT_TENSOR_DATA) + ET_FORALL_REAL_TYPES_AND2(Bool, Half, PRINT_TENSOR_DATA) default: os << "[]"; }