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

make gpus=str in Trainer consistent with command line parsing of string #6388

Merged
merged 20 commits into from
May 4, 2021

Conversation

awaelchli
Copy link
Contributor

@awaelchli awaelchli commented Mar 7, 2021

What does this PR do?

Fixes #6228
Closes #7236

Current behavior:

# Selects GPU device 3
Trainer(gpus="3")

Desired behavior:

# Selects first 3 GPUS
Trainer(gpus="3")

This change makes the string type parsing for the gpus flag consistent with how the command line arguments are parsed.
**This PR announces the change today (from 1.3), the changes will take effect in 1.5 (breaking change). **

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 🙃

@awaelchli awaelchli added feature Is an improvement or enhancement design Includes a design discussion labels Mar 7, 2021
@awaelchli awaelchli added this to the 1.3 milestone Mar 7, 2021
@codecov
Copy link

codecov bot commented Mar 7, 2021

Codecov Report

Merging #6388 (fe4f636) into master (597b309) will decrease coverage by 0%.
The diff coverage is 85%.

@@          Coverage Diff           @@
##           master   #6388   +/-   ##
======================================
- Coverage      91%     91%   -0%     
======================================
  Files         200     200           
  Lines       12896   12985   +89     
======================================
+ Hits        11746   11799   +53     
- Misses       1150    1186   +36     

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.

No strong feelings for either a) or b). But if you choose b), you could leave all this logic for the future behaviour implemented already by checking the current lightning version. Just in case we forget about this.

Then when 1.5 comes we just have to remove the old code instead of resolving TODOs

tests/models/test_gpu.py Show resolved Hide resolved
@edenlightning
Copy link
Contributor

I really think we should avoid breaking changes, esp when this is unexpected.

@awaelchli
Copy link
Contributor Author

@edenlightning so you want me to close this PR? this would mean we keep the current behavior, nothing changes, and also close the linked issue.

@Borda
Copy link
Member

Borda commented Mar 14, 2021

@awaelchli still draft?

@awaelchli
Copy link
Contributor Author

@Borda it's 95% done, just waiting for a go/no-go decision here.
If backward incompatible changes are not acceptable, this PR can be closed. @edenlightning

@awaelchli awaelchli closed this Apr 20, 2021
@Borda Borda deleted the bugfix/str-gpu branch April 23, 2021 07:29
@awaelchli awaelchli restored the bugfix/str-gpu branch May 2, 2021 20:18
@awaelchli awaelchli reopened this May 2, 2021
Copy link
Contributor

@kaushikb11 kaushikb11 left a comment

Choose a reason for hiding this comment

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

LGTM!

@kaushikb11 kaushikb11 added the ready PRs ready to be merged label May 2, 2021
@awaelchli awaelchli modified the milestones: v1.3, v1.4 May 3, 2021
@carmocca
Copy link
Contributor

carmocca commented May 3, 2021

@awaelchli I see you modified the milestone here. Note that if this goes into 1.4 you'll have to update the deprecation warnings

@awaelchli
Copy link
Contributor Author

Yes this got pushed back so I'll pick it up after 1.3. Thanks.

@awaelchli awaelchli changed the title make gpus=str in Trainer consistent with command line parsing of string [wip] make gpus=str in Trainer consistent with command line parsing of string May 3, 2021
@awaelchli awaelchli changed the title [wip] make gpus=str in Trainer consistent with command line parsing of string make gpus=str in Trainer consistent with command line parsing of string May 3, 2021
@awaelchli awaelchli modified the milestones: v1.4, v1.3 May 3, 2021
@mergify mergify bot added the has conflicts label May 4, 2021
@pep8speaks
Copy link

pep8speaks commented May 4, 2021

Hello @awaelchli! Thanks for updating this PR.

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

Comment last updated at 2021-05-04 09:03:46 UTC

@mergify mergify bot removed the has conflicts label May 4, 2021
Comment on lines +236 to +238
.. warning::
The behavior for :code:`gpus="3"` (str) will change. Currently it selects the GPU with index 3, but will
select the first 3 GPUs from v1.5.
Copy link
Member

Choose a reason for hiding this comment

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

why are we announcing a change in 2 versions ahead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

are you saying one version is enough? I followed deprecation guideline of two versions.

Copy link
Contributor

@tchaton tchaton left a comment

Choose a reason for hiding this comment

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

I am for it. BC should be prevented when possible, unless it is to correct a behaviour.

from tests.helpers import BoringModel
from tests.helpers.datamodules import ClassifDataModule
from tests.helpers.imports import Batch, Dataset, Example, Field, LabelField
from tests.helpers.runif import RunIf
from tests.helpers.simple_models import ClassificationModel

PL_VERSION_LT_1_5 = _compare_version("pytorch_lightning", operator.lt, "1.5")
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice !

@tchaton tchaton enabled auto-merge (squash) May 4, 2021 08:37
@tchaton tchaton merged commit a6aa1a0 into master May 4, 2021
@tchaton tchaton deleted the bugfix/str-gpu branch May 4, 2021 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Includes a design discussion feature Is an improvement or enhancement ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cli: Confused on (str, int, List[int]) variants for argparse for --gpus flag?
9 participants