Exemple #1
0
def test_logistic_regression():
    with cupy_using_allocator(dummy_allocator):
        X_train, X_test, y_train, y_test = \
            small_classification_dataset(np.float32)
        y_train = y_train.astype(np.float32)
        y_test = y_test.astype(np.float32)
        culog = LogisticRegression()
        culog.fit(X_train, y_train)
        culog.predict(X_train)
Exemple #2
0
def rmm_cupy_ary(cupy_fn, *args, **kwargs):
    """

    Function to call CuPy functions with RMM memory management


    Parameters
    ----------
    cupy_fn : cupy function,
        CuPy function to execute, for example cp.array

    *args :
        Non keyword arguments to pass to the CuPy function

    **kwargs :
        Keyword named arguments to pass to the CuPy function


    Note: this function should be used if the result of cupy_fn creates
    a new array. Functions to create a new CuPy array by reference to
    existing device array (through __cuda_array_interface__) can be used
    directly.

    Examples
    ---------

    .. code-block:: python

        from cuml.common import rmm_cupy_ary
        import cupy as cp

        # Get a new array filled with 0, column major
        a = rmm_cupy_ary(cp.zeros, 5, order='F')


    """

    # using_allocator was introduced in CuPy 7. Once 7+ is required,
    # this check can be removed alongside the else code path.
    if check_min_cupy_version("7.0"):
        with cupy_using_allocator(rmm.rmm_cupy_allocator):
            result = cupy_fn(*args, **kwargs)

    else:
        temp_res = cupy_fn(*args, **kwargs)
        result = \
            _rmm_cupy6_array_like(temp_res,
                                  order=_strides_to_order(temp_res.strides,
                                                          temp_res.dtype))
        cp.copyto(result, temp_res)

    return result
Exemple #3
0
def test_naive_bayes(nlp_20news):
    X, y = nlp_20news

    X = sparse_scipy_to_cp(X, cp.float32).astype(cp.float32)
    y = y.astype(cp.int32)

    with cupy_using_allocator(dummy_allocator):
        model = MultinomialNB()
        model.fit(X, y)

        y_hat = model.predict(X)
        y_hat = model.predict(X)
        y_hat = model.predict_proba(X)
        y_hat = model.predict_log_proba(X)
        y_hat = model.score(X, y)

        del y_hat
Exemple #4
0
    def __init__(self):
        super().__init__()

        def cleanup():
            cuml.global_settings.root_cm = None

        self.callback(cleanup)

        self.enter_context(cupy_using_allocator(rmm.rmm_cupy_allocator))
        self.prev_output_type = self.enter_context(_using_mirror_output_type())

        self._output_type = None
        self.output_dtype = None

        # Set the output type to the prev_output_type. If "input", set to None
        # to allow inner functions to specify the input
        self.output_type = (None if self.prev_output_type == "input" else
                            self.prev_output_type)

        self._count = 0

        self.call_stack = {}

        cuml.global_settings.root_cm = self
Exemple #5
0
def test_dummy_allocator():
    with pytest.raises(AssertionError):
        with cupy_using_allocator(dummy_allocator):
            a = cp.arange(10)
            del a
Exemple #6
0
 def cupy_rmm_wrapper(*args, **kwargs):
     with cupy_using_allocator(rmm.rmm_cupy_allocator):
         return func(*args, **kwargs)