Attempting to unscale FP16 gradients
I want to train and save my model with 16-bit precision, what should I do ?
def train():
    model = Model(**config)
    model.half()
    data_module = MyDataModule(config['train_root'], config['folds'], config['size'],
                               config['batch_size'], config['num_workers'])
    for i in range(config['folds']):
        model.set_net(i)
        trainer = pl.Trainer(max_epochs=config['epochs'], gpus=[0, ], precision=16,
                             # limit_train_batches=config['limit_train_batches'],
                             # limit_val_batches=config['limit_val_batches'],
                             )
        trainer.fit(model=model,
                    train_dataloader=data_module.train_dataloader(i),
                    val_dataloaders=data_module.val_dataloader(i))

print:

{'n_class': 2, 'num_workers': 4, 'batch_size': 32, 'train_root': '/root/projects/Screw/data/train', 'ckpt': 'model-7res18.pt', 'epochs': 30, 'lr': 0.001, 'size': 224, 'folds': 7, 'limit_train_batches': None, 'limit_val_batches': None}
GPU available: True, used: True
TPU available: False, using: 0 TPU cores
LOCAL_RANK: 0 - CUDA_VISIBLE_DEVICES: [0]
Using native 16bit precision.

  | Name    | Type       | Params
---------------------------------------
0 | nets    | ModuleList | 78 M  
1 | cur_net | Net        | 11 M  
/root/anaconda3/envs/py37/lib/python3.7/site-packages/pytorch_lightning/utilities/distributed.py:45: UserWarning: Your val_dataloader has `shuffle=True`, it is best practice to turn this off for validation and test dataloaders.
  warnings.warn(*args, **kwargs)
Validation sanity check:  50%|██████████          | 1/2 [00:00<00:00,  1.90it/s]cur net: 0
{'val_loss': tensor(0.9086, device='cuda:0'), 'val_f1': 0.5681818181818181}
Epoch 0:   0%|                                           | 0/19 [00:00<?, ?it/s]Traceback (most recent call last):
  File "/root/projects/Screw/model.py", line 251, in <module>
    train()
  File "/root/projects/Screw/model.py", line 223, in train
    val_dataloaders=data_module.val_dataloader(i))
  File "/root/anaconda3/envs/py37/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 446, in fit
    results = self.accelerator_backend.train()
  File "/root/anaconda3/envs/py37/lib/python3.7/site-packages/pytorch_lightning/accelerators/gpu_accelerator.py", line 64, in train
    results = self.train_or_test()
  File "/root/anaconda3/envs/py37/lib/python3.7/site-packages/pytorch_lightning/accelerators/accelerator.py", line 66, in train_or_test
    results = self.trainer.train()
  File "/root/anaconda3/envs/py37/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 495, in train
    self.train_loop.run_training_epoch()
  File "/root/anaconda3/envs/py37/lib/python3.7/site-packages/pytorch_lightning/trainer/training_loop.py", line 561, in run_training_epoch
    batch_output = self.run_training_batch(batch, batch_idx, dataloader_idx)
  File "/root/anaconda3/envs/py37/lib/python3.7/site-packages/pytorch_lightning/trainer/training_loop.py", line 728, in run_training_batch
    self.optimizer_step(optimizer, opt_idx, batch_idx, train_step_and_backward_closure)
  File "/root/anaconda3/envs/py37/lib/python3.7/site-packages/pytorch_lightning/trainer/training_loop.py", line 470, in optimizer_step
    optimizer, batch_idx, opt_idx, train_step_and_backward_closure, *args, **kwargs
  File "/root/anaconda3/envs/py37/lib/python3.7/site-packages/pytorch_lightning/accelerators/accelerator.py", line 124, in optimizer_step
    **kwargs,
  File "/root/anaconda3/envs/py37/lib/python3.7/site-packages/pytorch_lightning/core/lightning.py", line 1372, in optimizer_step
    optimizer_closure()
  File "/root/anaconda3/envs/py37/lib/python3.7/site-packages/pytorch_lightning/trainer/training_loop.py", line 723, in train_step_and_backward_closure
    self.trainer.hiddens
  File "/root/anaconda3/envs/py37/lib/python3.7/site-packages/pytorch_lightning/trainer/training_loop.py", line 823, in training_step_and_backward
    self.backward(result, optimizer, opt_idx)
  File "/root/anaconda3/envs/py37/lib/python3.7/site-packages/pytorch_lightning/trainer/training_loop.py", line 844, in backward
    result.closure_loss, optimizer, opt_idx, *args, **kwargs
  File "/root/anaconda3/envs/py37/lib/python3.7/site-packages/pytorch_lightning/accelerators/accelerator.py", line 90, in backward
    closure_loss, optimizer, opt_idx, *args, **kwargs
  File "/root/anaconda3/envs/py37/lib/python3.7/site-packages/pytorch_lightning/plugins/native_amp.py", line 50, in backward
    self.trainer.scaler.unscale_(optimizer)
  File "/root/anaconda3/envs/py37/lib/python3.7/site-packages/torch/cuda/amp/grad_scaler.py", line 240, in unscale_
    optimizer_state["found_inf_per_device"] = self._unscale_grads_(optimizer, inv_scale, found_inf, False)
  File "/root/anaconda3/envs/py37/lib/python3.7/site-packages/torch/cuda/amp/grad_scaler.py", line 187, in _unscale_grads_
    raise ValueError("Attempting to unscale FP16 gradients.")
ValueError: Attempting to unscale FP16 gradients.
Exception ignored in: <function tqdm.__del__ at 0x7efe5330fb70>
Traceback (most recent call last):
  File "/root/anaconda3/envs/py37/lib/python3.7/site-packages/tqdm/std.py", line 1128, in __del__
  File "/root/anaconda3/envs/py37/lib/python3.7/site-packages/tqdm/std.py", line 1341, in close
  File "/root/anaconda3/envs/py37/lib/python3.7/site-packages/tqdm/std.py", line 1520, in display
  File "/root/anaconda3/envs/py37/lib/python3.7/site-packages/tqdm/std.py", line 1131, in __repr__
  File "/root/anaconda3/envs/py37/lib/python3.7/site-packages/tqdm/std.py", line 1481, in format_dict
TypeError: cannot unpack non-iterable NoneType object

Process finished with exit code 1