You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The torch.cuda.mem_get_info() function was added two years ago (May 26th, 2021). We have already relied on torch.cuda.is_bf16_supported() without a torch version check in the next method below. The torch.cuda.is_bf16_supported() function was added on August 26th, 2021. So we can assume the torch.cuda.mem_get_info() function is always available for the torch version we support.
As of version 11.0.0, the NVML-wrappers used in pynvml are identical to those published through nvidia-ml-py.
Having pynvml will add an extra dependency. It will also break the users' Python environment if they have nvidia-ml-py installed. Because both pynvml and nvidia-ml-py provide the pynvml module. We can rely on torch.cuda.mem_get_info() where no extra dependency will be added.
Handling the CUDA_VISIBLE_DEVICES environment variable is very complex. The variable can be a comma-separated list of integers or UUID strings. Currently, we only support integers. The torch.cuda.mem_get_info() directly calls the CUDA API which does not need index conversion between CUDA and NVML.
Hi @XuehaiPan - thank you for the contribution. If I recall correctly, we had to use pynvml because we were getting inaccurate memory information from torch in some scenarios. @jeffra may be able to comment more on this.
Either way, I will try out this branch and see if that is still the case. In particular, this code is necessary for FastGen and DeepSpeed-MII.
Hi @XuehaiPan - thank you for the contribution. If I recall correctly, we had to use pynvml because we were getting inaccurate memory information from torch in some scenarios. @jeffra may be able to comment more on this.
Either way, I will try out this branch and see if that is still the case. In particular, this code is necessary for FastGen and DeepSpeed-MII.
If we aren't able to switch over, would it at least make sense to move to the nvidia-ml-py package as it is more regularly updated and at least matches the cuda version?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR refactors the
available_memory()method for the CUDA accelerator to usefree, total = torch.cuda.mem_get_info(). It also removes the hard dependencypynvml.Related PR:
The
torch.cuda.mem_get_info()function was added two years ago (May 26th, 2021). We have already relied ontorch.cuda.is_bf16_supported()without atorchversion check in the next method below. Thetorch.cuda.is_bf16_supported()function was added on August 26th, 2021. So we can assume thetorch.cuda.mem_get_info()function is always available for thetorchversion we support.Rationale
The official NVML Python binding package is
nvidia-ml-pyrather thanpynvmlon PyPI. See the documentation on https://pypi.org/project/pynvml:Having
pynvmlwill add an extra dependency. It will also break the users' Python environment if they havenvidia-ml-pyinstalled. Because bothpynvmlandnvidia-ml-pyprovide thepynvmlmodule. We can rely ontorch.cuda.mem_get_info()where no extra dependency will be added.Handling the
CUDA_VISIBLE_DEVICESenvironment variable is very complex. The variable can be a comma-separated list of integers or UUID strings. Currently, we only support integers. Thetorch.cuda.mem_get_info()directly calls the CUDA API which does not need index conversion between CUDA and NVML.https://github.com/microsoft/DeepSpeed/blob/6d7b44a838548d2e1878439613e1fbc17ddcfaf0/accelerator/cuda_accelerator.py#L156-L169