Skip to content

Add optimize() method for automatic layout and chunk_size tuning#30

Merged
rapids-bot[bot] merged 7 commits intorapidsai:mainfrom
dantegd:fea-optimize
Jan 15, 2026
Merged

Add optimize() method for automatic layout and chunk_size tuning#30
rapids-bot[bot] merged 7 commits intorapidsai:mainfrom
dantegd:fea-optimize

Conversation

@dantegd
Copy link
Copy Markdown
Member

@dantegd dantegd commented Jan 14, 2026

PR ports the optimize() method from cuML FIL to cuforest, enabling automatic tuning of layout and chunk_size parameters for optimal inference performance.

Changes

  • Mutable layout support: Models can now change layout after construction, triggering automatic model reload
  • optimize() method: Searches over layout (depth_first, breadth_first, layered) and chunk_size (powers of 2) combinations to find optimal configuration for a given batch size
  • Settable default_chunk_size: Allows setting the default chunk size used when none is specified in predict calls

Files Modified

File Changes
detail/forest_inference.pyx Store treelite bytes for reload, add layout setter with _reload_model()
_forest_inference.py Add OptimizeMixin class with optimize() method
_base.py Add abstract signatures for optimize(), layout setter, default_chunk_size
tests/test_optimize.py New test file with 7 tests for optimize functionality

Usage

import cuforest

fm = cuforest.load_model("model.ubj", device="gpu")

# Auto-tune for a specific batch size
fm.optimize(data=X, timeout=0.5)

# Or manually set layout/chunk_size
fm.layout = "breadth_first"
fm.default_chunk_size = 16

@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented Jan 14, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@dantegd dantegd added feature request New feature or request non-breaking Introduces a non-breaking change labels Jan 15, 2026
@hcho3 hcho3 marked this pull request as ready for review January 15, 2026 04:57
@hcho3 hcho3 requested a review from a team as a code owner January 15, 2026 04:57
@hcho3
Copy link
Copy Markdown
Contributor

hcho3 commented Jan 15, 2026

/ok to test 9ec0856

@hcho3
Copy link
Copy Markdown
Contributor

hcho3 commented Jan 15, 2026

/merge

@rapids-bot rapids-bot Bot merged commit 503b18e into rapidsai:main Jan 15, 2026
71 checks passed
@hcho3 hcho3 deleted the fea-optimize branch January 15, 2026 05:52
Copy link
Copy Markdown
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.

Post-merge review; I have one high-level concern.

Comment on lines 318 to 319
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should revise the model where we optimize an instance "in-place" that necessitates some of the complexity here for "reloading" a model. We should instead consider whether we simply produce a new "optimized" instance.

Copy link
Copy Markdown
Member Author

@dantegd dantegd Jan 15, 2026

Choose a reason for hiding this comment

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

Good point. The in-place mutation with hidden model reload on layout change is surprising behavior. I ca revise to have optimize() return a new instance with optimal settings instead:

fm_opt = fm.optimize(data=X) 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Cython / Python feature request New feature or request non-breaking Introduces a non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants