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

Move is_interactive_compatible to Strategy #11970

Closed
wants to merge 1 commit into from

Conversation

four4fish
Copy link
Contributor

What does this PR do?

Fixes #11449 follow up item "Move _IS_INTERACTIVE check to strategy"

Does your PR introduce any breaking changes? If yes, please list them.

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 list all the breaking changes introduced by this pull request?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

PR review

Anyone in the community is welcome to review the PR.
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 🙃

is_interactive_compatible = (
self.strategy.is_interactive_compatible if hasattr(self.strategy, "is_interactive_compatible") else False
)
if _IS_INTERACTIVE and not is_interactive_compatible:
Copy link
Contributor

Choose a reason for hiding this comment

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

do the _IS_INTERACTIVE check first. you can return early if it's not interactive. then you only need to check the strategy's property afterward instead of always checking it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to have strategy object to get the is_interactive_compatible property.

Copy link
Contributor

@carmocca carmocca Feb 18, 2022

Choose a reason for hiding this comment

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

I think Ananth means:

if _IS_INTERACTIVE and hasattr(self.strategy, "is_interactive_compatible") and not self.strategy.is_interactive_compatible:
    raise ...

Copy link
Contributor

Choose a reason for hiding this comment

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

if not _IS_INTERACTIVE:
    return

if hasattr(self.strategy, "is_interactive_compatible") and not self.strategy.is_interactive_compatible:
    raise

from pytorch_lightning.utilities import _IS_INTERACTIVE

is_interactive_compatible = (
self.strategy.is_interactive_compatible if hasattr(self.strategy, "is_interactive_compatible") else False
Copy link
Contributor

Choose a reason for hiding this comment

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

should these specific hasattr checks could be formalized as traits or mixins? someone has to go deep into the code to realize these specific properties need to be added to their strategy for this to work. we had the same discussion for backward sync

from pytorch_lightning.utilities import _IS_INTERACTIVE

is_interactive_compatible = (
self.strategy.is_interactive_compatible if hasattr(self.strategy, "is_interactive_compatible") else False
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not add it to the base class and have it default to False?

is_interactive_compatible = (
self.strategy.is_interactive_compatible if hasattr(self.strategy, "is_interactive_compatible") else False
)
if _IS_INTERACTIVE and not is_interactive_compatible:
Copy link
Contributor

@carmocca carmocca Feb 18, 2022

Choose a reason for hiding this comment

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

I think Ananth means:

if _IS_INTERACTIVE and hasattr(self.strategy, "is_interactive_compatible") and not self.strategy.is_interactive_compatible:
    raise ...

@@ -109,6 +109,10 @@ def _is_single_process_single_device(self):
def _configure_launcher(self):
self._launcher = _SpawnLauncher(self)

@property
def is_interactive_compatible(self) -> bool:
return True
Copy link
Contributor

Choose a reason for hiding this comment

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

well, unfortunately no longer #7550 :(((

@@ -109,6 +109,10 @@ def _is_single_process_single_device(self):
def _configure_launcher(self):
self._launcher = _SpawnLauncher(self)

@property
Copy link
Contributor

Choose a reason for hiding this comment

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

can we move the property up to join the others?

f"`Trainer(strategy={self.strategy.strategy_name!r})` or"
f" `Trainer(accelerator={self.strategy.strategy_name!r})` is not compatible with an interactive"
" environment. Run your code as a script, or choose one of the compatible backends, for example:"
"dp, ddp_spawn, ddp_shard_spawn or tpu_spawn"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"dp, ddp_spawn, ddp_shard_spawn or tpu_spawn"
" dp, ddp_sharded_spawn or tpu_spawn."

@awaelchli
Copy link
Contributor

awaelchli commented Feb 19, 2022

Can we consider adding this to the launcher? it would be much less to think about when implementing a new strategy and the Jupyter environment compatibility is really just about the multiprocess launching so to me the process launchers are the better place to introduce this property.

What do people think?

EDIT: Found that interactive support is broken on master. See #12008

@four4fish
Copy link
Contributor Author

Abandon this PR in favor of #12008

@four4fish four4fish closed this Feb 22, 2022
@awaelchli
Copy link
Contributor

Thanks anyway for looking into this ☺️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rewrite Accelerator_connector and follow up tasks
4 participants