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

Implement apply() in FIL #5358

Merged
merged 29 commits into from
May 26, 2023
Merged

Conversation

hcho3
Copy link
Contributor

@hcho3 hcho3 commented Apr 12, 2023

Replaces #5307

Depends on #5365

@hcho3 hcho3 requested review from a team as code owners April 12, 2023 17:54
@github-actions github-actions bot added CUDA/C++ Cython / Python Cython or Python issue labels Apr 12, 2023
@hcho3 hcho3 mentioned this pull request Apr 12, 2023
@hcho3 hcho3 added non-breaking Non-breaking change improvement Improvement / enhancement to an existing function labels Apr 12, 2023
Copy link
Contributor

@csadorf csadorf left a comment

Choose a reason for hiding this comment

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

Only reviewed the P/Cython code: added a few suggestions, but overall LGTM.

Comment on lines +823 to +825
fm = ForestInference.load(
model_path, output_class=True, model_type="xgboost"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it matter in which using_device_type context this is instantiated? If not, should we maybe test expected behavior if this is done wrongly?

Copy link
Contributor

Choose a reason for hiding this comment

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

It should not matter, and yes, we should definitely test that.

model_path, output_class=True, model_type="xgboost"
)

with using_device_type(infer_device):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to ensure/test that the inference is actually performed on the correct device?


with using_device_type(infer_device):
pred_leaf = fm.apply(X).astype(np.int32)
expected_pred_leaf = bst.predict(xgb.DMatrix(X), pred_leaf=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless this is affected by using_device_type(), I'd suggest to move it outside of the context. That goes for all other code where the same principle applies.

classification=True,
)

model_path = os.path.join(tmp_path, "xgb_class.model")
Copy link
Contributor

Choose a reason for hiding this comment

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

The tmp_path fixture should be a pathlib.Path object, so this should be equivalent:

Suggested change
model_path = os.path.join(tmp_path, "xgb_class.model")
model_path = tmp_path / "xgb_class.model"

preds
If non-None, outputs will be written in-place to this array.
Therefore, if given, this should be a C-major array of shape
n_rows * n_trees.
Copy link
Contributor

Choose a reason for hiding this comment

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

You use a X symbol in row 1254, maybe use the same here to be consistent?

Suggested change
n_rows * n_trees.
n_rows X n_trees.

Copy link
Contributor

@wphicks wphicks left a comment

Choose a reason for hiding this comment

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

Looking pretty good. After we changed our approach a bit for predict_per_tree, though, I'm wondering if we can't simplify the logic a bit for apply as well.

Copy link
Contributor

@wphicks wphicks left a comment

Choose a reason for hiding this comment

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

This is a really nice refactor of the previous implementation! I think we can simplify the logic for output indexing just a little further, but otherwise (assuming perf testing shakes out), this looks perfect.

categorical_data,
infer_type);
if (infer_type == infer_kind::leaf_id) {
infer_kernel_cpu<has_categorical_nodes, true>(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm only adding predict_leaf template parameter to the CPU kernel. Adding it to the GPU kernel adds too much boilerplate.

@dantegd
Copy link
Member

dantegd commented May 26, 2023

/merge

@rapids-bot rapids-bot bot merged commit 36c1ea9 into rapidsai:branch-23.06 May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CUDA/C++ Cython / Python Cython or Python issue improvement Improvement / enhancement to an existing function non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants