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

add test-time dependency on setuptools #776

Closed
wants to merge 1 commit into from

Conversation

jameslamb
Copy link
Member

Summary

Contributes to #775, follow-up to #773.

Some nightly Python 3.12 tests are failing in this repo, as a result of the following:

  • some tests here rely on GPUtil
  • GPUtil was last updated 5+ years ago, and unconditionally imports distutils (code link)
  • distutils was removed from the Python standard library in Python 3.12

This proposes a temporary fix... adding a test-time dependency on setuptools. import distutils will work in an environment where setuptools is installed.

Benefits of these changes

Fixes nightly tests, without imposing any new requirements of users of cucim.

Notes for Reviewers

At some point, setuptools will likely remove distutils or the parts of it that GPUtil needs, and these tests will break in this way again. I've listed out some alternatives in #775, those should be explored at some point.

How I tested this

On a machine with CUDA 12.2 and V100s, I can reproduce the test failures like this:

docker run \
    --rm \
    --gpus 1 \
    -v $(pwd):/opt/work \
    -w /opt/work \
    -it rapidsai/citestwheel:cuda12.5.1-ubuntu22.04-py3.12 \
    bash

python -m pip install \
    'cucim-cu12[test]==24.10.*,>=0.0.0a0'

python -m pytest \
    --numprocesses=8 \
    --dist=worksteal \
    ./python/cucim/tests/performance/clara

After running pip install setuptools, those tests pass 😁

@jameslamb jameslamb added improvement Improves an existing functionality non-breaking Introduces a non-breaking change labels Sep 6, 2024
@jameslamb jameslamb changed the title WIP: add test-time dependency on setuptools add test-time dependency on setuptools Sep 6, 2024
@jameslamb jameslamb marked this pull request as ready for review September 6, 2024 17:09
@jameslamb jameslamb requested a review from a team as a code owner September 6, 2024 17:09
@@ -301,6 +301,7 @@ dependencies:
- pytest-cov>=2.12.1
- pytest-lazy-fixtures>=1.0.0
- pytest-xdist
- setuptools>=60.0 # provides 'distutils', keeps 'GPUtil' working on Python 3.12+
Copy link
Member Author

Choose a reason for hiding this comment

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

setuptools==60.0.0 is the first release where disutils was vendored. From https://setuptools.pypa.io/en/latest/deprecated/distutils-legacy.html

Since the 60.0.0 release, Setuptools includes a local, vendored copy of distutils (from late copies of CPython) that is enabled by default.

That release is from December 2021 (link), so I'd be surprised if it causes any conflicts.

@bdice
Copy link
Contributor

bdice commented Sep 6, 2024

We may be able to get rid of GPUtil. It's very outdated and we have other ways to get the information it provides.

It is only used in one test:

def test_read_region_cuda_memleak(testimg_tiff_stripe_4096x4096_256_jpeg):

We can replace GPUtil.get_GPUs()[0].memoryUsed with this code from rmm:

import rmm

def get_used_memory():
    free, total = rmm.mr.available_device_memory()
    memory_used = (total - free) / (2 ** 20)
    return memory_used

Or we can use cuda-python: https://nvidia.github.io/cuda-python/module/cudart.html#cuda.cudart.cudaMemGetInfo

import cuda.cudart

def get_used_memory():
    status, free, total = cuda.cudart.cudaMemGetInfo()
    if status != cuda.cudart.cudaError_t.cudaSuccess:
        raise RuntimeError("Failed to get GPU memory info.")
    memory_used = (total - free) / (2 ** 20)
    return memory_used

Neither rmm or cuda-python are test dependencies at present, but I think it would be reasonable to use one of these stable, actively maintained packages instead of GPUtil. I lean towards the cuda-python solution because it's more minimal.

@rapids-bot rapids-bot bot closed this in #777 Sep 6, 2024
@rapids-bot rapids-bot bot closed this in 73e6d93 Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improves an existing functionality non-breaking Introduces a non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants