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

HPU & TPU doesn't support torch.inference_mode #13014

Merged
merged 9 commits into from
May 9, 2022
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Fixed mismatching default values for the types of some arguments in the DeepSpeed and Fully-Sharded strategies which made the CLI unable to use them ([#12989](https://github.com/PyTorchLightning/pytorch-lightning/pull/12989))


-
- Fixed an issue with unsupported torch.inference_mode() on hpu backends by making it use no_grad ([#13014](https://github.com/PyTorchLightning/pytorch-lightning/pull/13014))


-
Expand Down
1 change: 1 addition & 0 deletions docs/source/accelerators/hpu_basic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,4 @@ Known limitations
* Multiple optimizers are not supported.
* `Habana dataloader <https://docs.habana.ai/en/latest/PyTorch_User_Guide/PyTorch_User_Guide.html#habana-data-loader>`__ is not supported.
* :class:`~pytorch_lightning.callbacks.device_stats_monitor.DeviceStatsMonitor` is not supported.
* torch.inference_mode() is not supported
jerome-habana marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 4 additions & 2 deletions pytorch_lightning/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2802,10 +2802,12 @@ def configure_optimizers(self):

@contextmanager
def _evaluation_context() -> Generator:
# inference mode is not supported with gloo backend (#9431)
# inference mode is not supported with gloo backend (#9431) and hpu backend
context_manager_class = (
torch.inference_mode
if _TORCH_GREATER_EQUAL_1_9 and not (dist.is_initialized() and dist.get_backend() == "gloo")
if _TORCH_GREATER_EQUAL_1_9
and not (dist.is_initialized() and dist.get_backend() == "gloo")
and not _HPU_AVAILABLE
jerome-habana marked this conversation as resolved.
Show resolved Hide resolved
else torch.no_grad
)
with context_manager_class():
Expand Down