Skip to content

Conversation

@jcrist
Copy link
Member

@jcrist jcrist commented Jul 25, 2025

This adds support for enabling cuml.accel by setting the CUML_ACCEL_ENABLED environment variable to 1 or true (case insensitive). This can be useful for enabling acceleration in applications where you cannot invoke the CLI or call cuml.accel.install() programmatically.

@jcrist jcrist self-assigned this Jul 25, 2025
@jcrist jcrist added the improvement Improvement / enhancement to an existing function label Jul 25, 2025
@jcrist jcrist requested review from a team as code owners July 25, 2025 16:26
@jcrist jcrist added non-breaking Non-breaking change cuml-accel Issues related to cuml.accel labels Jul 25, 2025
@github-actions github-actions bot added Cython / Python Cython or Python issue CMake labels Jul 25, 2025
add_subdirectory(cuml/experimental/linear_model)

# Include the pth file in the built wheel
install(FILES "_cuml_accel.pth" DESTINATION ".")
Copy link
Member Author

@jcrist jcrist Jul 25, 2025

Choose a reason for hiding this comment

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

No idea if this is the proper way to do this, but it seems to work for wheels at least.

I haven't checked if _cuml_accel.pth is included in an sdist yet. edit: now checked, this seems to be correct too.

Copy link
Member

@betatim betatim left a comment

Choose a reason for hiding this comment

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

Not sure about the CMakeLists part, I'll let someone else comment on that.

The rest looks fine to me.

For my education: is there an example program/application where you can not use -p or the programmatic way of enabling this?

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.

I don't have immediate concerns with the implementation, but I'd like to have a bit more motivation for this. Specifically, I'm a bit worried that this sets false expectations.

Specifically, enabling via environment variable means that we don't fail if cuml is not installed at all.

@jcrist
Copy link
Member Author

jcrist commented Aug 4, 2025

The primary motivation for this was the follow-up PR (#7047). The mechanism added here is the cleanest and most robust way of supporting that use case. I figured exposing it to a user would be harmless and increase the flexibility of the tool. Environment variables feel even more zero code change since they don't require changing the script/notebook or command used to execute them.

For prior art, the mechanism for cugraph's dispatch layer also requires setting some environment variables (though their mechanism is sufficiently different).

If I added a line in the docs noting your worry would that be sufficient?

@csadorf
Copy link
Contributor

csadorf commented Aug 4, 2025

If I added a line in the docs noting your worry would that be sufficient?

Yes. It should contextualize that this approach – unlike the others – will not fail if cuML is not installed and that it is most suitable when you don't want or cannot change the entrypoint. I think by adding yet another alternative way of enabling zero-code change we need to provide the littlest bit of guidance on when to use which approach.

jcrist added 2 commits August 4, 2025 14:11
This adds support for enabling `cuml.accel` by setting the
`CUML_ACCEL_ENABLED` environment variable to `1` or `true` (case
insensitive). This can be useful for enabling acceleration in
applications where you cannot invoke the CLI or call
`cuml.accel.install()` programmatically.
@jcrist jcrist force-pushed the cuml-accel-environ branch from 398b365 to 10bcb73 Compare August 4, 2025 21:18
@jcrist
Copy link
Member Author

jcrist commented Aug 4, 2025

Done

@jcrist
Copy link
Member Author

jcrist commented Aug 4, 2025

For my education: is there an example program/application where you can not use -p or the programmatic way of enabling this?

-p is for the pytest plugin, I assume you mean -m (for the cuml.accel module CLI).

As mentioned above, the primary motivation for this was propagating cuml.accel to subprocesses, I don't have a specific use case for this being user facing other than it's necessary for solving #7047 and feels harmless to document the existence of. That said, any tool that you can't control the execution of (maybe it's bundled in an existing CLI or hardcodes the executable) can activate the accelerator with an environment variable instead. This added flexibility may be useful for some deployments.

If nothing else, it makes it easier to have a programmatic switch on whether the accelerator is turned on or not in a deployment scenario since you just have to change the value of an environment variable (in e.g. a k8s pod spec) rather than change the executable line.

@jcrist jcrist requested a review from csadorf August 4, 2025 21:29
Copy link
Member

@betatim betatim left a comment

Choose a reason for hiding this comment

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

Thanks for the explanations and adding context/motivation. Still looks good to me

@jcrist
Copy link
Member Author

jcrist commented Aug 5, 2025

/merge

@rapids-bot rapids-bot bot merged commit e07c2bf into rapidsai:branch-25.10 Aug 5, 2025
71 checks passed
@jcrist jcrist deleted the cuml-accel-environ branch August 5, 2025 20:17
rapids-bot bot pushed a commit that referenced this pull request Sep 26, 2025
This makes use of the `CUML_ACCEL_ENABLED` environment variable to ensure if cuml.accel is enabled in a parent process then it's enabled (by default) in a child process. This makes `cuml.accel` usage more transparent with common python multiprocessing solutions (`multiprocessing`/`joblib`/`dask`). Things _just work_.

Currently on top of #7046. Note that this use case was the primary motivation for #7046, though I can see other reasons why an environment variable might be nice too.

Authors:
  - Jim Crist-Harif (https://github.com/jcrist)
  - Simon Adorf (https://github.com/csadorf)

Approvers:
  - Simon Adorf (https://github.com/csadorf)

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

Labels

CMake cuml-accel Issues related to cuml.accel 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.

3 participants