From 6f09b0ebd152f3bb0e195fa714dbdaa92e560b4c Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Wed, 24 May 2023 13:22:00 +0800 Subject: [PATCH] chore(trace): add more error message for tensor invalid GitOrigin-RevId: 762334218bb7e52c4be4c8eb66319df6679c4b27 --- imperative/python/src/tensor.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/imperative/python/src/tensor.cpp b/imperative/python/src/tensor.cpp index a93dc43d7..887dbd134 100644 --- a/imperative/python/src/tensor.cpp +++ b/imperative/python/src/tensor.cpp @@ -672,7 +672,17 @@ PyObject* TensorWrapper::format() { PyObject* TensorWrapper::numpy() { auto hv = m_tensor->numpy(); if (!hv) { - PyErr_SetString(PyExc_ValueError, "tensor invalid"); + if (TransformationManager::get_instance() + .segments[TransformationManager::Segment::Eval] + .size() > 1) { + PyErr_SetString( + PyExc_ValueError, + "tensor invalid, can not infer value of this tensor under " + "trace(symbolic=True). You can try to use trace(symbolic=False) to " + "avoid this issue."); + } else { + PyErr_SetString(PyExc_ValueError, "tensor invalid"); + } return nullptr; } auto arr = py::reinterpret_steal( -- GitLab