Skip to content
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
2 changes: 1 addition & 1 deletion ci/run_cuml_singlegpu_accel_pytests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# Copyright (c) 2024-2025, NVIDIA CORPORATION.

# Support invoking run_cuml_singlegpu_pytests.sh outside the script directory
cd "$(dirname "$(realpath "${BASH_SOURCE[0]}")")"/../python/cuml/cuml/tests/experimental/accel
cd "$(dirname "$(realpath "${BASH_SOURCE[0]}")")"/../python/cuml/cuml/tests/accel

python -m pytest -p cuml.accel --cache-clear "$@" .
2 changes: 1 addition & 1 deletion ci/test_python_singlegpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ rapids-logger "pytest cuml single GPU"
--numprocesses=8 \
--dist=worksteal \
--junitxml="${RAPIDS_TESTS_DIR}/junit-cuml-accel.xml" \
--cov-config=../../../../.coveragerc \
--cov-config=../../../.coveragerc \
--cov=cuml \
--cov-report=xml:"${RAPIDS_COVERAGE_DIR}/cuml-accel-coverage.xml"

Expand Down
15 changes: 10 additions & 5 deletions python/cuml/cuml/accel/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2025, NVIDIA CORPORATION.
# Copyright (c) 2024-2025, 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 @@ -14,8 +14,13 @@
# limitations under the License.
#

from cuml.experimental.accel import (
install,
load_ipython_extension,
pytest_load_initial_conftests,
from cuml.accel.core import install
from cuml.accel.magics import load_ipython_extension
from cuml.accel.pytest_plugin import pytest_load_initial_conftests


__all__ = (
"install",
"load_ipython_extension",
"pytest_load_initial_conftests",
)
105 changes: 103 additions & 2 deletions python/cuml/cuml/accel/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2025, NVIDIA CORPORATION.
# Copyright (c) 2024-2025, 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 @@ -14,7 +14,108 @@
# limitations under the License.
#

from cuml.experimental.accel.__main__ import main
import code
import pickle
import runpy
import sys

import click
import joblib

from cuml.internals import logger
from cuml.accel.core import install


@click.command()
@click.option("-m", "module", required=False, help="Module to run")
@click.option(
"--convert-to-sklearn",
type=click.Path(exists=True),
required=False,
help="Path to a pickled accelerated estimator to convert to a sklearn estimator.",
)
@click.option(
"--format",
"format",
type=click.Choice(["pickle", "joblib"], case_sensitive=False),
default="pickle",
help="Format to save the converted sklearn estimator.",
)
@click.option(
"--output",
type=click.Path(writable=True),
default="converted_sklearn_model.pkl",
help="Output path for the converted sklearn estimator file.",
)
@click.option(
"--disable-uvm",
is_flag=True,
default=False,
help="Disable UVM (managed memory) allocations.",
)
@click.option(
"-v",
"--verbose",
count=True,
help="Increase output verbosity (can be used multiple times, e.g. -vv). Default shows warnings only.",
)
@click.argument("args", nargs=-1)
def main(
module, convert_to_sklearn, format, output, disable_uvm, verbose, args
):
default_logger_level_index = list(logger.level_enum).index(
logger.level_enum.warn
)
logger_level_index = max(0, default_logger_level_index - verbose)
logger_level = list(logger.level_enum)[logger_level_index]
logger.set_level(logger_level)
logger.set_pattern("%v")

# Enable acceleration
install(disable_uvm=disable_uvm)

# If the user requested a conversion, handle it and exit
if convert_to_sklearn:

with open(convert_to_sklearn, "rb") as f:
if format == "pickle":
serializer = pickle
elif format == "joblib":
serializer = joblib
accelerated_estimator = serializer.load(f)

sklearn_estimator = accelerated_estimator.as_sklearn()

with open(output, "wb") as f:
serializer.dump(sklearn_estimator, f)

sys.exit()

if module:
(module,) = module
# run the module passing the remaining arguments
# as if it were run with python -m <module> <args>
sys.argv[:] = [module, *args.args] # not thread safe?
runpy.run_module(module, run_name="__main__")
elif len(args) >= 1:
# Remove ourself from argv and continue
sys.argv[:] = args
runpy.run_path(args[0], run_name="__main__")
else:
if sys.stdin.isatty():
banner = f"Python {sys.version} on {sys.platform}"
site_import = not sys.flags.no_site
if site_import:
cprt = 'Type "help", "copyright", "credits" or "license" for more information.'
banner += "\n" + cprt
else:
# Don't show prompts or banners if stdin is not a TTY
sys.ps1 = ""
sys.ps2 = ""
banner = ""

# Launch an interactive interpreter
code.interact(banner=banner, exitmsg="")


if __name__ == "__main__":
Expand Down
15 changes: 15 additions & 0 deletions python/cuml/cuml/accel/_wrappers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# Copyright (c) 2020, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2024, NVIDIA CORPORATION.
# Copyright (c) 2024-2025, 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 @@ -14,7 +14,7 @@
# limitations under the License.
#

from ..estimator_proxy import intercept
from cuml.accel.estimator_proxy import intercept


HDBSCAN = intercept(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
#

from ..estimator_proxy import intercept
from cuml.accel.estimator_proxy import intercept


###############################################################################
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2024, NVIDIA CORPORATION.
# Copyright (c) 2024-2025, 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 @@ -14,7 +14,7 @@
# limitations under the License.
#

from ..estimator_proxy import intercept
from cuml.accel.estimator_proxy import intercept


UMAP = intercept(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2024-2025, NVIDIA CORPORATION.
# Copyright (c) 2025, 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 @@ -14,11 +14,8 @@
# limitations under the License.
#


import importlib

from .magics import load_ipython_extension

from cuda.bindings import runtime
from cuml.internals import logger
from cuml.internals.global_settings import GlobalSettings
Expand All @@ -27,11 +24,9 @@

rmm = gpu_only_import("rmm")

__all__ = ["load_ipython_extension", "install"]


def _install_for_library(library_name):
importlib.import_module(f"._wrappers.{library_name}", __name__)
importlib.import_module(f"cuml.accel._wrappers.{library_name}", __name__)


def _is_concurrent_managed_access_supported():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@
# limitations under the License.
#


import inspect
import sys
import types
from typing import Optional, Tuple, Dict, Any, Type, List

from cuml.internals.mem_type import MemoryType
from cuml.internals import logger
from cuml.internals.global_settings import GlobalSettings
from cuml.internals.safe_imports import gpu_only_import, cpu_only_import
from typing import Optional, Tuple, Dict, Any, Type, List


class ProxyModule:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2024, NVIDIA CORPORATION.
# Copyright (c) 2024-2025, 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 @@ -14,16 +14,8 @@
# limitations under the License.
#

from cuml.accel.core import install

try:
from IPython.core.magic import Magics, cell_magic, magics_class

def load_ipython_extension(ip):
from . import install

install()

except ImportError:

def load_ipython_extension(ip):
pass
def load_ipython_extension(ip):
install()
28 changes: 28 additions & 0 deletions python/cuml/cuml/accel/pytest_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Copyright (c) 2025, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from cuml.accel.core import install


def pytest_load_initial_conftests(early_config, parser, args):
# https://docs.pytest.org/en/7.1.x/reference/\
# reference.html#pytest.hookspec.pytest_load_initial_conftests
try:
install()
except RuntimeError:
raise RuntimeError(
"An existing plugin has already loaded sklearn. Interposing failed."
)
Loading