-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Conversation
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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ...
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"dp, ddp_spawn, ddp_shard_spawn or tpu_spawn" | |
" dp, ddp_sharded_spawn or tpu_spawn." |
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 |
Abandon this PR in favor of #12008 |
Thanks anyway for looking into this |
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
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:
Did you have fun?
Make sure you had fun coding 🙃