From 87ce94f7fbcab8b9948d1cb44492ebc884bc1089 Mon Sep 17 00:00:00 2001 From: liufengwei0103 <2472937968@qq.com> Date: Thu, 19 Aug 2021 05:31:14 +0800 Subject: [PATCH] Fix bug scalar (#5950) * fix bug scalar * add test Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com> --- python/oneflow/framework/tensor_str.py | 2 +- python/oneflow/test/modules/test_tensor_str.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/python/oneflow/framework/tensor_str.py b/python/oneflow/framework/tensor_str.py index 764f61b2be..6ea41fb4dc 100644 --- a/python/oneflow/framework/tensor_str.py +++ b/python/oneflow/framework/tensor_str.py @@ -133,7 +133,7 @@ class _Formatter(object): def _scalar_str(self, formatter1): - return formatter1.format(self.tolist()) + return formatter1.format(_try_convert_to_local_tensor(self).tolist()) def _vector_str(self, indent, summarize, formatter1): diff --git a/python/oneflow/test/modules/test_tensor_str.py b/python/oneflow/test/modules/test_tensor_str.py index bed4fa52ad..5c88acb2f2 100644 --- a/python/oneflow/test/modules/test_tensor_str.py +++ b/python/oneflow/test/modules/test_tensor_str.py @@ -109,6 +109,7 @@ def _test_consistent_tensor_str(test_case, device): x = flow.ones((10, 10), placement=placement, sbp=[flow.sbp.partial_sum]) tensor_str = str(x) test_case.assertTrue("1." in tensor_str) + test_case.assertTrue("1." in str(x[0][0])) # summarized consistent tensor x = flow.ones((100, 100), placement=placement, sbp=[flow.sbp.split(0)]) -- GitLab