Skip to content

Commit

Permalink
Use protocol for dlpack instead of deprecated function (#18134)
Browse files Browse the repository at this point in the history
This PR adapts cudf's dlpack tests for compatibility with cupy 13.4,
which was just released yesterday on PyPI and containers
cupy/cupy#8722 that breaks the legacy toDlpack
functionality.
  • Loading branch information
vyasr authored Mar 1, 2025
1 parent 1fe744f commit 09ebf31
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/df_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def __dlpack__(self):
# DLPack not implemented in NumPy yet, so leave it out here.
try:
cuda_array = as_cuda_array(self._buf).view(self._dtype)
return cp.asarray(cuda_array).toDlpack()
return cp.asarray(cuda_array).__dlpack__()
except ValueError:
raise TypeError(f"dtype {self._dtype} unsupported by `dlpack`")

Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/subword_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def _cast_to_appropriate_type(ar, cast_type):
elif cast_type == "tf":
from tensorflow.experimental.dlpack import from_dlpack

return from_dlpack(ar.astype("int32").toDlpack())
return from_dlpack(ar.astype("int32").__dlpack__())

Check warning on line 22 in python/cudf/cudf/core/subword_tokenizer.py

View check run for this annotation

Codecov / codecov/patch

python/cudf/cudf/core/subword_tokenizer.py#L22

Added line #L22 was not covered by tests


class SubwordTokenizer:
Expand Down
6 changes: 3 additions & 3 deletions python/cudf/cudf/tests/test_dlpack.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019-2024, NVIDIA CORPORATION.
# Copyright (c) 2019-2025, NVIDIA CORPORATION.

import itertools
from contextlib import ExitStack as does_not_raise
Expand Down Expand Up @@ -140,7 +140,7 @@ def test_to_dlpack_cupy_2d(data_2d):
def test_from_dlpack_cupy_1d(data_1d):
cupy_array = cupy.array(data_1d)
cupy_host_array = cupy_array.get()
dlt = cupy_array.toDlpack()
dlt = cupy_array.__dlpack__()

gs = cudf.from_dlpack(dlt)
cudf_host_array = gs.to_numpy(na_value=np.nan)
Expand All @@ -151,7 +151,7 @@ def test_from_dlpack_cupy_1d(data_1d):
def test_from_dlpack_cupy_2d(data_2d):
cupy_array = cupy.array(data_2d, order="F")
cupy_host_array = cupy_array.get().flatten()
dlt = cupy_array.toDlpack()
dlt = cupy_array.__dlpack__()

gdf = cudf.from_dlpack(dlt)
cudf_host_array = np.array(gdf.to_pandas()).flatten()
Expand Down

0 comments on commit 09ebf31

Please sign in to comment.