テクニカルガイド
混合精度トレーニング
Mixed precision uses lower-precision arithmetic for selected operations while retaining precision where needed.
このガイドを聴くAIによるナレーション · ~2 min
概要
It can reduce memory use and improve throughput on supported hardware, but gains and numerical effects depend on the model, workload, hardware and training recipe.
ディープダイブ
Traditional training stores weights and runs math in 32-bit floating point (FP32). Mixed precision uses lower-precision FP16 or bfloat16 for eligible operations while retaining FP32 where needed. Some FP16 recipes maintain a separate FP32 master copy to accumulate small weight updates; autocast workflows may instead keep model parameters in FP32 while casting selected operation inputs. Using 16-bit tensors can reduce memory used by eligible operations. Supported accelerators may execute some low-precision operations faster, but end-to-end throughput depends on hardware, workload and which operations autocast selects. FP16 has a narrower range, so tiny gradients can underflow. Loss scaling multiplies the loss before backpropagation and reverses that scale before the optimizer update; tools such as torch.amp.GradScaler can manage this process. Bfloat16 has a wider exponent range than FP16 and often does not need the same loss-scaling strategy, though model and hardware behavior still need testing.
現実世界の実装
PyTorch の torch.cuda.amp.autocast がトレーニング ループをラップして、単一の GPU でメモリを約半分にし、スループットを 2 倍にします。
損失スケーリング調整を回避するために、TPU 上の bfloat16 で GPT スタイルのトランスフォーマーのような大規模な言語モデルをトレーニングする
ResNet イメージ トレーニングを FP32 から FP16 に切り替えることにより、コンシューマ RTX GPU でより大きなバッチ サイズを適合させる
NVIDIA H100 GPU での FP8 混合精度により、フロンティアスケールのモデルの事前トレーニングのコストを削減
混合精度トレーニングの未来
精度はどんどん下がっていきます。 NVIDIA Hopper および Blackwell GPU でサポートされている FP8 トレーニングは、フロンティア モデルの標準になりつつあり、FP4 およびマイクロスケーリング フォーマット (MXFP) の研究がさらに進んでいます。フレームワークによるレイヤーごとの精度の自動選択、ハードウェアによるますます狭い形式のネイティブ処理、量子化対応トレーニングによる低精度トレーニングと推論の境界線があいまいになり、兆パラメータ モデルのトレーニング コストが削減されることが期待されます。
実践する
なぜそれが重要なのか
- 費用と予算. アーキテクチャの決定により、パフォーマンスと運用コストが何年にもわたって推進されます。
- より明確な判決. 技術教育は、チームが最新のスタックだけでなく、適切なスタックを選択するのに役立ちます。
- 品質管理. より良いエンジニアリングの選択により、本番環境での信頼性に関するインシデントが減少します。
気をつけてください
- 1 つのベンチマークを最適化すると、より広範なシステムの弱点が隠れる可能性があります。
- インフラストラクチャとメンテナンスのコストは過小評価されがちです。
- システムが複雑になるにつれて、セキュリティと可観測性のギャップが拡大する可能性があります。
次のステップ
- 実装前にレイテンシ、品質、コストの目標を定義します。
- 現実的な負荷とデータ条件でのベンチマーク。
- エラー、ドリフト、ユーザーへの影響を計測器で監視します。
- スケーリングの前に、ロールバックとインシデント対応のパスを準備します。
探検を続けましょう
よくある質問
What is Mixed Precision Training?
Mixed precision uses lower-precision arithmetic for selected operations while retaining precision where needed. It can reduce memory use and improve throughput on supported hardware, but gains and numerical effects depend on the model, workload, hardware and training recipe.
In an FP16 training recipe that keeps an FP32 master weight, why retain it?
Some FP16 recipes keep an FP32 master weight so small optimizer updates are not lost to low-precision rounding; not every mixed-precision recipe uses a separate copy.
損失スケーリングは FP16 トレーニングでどのような問題を解決しますか?
FP16 のダイナミック レンジは限られているため、小さな勾配はゼロに丸められる可能性があります。バックプロップの前に損失を乗算することで、表現可能性が保たれます。
bfloat16 には FP16 と比べてどのような利点がありますか?
Bfloat16 は FP32 と同様に 8 つの指数ビットを保持するため、ダイナミック レンジが広く、勾配のアンダーフローはまれです。
For many supported Tensor Core matrix operations, how are partial sums commonly accumulated?
Many common Tensor Core operations accumulate in FP32 to reduce rounding error; this does not make the computation exact.
What is a common benefit of using 16-bit values for supported training operations?
Lower precision can reduce memory and speed supported operations, but total results depend on the model, hardware, and kernels used.