You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "tqchen (via GitHub)" <gi...@apache.org> on 2026/06/05 17:00:58 UTC
[PR] [FIX] Drop test_empty_tensor_attributes (numpy dlpack stride change) [tvm-ffi]
tqchen opened a new pull request, #607:
URL: https://github.com/apache/tvm-ffi/pull/607
[FIX] Drop test_empty_tensor_attributes (numpy dlpack stride change for empty arrays)
NumPy silently changed how it exports strides for zero-element arrays via
`__dlpack__`. For a shape `(4, 0, 4)` array NumPy previously reported
strides `(0, 4, 1)`, but now reports `(0, 0, 0)`. Either choice is
arguably valid — any stride values are consistent when the array has zero
elements — but `tvm_ffi.from_dlpack` faithfully forwards whatever the
upstream exporter provides. The test was asserting a NumPy-side
implementation detail that has since changed, so it is removed rather than
patched. Deciding what the correct empty-array stride convention should be
is a separate question not in scope for this fix.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [FIX] Drop test_empty_tensor_attributes (numpy dlpack stride change) [tvm-ffi]
Posted by "kainzhong (via GitHub)" <gi...@apache.org>.
kainzhong commented on PR #607:
URL: https://github.com/apache/tvm-ffi/pull/607#issuecomment-4634436950
Ah sorry I didn't notice I was using numpy with a outdated version when I run my tests locally. I just updated it and now I see it returns strides with all zeros.
Though I wonder for shape (4, 0, 4) if numpy reports strides (0, 0, 0) then my current implementation will say `is_contiguous()=False` since the expected stride (0, 4, 1) doesn't match (0, 0, 0) from numpy, which differs from numpy and pytorch since they would see an empty tensor as contiguous, but this implementation matches the C++ implementation in `include/tvm/ffi/container/tensor.h`. Do we need to also fix both of them by return True early when `numel()=0`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [FIX] Drop test_empty_tensor_attributes (numpy dlpack stride change) [tvm-ffi]
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on code in PR #607:
URL: https://github.com/apache/tvm-ffi/pull/607#discussion_r3375467278
##########
docs/reference/python/index.rst:
##########
@@ -48,10 +48,6 @@ Tensor
Device
DLDeviceType
device
- ndim
- numel
- size
- is_contiguous
Review Comment:
previously there was a dup warning in sphinx, let me cross check
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [FIX] Drop test_empty_tensor_attributes (numpy dlpack stride change) [tvm-ffi]
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on PR #607:
URL: https://github.com/apache/tvm-ffi/pull/607#issuecomment-4636652127
@kainzhong seems we should match the pytorch behavior for empty strides, i will update in this patch
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [FIX] Drop test_empty_tensor_attributes (numpy dlpack stride change) [tvm-ffi]
Posted by "MasterJH5574 (via GitHub)" <gi...@apache.org>.
MasterJH5574 merged PR #607:
URL: https://github.com/apache/tvm-ffi/pull/607
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [FIX] Drop test_empty_tensor_attributes (numpy dlpack stride change) [tvm-ffi]
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on code in PR #607:
URL: https://github.com/apache/tvm-ffi/pull/607#discussion_r3376139450
##########
docs/reference/python/index.rst:
##########
@@ -48,10 +48,6 @@ Tensor
Device
DLDeviceType
device
- ndim
- numel
- size
- is_contiguous
Review Comment:
This is doc page for the root index, and we only need Tensor, the functions are part of Tensor methods and will appear in Tensor page
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [FIX] Drop test_empty_tensor_attributes (numpy dlpack stride change) [tvm-ffi]
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on code in PR #607:
URL: https://github.com/apache/tvm-ffi/pull/607#discussion_r3375467278
##########
docs/reference/python/index.rst:
##########
@@ -48,10 +48,6 @@ Tensor
Device
DLDeviceType
device
- ndim
- numel
- size
- is_contiguous
Review Comment:
i believe there was a doc dup in the core tensor causing warning in sphinx
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [FIX] Drop test_empty_tensor_attributes (numpy dlpack stride change) [tvm-ffi]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #607:
URL: https://github.com/apache/tvm-ffi/pull/607#discussion_r3364155976
##########
tests/python/test_tensor.py:
##########
@@ -52,19 +52,6 @@ def test_tensor_attributes() -> None:
np.testing.assert_equal(x2, data)
-def test_empty_tensor_attributes() -> None:
- data: npt.NDArray[Any] = np.zeros((4, 0, 4), dtype="int16")
- if not hasattr(data, "__dlpack__"):
- return
- x = tvm_ffi.from_dlpack(data)
- assert isinstance(x, tvm_ffi.Tensor)
- assert x.shape == (4, 0, 4)
- assert x.ndim == 3
- assert x.strides == (0, 4, 1)
- assert x.numel() == 0
- assert x.is_contiguous()
-
-
def test_non_contiguous_tensor_attributes() -> None:
Review Comment:

Instead of completely removing `test_empty_tensor_attributes`, we should keep it to maintain test coverage for empty tensors (which is an important edge case). We can relax the stride assertion to accept both the old and new NumPy stride conventions (`(0, 4, 1)` and `(0, 0, 0)`).
```suggestion
def test_empty_tensor_attributes() -> None:
data: npt.NDArray[Any] = np.zeros((4, 0, 4), dtype="int16")
if not hasattr(data, "__dlpack__"):
return
x = tvm_ffi.from_dlpack(data)
assert isinstance(x, tvm_ffi.Tensor)
assert x.shape == (4, 0, 4)
assert x.ndim == 3
assert x.strides in ((0, 4, 1), (0, 0, 0))
assert x.numel() == 0
assert x.is_contiguous()
def test_non_contiguous_tensor_attributes() -> None:
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [FIX] Drop test_empty_tensor_attributes (numpy dlpack stride change) [tvm-ffi]
Posted by "junrushao (via GitHub)" <gi...@apache.org>.
junrushao commented on code in PR #607:
URL: https://github.com/apache/tvm-ffi/pull/607#discussion_r3368203058
##########
docs/reference/python/index.rst:
##########
@@ -48,10 +48,6 @@ Tensor
Device
DLDeviceType
device
- ndim
- numel
- size
- is_contiguous
Review Comment:
Why do we want to drop documentation of those 4 fields?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org