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

Fix: handle logical CUDA device IDs for GPUStatsMonitor if CUDA_VISIBLE_DEVICES set #8260

Merged
merged 5 commits into from
Jul 19, 2021

Conversation

XuehaiPan
Copy link
Contributor

@XuehaiPan XuehaiPan commented Jul 2, 2021

What does this PR do?

CUDA device IDs may be different from the real GPU IDs if CUDA_VISIBLE_DEVICES set. For example, if I set CUDA_VISIBLE_DEVICES="3,4,5,6", the CUDA device enumeration will be:

  • cuda:0 --> GPU 3
  • cuda:1 --> GPU 4
  • cuda:2 --> GPU 5
  • cuda:3 --> GPU 6

The previous version of GPUStatsMonitor callback will log the wrong devices when users have set a non-trivial CUDA_VISIBLE_DEVICES environment variable.

Before submitting

  • Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

PR review

Anyone in the community is free to review the PR once the tests have passed.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:

  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

Did you have fun?

Make sure you had fun coding 🙃

@pep8speaks
Copy link

pep8speaks commented Jul 2, 2021

Hello @XuehaiPan! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-07-19 11:02:22 UTC

@codecov
Copy link

codecov bot commented Jul 2, 2021

Codecov Report

Merging #8260 (0ff187a) into master (999ef5c) will decrease coverage by 5%.
The diff coverage is 68%.

@@           Coverage Diff           @@
##           master   #8260    +/-   ##
=======================================
- Coverage      93%     88%    -5%     
=======================================
  Files         217     217            
  Lines       14227   14239    +12     
=======================================
- Hits        13201   12547   -654     
- Misses       1026    1692   +666     

Copy link
Contributor

@awaelchli awaelchli left a comment

Choose a reason for hiding this comment

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

great observation, thanks for sending the fix!

tests/callbacks/test_gpu_stats_monitor.py Show resolved Hide resolved
pytorch_lightning/callbacks/gpu_stats_monitor.py Outdated Show resolved Hide resolved
pytorch_lightning/callbacks/gpu_stats_monitor.py Outdated Show resolved Hide resolved
pytorch_lightning/callbacks/gpu_stats_monitor.py Outdated Show resolved Hide resolved
pytorch_lightning/callbacks/gpu_stats_monitor.py Outdated Show resolved Hide resolved
@awaelchli awaelchli added callback bug Something isn't working labels Jul 2, 2021
@awaelchli awaelchli added this to the v1.3.x milestone Jul 2, 2021
@XuehaiPan XuehaiPan requested a review from awaelchli July 4, 2021 13:47
@tchaton
Copy link
Contributor

tchaton commented Jul 6, 2021

Hey @XuehaiPan,

Mind removing this line there: https://github.com/PyTorchLightning/pytorch-lightning/blob/master/pytorch_lightning/trainer/connectors/logger_connector/logger_connector.py#L230

It was filtering the available GPUS. There is an associated test with it.

Best,
T.C

pytorch_lightning/callbacks/gpu_stats_monitor.py Outdated Show resolved Hide resolved
pytorch_lightning/callbacks/gpu_stats_monitor.py Outdated Show resolved Hide resolved
pytorch_lightning/callbacks/gpu_stats_monitor.py Outdated Show resolved Hide resolved
tests/callbacks/test_gpu_stats_monitor.py Outdated Show resolved Hide resolved
tests/callbacks/test_gpu_stats_monitor.py Outdated Show resolved Hide resolved
…BLE_DEVICES` set

[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Apply suggestions from code review

[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Split functions

Apply suggestions from code review

[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Apply suggestions from code review

Co-authored-by: Carlos Mocholí <[email protected]>

[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Apply suggestions from code review

fmt

[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Apply suggestions from code review

Co-authored-by: Jirka Borovec <[email protected]>

Format code
@XuehaiPan
Copy link
Contributor Author

Mind removing this line there: https://github.com/PyTorchLightning/pytorch-lightning/blob/master/pytorch_lightning/trainer/connectors/logger_connector/logger_connector.py#L230

gpus_metrics contains all GPUs' memory.used fields, but they are enumerated in the real GPU IDs. If CUDA_VISIBLE_DEVICES is set to integer strings, it's easy to map the GPU IDs to CUDA device IDS. But if CUDA_VISIBLE_DEVICES is set to UUID strings, it could be hard to determine the device mapping.

@Borda Borda modified the milestones: v1.3.x, v1.4 Jul 6, 2021
@edenlightning edenlightning modified the milestones: v1.4, v1.3.x Jul 6, 2021
tests/callbacks/test_gpu_stats_monitor.py Outdated Show resolved Hide resolved
@Borda Borda added the ready PRs ready to be merged label Jul 9, 2021
Copy link
Contributor

@carmocca carmocca left a comment

Choose a reason for hiding this comment

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

Pushed a commit to use list comprehensions instead which are simpler to understand

@carmocca carmocca enabled auto-merge (squash) July 19, 2021 11:02
@carmocca carmocca merged commit 2c5d94d into Lightning-AI:master Jul 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working callback ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants