* fixed new amp bugs

* fixed new amp bugs
This commit is contained in:
William Falcon
2020-04-23 15:24:02 -04:00
committed by GitHub
parent 68ca577919
commit 47629536e2
2 changed files with 4 additions and 5 deletions
+3 -3
View File
@@ -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
+1 -2
View File
@@ -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