Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Melhorar a performance do modelo com o bfloat16
Por padrão, as TPUs executam
operações de multiplicação de matriz com valores bfloat16
e acumulações com valores float32
do IEEE. O uso de números de ponto flutuante de precisão reduzida diminui o tempo de
convergência sem perder a precisão.
Embora a conversão automática de formato em TPUs permita evitar a precisão
numérica, é possível melhorar a performance ao transmitir valores explicitamente
para bfloat16. Há dois motivos para converter valores explicitamente em bfloat16:
Armazenar valores no formato bfloat16 economiza memória no chip, permitindo que as Cloud TPUs
treinem modelos maiores ou usem tamanhos de lote maiores.
Algumas operações são vinculadas à largura de banda, o que significa que o tempo necessário para carregar dados da memória pode diminuir o tempo total gasto na execução do cálculo. Armazenar operandos e saídas dessas operações no formato bfloat16
reduz a quantidade de dados que precisam ser transferidos, melhorando a velocidade
geral.
A conversão de formato de float32 para bfloat16 é inserida automaticamente pelo
compilador XLA. Na TPU, o esquema de arredondamento na conversão é
arredondado para o número par mais próximo
e transborda para inf. Além disso, o bfloat16 no Cloud TPU não oferece suporte a
subnormais, portanto, todos os subnormais são zerados durante a conversão.
Valores especiais, como NaN e inf, são preservados na conversão.
A conversão de formato de bfloat16 para float32 também é inserida automaticamente
pelo compilador XLA. Como float32 pode representar todos os valores exatos em bfloat16,
a conversão preenche 16 zeros nos bits de mantissa. Os valores especiais são
preservados na conversão.
Os checkpoints recebidos de um modelo treinado em Cloud TPUs podem ser implantados em outras plataformas de hardware, como inferência ou ajuste em CPUs ou GPUs, sem conversões manuais extensas.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-08-18 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."]]