Skip to content

Remove native model from Isolation Forest estimators - #8493

Draft
betatim wants to merge 1 commit into
NVIDIA:mainfrom
betatim:iso-forest-remove-native-model
Draft

Remove native model from Isolation Forest estimators#8493
betatim wants to merge 1 commit into
NVIDIA:mainfrom
betatim:iso-forest-remove-native-model

Conversation

@betatim

@betatim betatim commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

This PR removes the native model (self._model) which currently prevents a fitted model from being pickeld (and used again after unpickling).

IsolationForest is the only forest estimator in cuML that keeps a native C++ model alive in Python. fit allocates an IsolationForestModel<T> and stores it on the estimator as self._model. This means we can currently not pickle an IsolationForest and we need a lot of additional code in isolation_forest.pyx`.

The new design matches what we already do for random forest (c.f. #7249).

predict now returns int64 instead of int32. The old implementation wrote into an int32 device buffer because that is what the C++ signature took. The new one is cp.where(scores < offset_, -1, 1), which yields int64. This matches
sklearn.ensemble.IsolationForest.predict.

fit_treelite needs to hand back c(n) because Python applies the 2^(-E[h(x)] / c(n)) transform. The alternative is to drop the parameter and recompute c(n) in Python from max_samples_. I prefer the fit_treelite way because we don't end up duplicating code.

Match how random forest handles things by using treelite and nvforest
only. There is no need for a native model. This means pickling will work
and less code to maintain.
@betatim betatim added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Aug 19, 2026
@copy-pr-bot

copy-pr-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@betatim

betatim commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 6c6a777

@github-actions github-actions Bot added Cython / Python Cython or Python issue CUDA/C++ labels Aug 19, 2026
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.

2 participants