mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-10 12:21:57 +08:00
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user