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

Fixes detection of CuPy installed with pre-built wheels #1965

Merged
merged 1 commit into from
Sep 16, 2024

Conversation

tcsavage
Copy link
Contributor

What does this PR do?

This PR fixes discovery of CuPy when it's installed using one of the distributions of pre-built wheels.

The CuPy library ships both a source distribution (cupy) as well as versions containing pre-built wheels (cupy-cuda11x, cupy-cuda12x, cupy-rocm-5-0, cupy-rocm-4-3). Use of _is_package_available to detect CuPy only works for the source distribution of CuPy and fails when using the pre-built wheels versions.

This is because the _is_package_available will always attempt to resolve version information (even if it's not required) and in doing so assumes that the importable package name matches the installed distribution name. While this is usually the case, it doesn't work for CuPy and several other libraries. ONNX Runtime for example might be installed as onnxruntime or onnxruntime-gpu and thus Optimum just uses importlib.util.find_spec to work around the same problem. This commit replicates the same solution for CuPy.

Fixes #1925

Who can review?

@fxmarty, @echarlaix, @JingyaHuang, @michaelbenayoun

The CuPy library ships both a source distribution (`cupy`) as well as versions containing pre-built wheels (`cupy-cuda11x`, `cupy-cuda12x`, `cupy-rocm-5-0`, `cupy-rocm-4-3`). Use of `_is_package_available` to detect CuPy only works for the source distribution of CuPy and fails when using the pre-built wheels versions.

This is because the `_is_package_available` will always attempt to resolve version information (even if it's not required) and in doing so assumes that the _importable_ package name matches the _installed_ distribution name. While this is usually the case, it doesn't work for CuPy and several other libraries. ONNX Runtime for example might be installed as `onnxruntime` or `onnxruntime-gpu` and thus Optimum just uses `importlib.util.find_spec` to work around the same problem. This commit replicates the same solution for CuPy.
@IlyasMoutawwakil
Copy link
Member

Thank you for the fix !

@IlyasMoutawwakil IlyasMoutawwakil merged commit f1b708c into huggingface:main Sep 16, 2024
@tcsavage tcsavage deleted the fix-cupy-detection branch September 16, 2024 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

is_cupy_available() can't find CuPy wheel distributions
2 participants