This is an automated email from the ASF dual-hosted git repository.
tlopex pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new a104a7b0a2 [Fix][Relax] Return frontend tensor dtype value (#20051)
a104a7b0a2 is described below
commit a104a7b0a299103d1e910debcbe63aeafcea045f
Author: Akaash Parthasarathy <[email protected]>
AuthorDate: Mon Jul 27 12:41:19 2026 -0700
[Fix][Relax] Return frontend tensor dtype value (#20051)
Following the recent PrimType refactor, `nn.Tensor.dtype` returns a
`PrimType` object instead of the documented string dtype value. This
breaks consumers such as NumPy's astype. This PR returns the underlying
dtype value and adds an assertion verifying that `Tensor.dtype` remains
string-compatible.
---
python/tvm/relax/frontend/nn/core.py | 2 +-
tests/python/relax/test_frontend_nn_tensor.py | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/python/tvm/relax/frontend/nn/core.py
b/python/tvm/relax/frontend/nn/core.py
index 3e4a315aee..e93152403f 100644
--- a/python/tvm/relax/frontend/nn/core.py
+++ b/python/tvm/relax/frontend/nn/core.py
@@ -226,7 +226,7 @@ class Tensor(_TensorOp):
dtype : str
The data type of the tensor
"""
- return self._expr.ty.dtype
+ return self._expr.ty.dtype.dtype
def __repr__(self) -> str:
return f'Tensor({self.shape}, "{self.dtype}")'
diff --git a/tests/python/relax/test_frontend_nn_tensor.py
b/tests/python/relax/test_frontend_nn_tensor.py
index 2a0866e7f5..505f130dd7 100644
--- a/tests/python/relax/test_frontend_nn_tensor.py
+++ b/tests/python/relax/test_frontend_nn_tensor.py
@@ -30,6 +30,7 @@ def test_tensor_from_numpy():
tensor_x = Tensor.from_const(x)
assert tensor_x.shape == [1, 10]
assert tensor_x.ndim == 2
+ assert isinstance(tensor_x.dtype, str)
assert tensor_x.dtype == "float32"
assert repr(tensor_x) == 'Tensor([1, 10], "float32")'