天天看點

PyTorch的自動混合精度(AMP)

背景

PyTorch 1.6版本今天釋出了,帶來的最大更新就是自動混合精度。release說明的标題是:

  1. Stable release of automatic mixed precision (AMP).
  2. New Beta features include a TensorPipe backend for RPC, memory profiler,
  3. and several improvements to distributed training for both RPC and DDP.

可見自動混合精度正是PyTorch 1.6的最大更新。這就帶來了幾個問題:

  1. 什麼是自動混合精度訓練?
  2. 為什麼需要自動混合精度?
  3. 如何在PyTorch中使用自動混合精度?

什麼是自動混合精度訓練?

我們知道神經網絡架構的計算核心是Tensor,也就是那個從scaler -> array -> matrix -> tensor 次元一路豐富過來的tensor。在PyTorch中,我們可以這樣建立一個Tensor:

PyTorch的自動混合精度(AMP) - 知乎

繼續閱讀