기본적으로 TPU는 bfloat16 값을 사용해서 행렬 곱셈 연산을 수행하고 IEEE float32 값을 사용해서 합산합니다. 정밀도가 감소된 부동 소수점 숫자를 사용하면 정확도를 손실하지 않으면서 수렴 시간을 줄일 수 있습니다.
bfloat16 및 float32의 다이내믹 레인지는 동일합니다. 하지만 bfloat16은 메모리 공간의 절반을 사용합니다. bfloat16 성능에 대한 자세한 내용은 딥 러닝 학습을 위한 BFLOAT16 연구를 참조하세요.
bfloat16 명시적으로 사용
TPU에서 자동 형식 변환을 사용하면 숫자 정밀도를 생각하지 않아도 되며 값을 bfloat16으로 명시적으로 변환하여 성능을 더욱 향상시킬 수 있습니다. 값을 bfloat16으로 명시적으로 변환하는 이유는 두 가지입니다.
값을 bfloat16 형식으로 저장하면 온칩 메모리가 절약되어 Cloud TPU가 더 큰 모델을 학습시키거나 더 큰 배치 크기를 사용할 수 있습니다.
일부 작업은 메모리 대역폭에 제한을 받습니다. 즉, 메모리에서 데이터를 로드하는 데 걸리는 시간에 따라 계산 수행에 걸리는 전체 시간이 느려질 수 있습니다. 이러한 작업의 피연산자 및 출력을 bfloat16 형식으로 저장하면 전송되어야 하는 데이터 양이 줄어들어 전반적으로 속도가 향상됩니다.
float32에서 bfloat16으로 형식 변환도 XLA 컴파일러에 의해 자동으로 삽입됩니다. TPU에서 변환의 반올림 스키마는 가장 가까운 짝수로 반올림되고 inf로 오버플로됩니다. 또한 Cloud TPU의 bfloat16은 하위 기준을 지원하지 않으므로 변환 중에 모든 하위 정규화가 0으로 플러시됩니다.
NaN 및 inf와 같은 특수 값은 변환 시 유지됩니다.
또한 bfloat16에서 float32로의 형식 변환도 XLA 컴파일러에 의해 자동으로 삽입됩니다. float32는 bfloat16의 모든 정확한 값을 나타낼 수 있으므로 변환은 가수 비트의 0을 16개로 패딩합니다. 변환 시 특수 값은 유지됩니다.
Cloud TPU에서 학습된 모델에서 얻은 체크포인트는 광범위한 수동 변환 없이 다른 하드웨어 플랫폼(예: 추론 또는 CPU 또는 GPU의 미세 조정)에 배포될 수 있습니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[],[],null,["# Improve your model's performance with bfloat16\n==============================================\n\nBy default, TPUs perform\nmatrix multiplication operations with [`bfloat16`](https://en.wikipedia.org/wiki/Bfloat16_floating-point_format)\nvalues and accumulations with IEEE [`float32`](https://en.wikipedia.org/wiki/Single-precision_floating-point_format)\nvalues. Using reduced-precision floating point numbers decreases time to\nconvergence without losing accuracy.\n\nThe dynamic range of `bfloat16` and `float32` are equivalent. However, `bfloat16`\nuses half of the memory space. For more information about `bfloat16` performance,\nsee [A Study of BFLOAT16 for Deep Learning Training](https://arxiv.org/abs/1905.12322).\n\nUse bfloat16 explicitly\n-----------------------\n\nWhile automatic format conversion in TPUs lets you avoid thinking about numerical\nprecision, you can achieve performance improvements by explicitly casting values\nto `bfloat16`. There are two reasons to explicitly cast values to `bfloat16`:\n\n1. Storing values in `bfloat16` format saves on-chip memory, enabling Cloud TPUs\n to train larger models or use larger batch sizes.\n\n2. Some operations are memory-bandwidth-bound, which means the amount of time it\n takes to load data from memory can slow down the overall time spent performing\n the computation. Storing operands and outputs of those operations in `bfloat16`\n format reduces the amount of data that must be transferred, improving overall\n speed.\n\nTo get started, we recommend getting some experience with one of the\n[Cloud TPU reference models](/tpu/docs/tutorials/supported-models). After\nthat, the [profiling tools guide](/tpu/docs/profile-tpu-vm), and\n[troubleshooting guide](/tpu/docs/troubleshooting/troubleshooting) provide\nin-depth technical information to help you create and optimize machine learning\nmodels on your own.\n\n### Format conversion details\n\nThe format conversion from `float32` to `bfloat16` is automatically inserted by the\nXLA compiler. On TPU, the rounding scheme in the conversion is\n[round to nearest even](https://en.wikipedia.org/wiki/IEEE_754#Roundings_to_nearest)\nand overflow to `inf`. Also, the `bfloat16` on Cloud TPU does not support\nsubnormals, so all subnormals are flushed to zero during the conversion.\nSpecial values, such as `NaN` and `inf`, are preserved in the conversion.\n\nThe format conversion from `bfloat16` to `float32` is also automatically inserted\nby the XLA compiler. Since `float32` can represent all exact values in `bfloat16`,\nthe conversion pads 16 zeros in the mantissa bits. Special values are\npreserved in the conversion.\n\nCheckpoints obtained from a model trained on Cloud TPUs can be deployed on other\nhardware platforms (for example, inference or fine-tuning on CPUs or GPUs)\nwithout extensive manual conversions."]]