Skip to content

Fix torch-incompatible assertions in TestViewCudaArrayInterfaceGPU#1999

Open
leofang wants to merge 4 commits intoNVIDIA:mainfrom
leofang:fix-test-utils-arr-size
Open

Fix torch-incompatible assertions in TestViewCudaArrayInterfaceGPU#1999
leofang wants to merge 4 commits intoNVIDIA:mainfrom
leofang:fix-test-utils-arr-size

Conversation

@leofang
Copy link
Copy Markdown
Member

@leofang leofang commented Apr 30, 2026

The _check_view method in TestViewCudaArrayInterfaceGPU was missed during the tensor bridge refactor (#1894) and still used raw numpy attributes that don't work with torch.Tensor:

  • in_arr.size — torch's .size is a method (returns shape), not a property (returns element count)
  • in_arr.strides / in_arr.dtype.itemsize — torch tensors don't have numpy-style .strides
  • in_arr.flags["C_CONTIGUOUS"] — torch tensors don't have .flags
  • gpu_array_ptr(in_arr) — didn't handle torch tensors

Replaced with the _arr_* helpers that #1894 added for torch/numpy compatibility: _arr_ptr, _arr_size, _arr_strides_in_counts, _arr_is_c_contiguous.

Also unified the strides assertion pattern across all three _check_view methods to use the same if/else with in (None, strides_in_counts) for C-contiguous arrays (torch's __cuda_array_interface__ always reports strides, even for C-contiguous tensors).

Verified locally: 66/66 tests pass across TestViewCPU, TestViewGPU, and TestViewCudaArrayInterfaceGPU (including all torch variants).

Caught by the nightly optional-dependency CI (#1987).

-- Leo's bot

The _check_view method in TestViewCudaArrayInterfaceGPU was missed
during the tensor bridge refactor (NVIDIA#1894) and still used raw numpy
attributes (in_arr.size, in_arr.strides, in_arr.flags, etc.) that
don't work with torch tensors. Use the _arr_* helpers that NVIDIA#1894
added for torch/numpy compatibility.

Caught by the nightly optional-dependency CI (NVIDIA#1987).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@copy-pr-bot
Copy link
Copy Markdown
Contributor

copy-pr-bot Bot commented Apr 30, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the cuda.core Everything related to the cuda.core module label Apr 30, 2026
@leofang leofang self-assigned this May 1, 2026
@leofang leofang added bug Something isn't working P0 High priority - Must do! test Improvements or additions to tests labels May 1, 2026
@leofang leofang added this to the cuda.core v1.0.0 milestone May 1, 2026
@leofang
Copy link
Copy Markdown
Member Author

leofang commented May 1, 2026

/ok to test 24fc3aa

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

leofang and others added 3 commits May 1, 2026 02:28
torch's __cuda_array_interface__ always reports strides, even for
C-contiguous tensors. Use the same assertion pattern as the other
_check_view methods: allow strides to equal the C-contiguous values
instead of requiring None.

Verified locally: 7/7 torch CAI tests pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use the same if/else pattern with `in (None, strides_in_counts)` in
all three _check_view methods for consistency. Previously TestViewCPU
and TestViewCudaArrayInterfaceGPU used a one-liner that was harder
to read and behaved slightly differently.

Verified locally: 66/66 tests pass across TestViewCPU, TestViewGPU,
and TestViewCudaArrayInterfaceGPU (including all torch variants).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@leofang
Copy link
Copy Markdown
Member Author

leofang commented May 1, 2026

/ok to test dacfec9

@leofang leofang marked this pull request as ready for review May 1, 2026 03:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cuda.core Everything related to the cuda.core module P0 High priority - Must do! test Improvements or additions to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant