为JAX设计的混合精度训练工具,提升大模型训练效率且不损失精度。
MPX: Mixed Precision Training for JAX
- 通过动态损失缩放和半精度输入输出,解决半精度计算中的梯度溢出问题。
- 支持自动管理混合精度梯度与优化器,兼容Flax等主流工具链。
- 可零成本接入现有训练流程,适合大规模神经网络训练者使用。
混合精度训练已成为近年来提升神经网络训练效率的关键技术。与此同时,JAX作为功能强大的机器学习工具箱日益流行,但目前缺乏对混合精度训练的稳定支持。本文提出MPX,一个专为JAX设计的混合精度训练工具箱,可在保持模型精度的前提下,简化并加速大规模神经网络的训练。MPX无缝集成于Equinox、Flax等常用工具包,用户仅需少量修改即可将全精度训练流程转为混合精度版本。通过将输入和输出均转为半精度,并引入动态损失缩放机制,有效缓解了半精度计算中常见的梯度下溢和上溢问题。其设计继承了JAX的类型提升行为,确保操作在正确精度下执行,并允许选择性地在特定操作(如求和、均值、Softmax)中强制使用全精度。MPX还提供自动创建和管理混合精度梯度与优化器的封装,便于直接融入现有JAX训练流程。项目源码、文档及示例已开源至github.com/Data-Science-in-Mechanical-Engineering/mixed_precision_for_JAX。
原文摘要 · Abstract (English)
Mixed-precision training has emerged as an indispensable tool for enhancing the efficiency of neural network training in recent years. Concurrently, JAX has grown in popularity as a versatile machine learning toolbox. However, it currently lacks robust support for mixed-precision training. We propose MPX, a mixed-precision training toolbox for JAX that simplifies and accelerates the training of large-scale neural networks while preserving model accuracy. MPX seamlessly integrates with popular toolboxes such as Equinox and Flax, allowing users to convert full-precision pipelines to mixed-precision versions with minimal modifications. By casting both inputs and outputs to half precision, and introducing a dynamic loss-scaling mechanism, MPX alleviates issues like gradient underflow and overflow that commonly arise in half precision computations. Its design inherits critical features from JAX's type-promotion behavior, ensuring that operations take place in the correct precision and allowing for selective enforcement of full precision where needed (e.g., sums, means, or softmax). MPX further provides wrappers for automatic creation and management of mixed-precision gradients and optimizers, enabling straightforward integration into existing JAX training pipelines. MPX's source code, documentation, and usage examples are available at github.com/Data-Science-in-Mechanical-Engineering/mixed_precision_for_JAX .
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。