diff --git a/pytorch_lightning/core/lightning.py b/pytorch_lightning/core/lightning.py index ace22fd7..82be2d53 100644 --- a/pytorch_lightning/core/lightning.py +++ b/pytorch_lightning/core/lightning.py @@ -1159,19 +1159,19 @@ class LightningModule(ABC, GradInformation, ModelIO, ModelHooks): elif isinstance(optimizer, torch.optim.LBFGS): # native amp + lbfgs is a no go right now - if self.use_amp and self.use_native_amp: + if self.trainer.use_amp and self.trainer.use_native_amp: m = 'native PyTorch amp and lbfgs are not compatible. To request, please file' \ 'a Github issue in PyTorch and tag @mcarilli' raise MisconfigurationException(m) optimizer.step(second_order_closure) else: - if self.use_amp and self.use_native_amp: + if self.trainer.use_amp and self.trainer.use_native_amp: self.trainer.scaler.step(optimizer) else: optimizer.step() # in native 16-bit we need to update scaler after optimizer step - if self.use_amp and self.use_native_amp: + if self.trainer.use_amp and self.trainer.use_native_amp: self.trainer.scaler.update() # model hook diff --git a/pytorch_lightning/trainer/trainer.py b/pytorch_lightning/trainer/trainer.py index e92f3c09..fe69a98a 100644 --- a/pytorch_lightning/trainer/trainer.py +++ b/pytorch_lightning/trainer/trainer.py @@ -492,13 +492,12 @@ class Trainer( # we wrap the user's forward with autocast and give it back at the end of fit self.autocast_original_forward = None self.use_native_amp = hasattr(torch.cuda, "amp") and hasattr(torch.cuda.amp, "autocast") + self.precision = precision if self.use_native_amp and self.precision == 16: self.scaler = torch.cuda.amp.GradScaler() - self.precision = precision # TODO: remove for v0.8.0 self.amp_level = amp_level - self.precision = precision self.init_amp(use_amp) # Callback system