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

Upgrade Treelite 1.3.0 #3855

Merged
merged 7 commits into from
May 14, 2021
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 conda/environments/cuml_dev_cuda10.1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies:
- faiss-proc=*=cuda
- umap-learn
- scikit-learn=0.23.1
- treelite=1.1.0
- treelite=1.3.0
- pip
- pip:
- sphinx_markdown_tables
Expand Down
2 changes: 1 addition & 1 deletion conda/environments/cuml_dev_cuda10.2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies:
- faiss-proc=*=cuda
- umap-learn
- scikit-learn=0.23.1
- treelite=1.1.0
- treelite=1.3.0
- pip
- pip:
- sphinx_markdown_tables
Expand Down
2 changes: 1 addition & 1 deletion conda/environments/cuml_dev_cuda11.0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies:
- faiss-proc=*=cuda
- umap-learn
- scikit-learn=0.23.1
- treelite=1.1.0
- treelite=1.3.0
- pip
- pip:
- sphinx_markdown_tables
Expand Down
2 changes: 1 addition & 1 deletion conda/environments/cuml_dev_cuda11.2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies:
- faiss-proc=*=cuda
- umap-learn
- scikit-learn=0.23.1
- treelite=1.1.0
- treelite=1.3.0
- pip
- pip:
- sphinx_markdown_tables
Expand Down
4 changes: 2 additions & 2 deletions conda/recipes/cuml/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ requirements:
- setuptools
- cython>=0.29,<0.30
- cmake>=3.14
- treelite=1.1.0
- treelite=1.3.0
- cudf {{ minor_version }}
- libcuml={{ version }}
- libcumlprims {{ minor_version }}
Expand All @@ -42,7 +42,7 @@ requirements:
- libcuml={{ version }}
- libcumlprims {{ minor_version }}
- cupy>=7.8.0,<10.0.0a0
- treelite=1.1.0
- treelite=1.3.0
- nccl>=2.8.4
- ucx-py {{ minor_version }}
- ucx-proc=*=gpu
Expand Down
4 changes: 2 additions & 2 deletions conda/recipes/libcuml/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ requirements:
- ucx-proc=*=gpu
- libcumlprims {{ minor_version }}
- lapack
- treelite=1.1.0
- treelite=1.3.0
- faiss-proc=*=cuda
- gtest=1.10.0
- conda-forge::libfaiss=1.7.0
Expand All @@ -56,7 +56,7 @@ requirements:
- ucx-py {{ minor_version }}
- ucx-proc=*=gpu
- {{ pin_compatible('cudatoolkit', max_pin='x.x') }}
- treelite=1.1.0
- treelite=1.3.0
- faiss-proc=*=cuda
- conda-forge::libfaiss=1.7.0

Expand Down
4 changes: 2 additions & 2 deletions cpp/cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ else(DEFINED ENV{RAFT_PATH})

ExternalProject_Add(raft
GIT_REPOSITORY https://github.com/rapidsai/raft.git
GIT_TAG 37faba16f263b6556583208517d4237d9041bfc0
GIT_TAG c5030a0f9cc7f95ce4208febc89b77ccf251b60e
PREFIX ${RAFT_DIR}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
Expand Down Expand Up @@ -172,7 +172,7 @@ endif(BUILD_STATIC_FAISS)
##############################################################################
# - treelite build -----------------------------------------------------------

find_package(Treelite 1.0.0 REQUIRED)
find_package(Treelite 1.3.0 EXACT REQUIRED)

##############################################################################
# - googletest build -----------------------------------------------------------
Expand Down
15 changes: 15 additions & 0 deletions python/cuml/fil/fil.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ cdef extern from "treelite/c_api.h":
cdef int TreeliteQueryNumClass(ModelHandle handle, size_t* out) except +
cdef int TreeliteLoadLightGBMModel(const char* filename,
ModelHandle* out) except +
cdef int TreeliteSerializeModel(const char* filename,
ModelHandle handle) except +
cdef const char* TreeliteGetLastError()


Expand Down Expand Up @@ -148,6 +150,19 @@ cdef class TreeliteModel():
model.set_handle(handle)
return model

def to_treelite_checkpoint(self, filename):
"""
Serialize to a Treelite binary checkpoint

Parameters
----------
filename : string
Path to Treelite binary checkpoint
"""
assert self.handle != NULL
filename_bytes = filename.encode("UTF-8")
TreeliteSerializeModel(filename_bytes, self.handle)

@staticmethod
def from_treelite_model_handle(treelite_handle,
take_handle_ownership=False):
Expand Down
51 changes: 50 additions & 1 deletion python/cuml/test/test_random_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import random
import json
import io
import os
from contextlib import redirect_stdout

from numba import cuda
Expand All @@ -35,9 +36,12 @@
from sklearn.ensemble import RandomForestRegressor as skrfr
from sklearn.metrics import accuracy_score, mean_squared_error
from sklearn.datasets import fetch_california_housing, \
make_classification, make_regression
make_classification, make_regression, load_iris, load_breast_cancer, \
load_boston
from sklearn.model_selection import train_test_split

import treelite


@pytest.fixture(
scope="session",
Expand Down Expand Up @@ -1029,3 +1033,48 @@ def test_rf_regression_with_identical_labels(split_criterion,
if use_experimental_backend:
expected_dump['instance_count'] = 5
assert model_dump[0] == expected_dump


def test_rf_regressor_gtil_integration(tmpdir):
X, y = load_boston(return_X_y=True)
X, y = X.astype(np.float32), y.astype(np.float32)
clf = curfr(max_depth=3, random_state=0, n_estimators=10)
clf.fit(X, y)
expected_pred = clf.predict(X)

checkpoint_path = os.path.join(tmpdir, 'checkpoint.tl')
clf.convert_to_treelite_model().to_treelite_checkpoint(checkpoint_path)

tl_model = treelite.Model.deserialize(checkpoint_path)
out_pred = treelite.gtil.predict(tl_model, X)
np.testing.assert_almost_equal(out_pred, expected_pred, decimal=5)


def test_rf_binary_classifier_gtil_integration(tmpdir):
X, y = load_breast_cancer(return_X_y=True)
X, y = X.astype(np.float32), y.astype(np.int32)
clf = curfc(max_depth=3, random_state=0, n_estimators=10)
clf.fit(X, y)
expected_prob = clf.predict_proba(X)[:, 1]

checkpoint_path = os.path.join(tmpdir, 'checkpoint.tl')
clf.convert_to_treelite_model().to_treelite_checkpoint(checkpoint_path)

tl_model = treelite.Model.deserialize(checkpoint_path)
Comment on lines +1061 to +1063
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Add a convenience method to directly convert an RF object into a Treelite Model object.

out_prob = treelite.gtil.predict(tl_model, X)
np.testing.assert_almost_equal(out_prob, expected_prob, decimal=5)


def test_rf_multiclass_classifier_gtil_integration(tmpdir):
X, y = load_iris(return_X_y=True)
X, y = X.astype(np.float32), y.astype(np.int32)
clf = curfc(max_depth=3, random_state=0, n_estimators=10)
clf.fit(X, y)
expected_prob = clf.predict_proba(X)

checkpoint_path = os.path.join(tmpdir, 'checkpoint.tl')
clf.convert_to_treelite_model().to_treelite_checkpoint(checkpoint_path)

tl_model = treelite.Model.deserialize(checkpoint_path)
out_prob = treelite.gtil.predict(tl_model, X, pred_margin=True)
np.testing.assert_almost_equal(out_prob, expected_prob, decimal=5)