Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust deprecated cupy.sparse usage #5867

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions python/cuml/manifold/simpl_set.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022-2023, NVIDIA CORPORATION.
# Copyright (c) 2022-2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,7 @@ from cuml.internals.safe_imports import cpu_only_import
np = cpu_only_import('numpy')
from cuml.internals.safe_imports import gpu_only_import
cp = gpu_only_import('cupy')
cupyx = gpu_only_import('cupyx')

from cuml.manifold.umap_utils cimport *
from cuml.manifold.umap_utils import GraphHolder, find_ab_params, \
Expand Down Expand Up @@ -350,8 +351,8 @@ def simplicial_set_embedding(

graph = graph.tocoo()
graph.sum_duplicates()
if not isinstance(graph, cp.sparse.coo_matrix):
graph = cp.sparse.coo_matrix(graph)
if not isinstance(graph, cupyx.scipy.sparse.coo_matrix):
graph = cupyx.scipy.sparse.coo_matrix(graph)

handle = Handle()
cdef handle_t* handle_ = <handle_t*><size_t>handle.getHandle()
Expand Down
5 changes: 3 additions & 2 deletions python/cuml/manifold/umap_utils.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2022-2023, NVIDIA CORPORATION.
# Copyright (c) 2022-2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -25,6 +25,7 @@ from cuml.internals.safe_imports import cpu_only_import
np = cpu_only_import('numpy')
from cuml.internals.safe_imports import gpu_only_import
cp = gpu_only_import('cupy')
cupyx = gpu_only_import('cupyx')


cdef class GraphHolder:
Expand Down Expand Up @@ -102,7 +103,7 @@ cdef class GraphHolder:
rows = create_nonowning_cp_array(self.rows(), np.int32)
cols = create_nonowning_cp_array(self.cols(), np.int32)

return cp.sparse.coo_matrix(((vals, (rows, cols))))
return cupyx.scipy.sparse.coo_matrix(((vals, (rows, cols))))

def __dealloc__(self):
self.c_graph.reset(NULL)
Expand Down
5 changes: 3 additions & 2 deletions python/cuml/tests/test_simpl_set.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2022-2023, NVIDIA CORPORATION.
# Copyright (c) 2022-2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,6 +27,7 @@

np = cpu_only_import("numpy")
cp = gpu_only_import("cupy")
cupyx = gpu_only_import("cupyx")


IS_ARM = platform.processor() == "aarch64"
Expand Down Expand Up @@ -111,7 +112,7 @@ def test_fuzzy_simplicial_set(
)[0].tocoo()

cu_fss_graph = cu_fss_graph.todense()
ref_fss_graph = cp.sparse.coo_matrix(ref_fss_graph).todense()
ref_fss_graph = cupyx.scipy.sparse.coo_matrix(ref_fss_graph).todense()
assert correctness_sparse(
ref_fss_graph, cu_fss_graph, atol=0.1, rtol=0.2, threshold=0.95
)
Expand Down
4 changes: 2 additions & 2 deletions python/cuml/tests/test_umap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019-2023, NVIDIA CORPORATION.
# Copyright (c) 2019-2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -667,7 +667,7 @@ def test_fuzzy_simplicial_set(n_rows, n_features, n_neighbors):
ref_fss_graph = model.graph_

cu_fss_graph = cu_fss_graph.todense()
ref_fss_graph = cp.sparse.coo_matrix(ref_fss_graph).todense()
ref_fss_graph = cupyx.scipy.sparse.coo_matrix(ref_fss_graph).todense()
assert correctness_sparse(
ref_fss_graph, cu_fss_graph, atol=0.1, rtol=0.2, threshold=0.95
)
Expand Down
Loading