Loss scaling is a technique used in mixed-precision training where the calculated loss value is multiplied by a constant scaling factor (S) before the backward pass, preventing gradient values from underflowing to zero when represented in FP16 (half-precision). The gradients are subsequently divided by the same factor before the optimizer updates the model weights, preserving the original update direction and magnitude. This simple multiplicative operation allows training to leverage the speed and memory benefits of FP16 while maintaining the numerical stability traditionally associated with FP32 (single-precision).
Glossary
Loss Scaling

What is Loss Scaling?
A foundational technique in mixed-precision training that prevents numerical underflow in low-precision gradients.
The technique is critical because the backward pass computes gradients, which can have magnitudes smaller than the minimum positive value representable in FP16 (~5.96e-8), causing them to become zero—a phenomenon known as numerical underflow. By scaling the loss up, all gradients are proportionally scaled up, keeping them within FP16's representable range. Frameworks like Automatic Mixed Precision (AMP) dynamically adjust this scaling factor during training, monitoring for gradient overflow to prevent the opposite problem. Loss scaling is a key enabler for efficient training on modern Neural Processing Units (NPUs) and GPUs with dedicated FP16 arithmetic units.
Key Characteristics of Loss Scaling
Loss scaling is a critical technique in mixed-precision training that prevents gradient underflow in FP16 by applying a multiplicative factor before backpropagation, ensuring stable convergence.
Prevents Gradient Underflow
The primary purpose of loss scaling is to prevent gradient values from underflowing to zero when represented in FP16. In FP16, the smallest positive normalized number is approximately 5.96e-8. Many gradient values, especially in the early layers of deep networks, can be smaller than this threshold. By multiplying the loss by a scaling factor (e.g., 1024 or 4096), the entire gradient chain is proportionally scaled up during backpropagation, keeping values within the FP16 representable range. The gradients are then unscaled before the optimizer step, preserving the correct weight update magnitude.
Dynamic vs. Static Scaling
Loss scaling strategies are categorized by how the scaling factor is adjusted:
- Dynamic Loss Scaling: The scaling factor is automatically adjusted during training. The system monitors gradients for NaN/Inf values (indicating overflow). If overflow is detected, the scale is reduced (e.g., halved), and the step is skipped. If no overflow occurs for a set number of steps, the scale is increased to maximize precision. This is the most common and robust method.
- Static Loss Scaling: A single, constant scaling factor is chosen before training, often determined through empirical testing on a small dataset. It is simpler but less adaptive to the changing gradient landscape throughout training.
The Gradient Unscaling Step
A critical, non-negotiable step is unscaling the gradients before the optimizer updates the weights. After backpropagation, the computed gradients are still scaled by the loss scaling factor. If these scaled gradients were applied directly, the weight update would be catastrophically large, causing training divergence. Therefore, the gradients are divided by the same scaling factor before being passed to the optimizer (e.g., optimizer.step()). In AMP, this unscaling happens automatically within the context manager.
Relationship to BF16 Format
The adoption of the BF16 (Brain Float 16) format reduces, but does not eliminate, the need for aggressive loss scaling. BF16 has the same 8-bit exponent range as FP32, making it highly resistant to underflow. However, overflow can still occur. While dynamic loss scaling is often still used with BF16 for safety, the scaling factors can typically be much larger and more stable than with FP16, as the primary concern shifts from underflow prevention to managing occasional overflow events.
Impact on Convergence and Accuracy
When implemented correctly, loss scaling has a neutral impact on final model accuracy while providing significant speedups. The technique is mathematically sound because it applies a linear scaling to the loss, which results in a linear scaling of all gradients. After unscaling, the weight update is identical to what it would have been in full FP32 precision, assuming no underflow occurred. The key benefit is enabling the use of faster FP16/BF16 arithmetic for the forward and backward passes without sacrificing the fidelity of the weight updates, leading to 1.5x to 3x faster training on compatible hardware.
Loss Scaling vs. Related Techniques
A comparison of loss scaling with other key techniques used to manage numerical precision in neural network training and inference, highlighting their primary purpose, mechanism, and typical use case.
| Feature / Metric | Loss Scaling | Automatic Mixed Precision (AMP) | Quantization-Aware Training (QAT) | Post-Training Quantization (PTQ) |
|---|---|---|---|---|
Primary Purpose | Prevent gradient underflow in FP16/BF16 training | Automate precision casting to accelerate training | Train a model to be robust to subsequent quantization | Compress a trained model for efficient inference |
Core Mechanism | Multiply loss by a scale factor before backpropagation | Framework-managed casting between FP32/FP16 and gradient scaling | Simulate quantization (fake quantization) during forward/backward passes | Calibrate and apply affine quantization using a static dataset |
Phase of Use | Training (specifically backward pass) | Training (forward & backward passes) | Training (fine-tuning phase) | Post-training / Inference preparation |
Numerical Precision(s) | FP16/BF16 for forward/backward, FP32 for master weights | FP16/BF16 for compute, FP32 for master weights & certain ops | Simulated INT8/FP16 during forward, FP32 for backward | INT8 (or INT4) for weights & activations at inference |
Handles Gradient Underflow | ||||
Requires Model Retraining | ||||
Reduces Model Memory Footprint | ~50% for activations/gradients | ~50% for activations/gradients | Up to 75% (for INT8) | Up to 75% (for INT8) |
Typical Performance Gain | 2-3x training speedup on supported hardware | 2-3x training speedup on supported hardware | Minimal during training; enables fast inference | 2-4x inference speedup on integer hardware |
Key Hyperparameter / Input | Loss scale factor (dynamic or static) | Grad scaler configuration (e.g., | Quantization scheme (e.g., symmetric, per-channel) | Calibration dataset (100-500 samples) |
Primary Hardware Target | GPUs/NPUs with fast FP16/BF16 units (e.g., NVIDIA Tensor Cores) | GPUs/NPUs with fast FP16/BF16 units | Any, but optimized for integer NPUs/CPUs | Integer NPUs, Edge TPUs, Mobile CPUs |
Framework Implementation
Loss scaling is a critical technique in mixed-precision training, implemented within deep learning frameworks to prevent gradient underflow in FP16. This section details its practical integration and management.
Automatic Mixed Precision (AMP)
Automatic Mixed Precision (AMP) is a library feature that automates the application of loss scaling and precision casting. Frameworks like PyTorch (torch.cuda.amp) and TensorFlow (tf.keras.mixed_precision) use it to:
- Automatically cast operations to FP16 where safe.
- Apply dynamic loss scaling by default, monitoring gradients for NaN/Inf values.
- Scale the loss before the forward pass and unscale gradients before the optimizer step.
- Provide a GradScaler object that manages the scaling factor, adjusting it upward after successful steps or downward after overflow detection.
Gradient Scaling & Unscaling
The core mechanics involve two framework-managed steps:
- Scaling: The computed loss value is multiplied by a scale factor (e.g., 1024, 65536) before
loss.backward(). This shifts small FP16 gradient values into a representable range. - Unscaling: Before the optimizer updates weights (
optimizer.step()), the gradients accumulated in the.gradattributes are divided by the same scale factor. This ensures the weight update is correct and not artificially magnified. Frameworks perform this unscaling efficiently, often fusing it with gradient clipping or other pre-update operations.
Dynamic vs. Static Scaling
Frameworks implement two primary scaling strategies:
- Dynamic Loss Scaling: The default in AMP. The scale factor is adjusted automatically each iteration. After a number of successful steps (e.g., 2000), the scale is doubled. If a gradient overflow (NaN/Inf) is detected, the optimizer step is skipped, the scale is halved, and gradients are cleared. This adapts to changing gradient norms throughout training.
- Static Loss Scaling: A constant, empirically determined scale factor is used for the entire training run. This is less common as it requires manual tuning and is less robust to varying gradient dynamics. It may be used in highly stable training regimes.
Overflow Detection & Skipped Batches
A key framework responsibility is overflow detection. After the backward pass, the system checks gradients for NaN or Inf values.
- If overflow is detected, the framework:
- Skips the
optimizer.step()call for that iteration. - Reduces the loss scale (e.g., multiplies by 0.5 or a
backoff_factor). - Clears the gradients to prevent corrupted values from affecting the next step.
- Skips the
- This process prevents weight corruption and allows training to recover automatically. Monitoring the frequency of skipped batches is a key debugging metric.
Integration with Optimizers & Gradient Clipping
Loss scaling must interoperate seamlessly with other training components:
- Optimizers: The unscaling operation occurs just before the optimizer's update rule is applied. Frameworks ensure the optimizer receives the true, unscaled gradients.
- Gradient Clipping: Clipping is typically applied after unscaling but before the weight update. This ensures gradients are clipped based on their true magnitude, not the scaled magnitude. The framework's
GradScaleroften has aunscale_method that is called prior toclip_grad_norm_.
Framework-Specific APIs
PyTorch: Uses torch.cuda.amp.GradScaler and autocast context managers.
pythonscaler = GradScaler() with autocast(): loss = model(data) scaler.scale(loss).backward() scaler.step(optimizer) scaler.update()
TensorFlow: Uses tf.keras.mixed_precision.Policy and a LossScaleOptimizer wrapper.
pythonpolicy = tf.keras.mixed_precision.Policy('mixed_float16') tf.keras.mixed_precision.set_global_policy(policy) optimizer = tf.keras.optimizers.Adam() optimizer = tf.keras.mixed_precision.LossScaleOptimizer(optimizer)
JAX: Uses optax.scale_by_amsgrad or custom gradient transformation chains with jax.lax.scan for dynamic scaling logic.
Frequently Asked Questions
Loss scaling is a critical technique in mixed-precision training, designed to prevent numerical underflow in low-precision gradients. These questions address its core mechanics, implementation, and role in modern AI hardware acceleration.
Loss scaling is a technique used in mixed-precision training where the computed loss value is multiplied by a constant scaling factor (e.g., 128, 256, 1024) before the backward pass begins. This multiplication increases the magnitude of the gradient values flowing backward through the network, preventing them from underflowing to zero in FP16 precision. After the backward pass, the resulting weight gradients are divided (unscaled) by the same factor before the optimizer applies the weight update, ensuring the update magnitude is correct.
How it works:
- Forward Pass: Model executes in mixed precision (FP16/FP32).
- Scale Loss: The calculated scalar loss is multiplied by the scaling factor
S. - Backward Pass: Automatic differentiation computes gradients with respect to the scaled loss, producing gradients that are
Stimes larger. - Unscale Gradients: Before the optimizer step, all gradients are divided by
S. - Optimizer Step: Weights are updated using the unscaled gradients.
This simple multiplicative operation preserves the direction of gradients while ensuring their values remain within the representable range of FP16.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Loss scaling is a core component of mixed-precision training. These related terms define the numerical formats, techniques, and hardware considerations that make this optimization possible.
Automatic Mixed Precision (AMP)
Automatic Mixed Precision (AMP) is a library feature that automates the casting of tensors between different numerical precisions (e.g., FP16 and FP32) during training. It manages the entire mixed-precision workflow, including loss scaling, to accelerate performance while preserving gradient stability. Common implementations include NVIDIA's Apex and native support in PyTorch and TensorFlow.
- Key Function: Automates precision selection and gradient scaling.
- Primary Benefit: Reduces developer overhead for implementing mixed-precision training.
- Use Case: Standard practice for training large models on modern GPUs and NPUs.
FP16 (Half-Precision)
FP16, or half-precision floating-point, is a 16-bit numerical format defined by the IEEE 754 standard. It is the primary lower-precision format used in mixed-precision training. Its limited dynamic range (approx. 5.96e-8 to 65504) is the core reason loss scaling is required, as small gradient values can underflow to zero.
- Bit Layout: 1 sign bit, 5 exponent bits, 10 mantissa bits.
- Memory/Compute Benefit: Halves memory footprint and bandwidth vs. FP32; many accelerators have dedicated FP16 arithmetic units for higher throughput.
- Trade-off: Increased risk of underflow/overflow compared to higher-precision formats.
BF16 (Brain Floating-Point)
BF16 is an alternative 16-bit floating-point format that uses an 8-bit exponent (same as FP32) and a 7-bit mantissa. It is designed to preserve the dynamic range of FP32 much better than FP16, making it inherently more robust for training. While loss scaling may still be used with BF16, the risk of gradient underflow is significantly reduced.
- Bit Layout: 1 sign bit, 8 exponent bits, 7 mantissa bits.
- Primary Advantage: Excellent dynamic range preservation simplifies mixed-precision training.
- Hardware Support: Native support on Google TPUs, Intel CPUs (AMX), and NVIDIA GPUs (starting with Ampere architecture).
Numerical Underflow
Numerical underflow occurs when a computational result is smaller than the smallest positive number representable in a given floating-point format, causing it to be rounded to zero. In mixed-precision training with FP16, small gradient values are highly susceptible to underflow, which halts learning. Loss scaling directly counteracts this by multiplying the loss (and thus the gradients) by a large factor, shifting them into a representable range before the weight update.
- Direct Cause: Gradients with magnitudes less than ~5.96e-8 in FP16.
- Consequence: Zero gradients provide no weight update signal.
- Solution: Scale values up before the computation, then scale down the result.
Gradient Scaling
Gradient scaling is the broader technique of which loss scaling is a specific, efficient implementation. Instead of scaling individual gradients, loss scaling multiplies the scalar loss value before backpropagation, leveraging the chain rule to automatically scale all subsequent gradients. This ensures consistency and minimizes computational overhead.
- Core Principle: Scaling a scalar (the loss) is cheaper and more uniform than scaling a high-dimensional gradient tensor.
- Mathematical Foundation: Based on the linearity of the derivative: d(sL)/dw = s * dL/dw.
- Implementation Check: The optimizer must unscale the gradients before applying the weight update to maintain the correct update magnitude.
Dynamic Loss Scaling
Dynamic loss scaling is an adaptive algorithm that automatically adjusts the scaling factor during training. It starts with a high scale factor, monitors for gradient overflow (NaN/Inf values), and reduces the scale if overflow is detected. If no overflow occurs for a period, it cautiously increases the scale to maximize precision.
- Algorithm Steps:
- Start with a high scale (e.g., 2^24).
- Perform forward/backward pass with scaled loss.
- Check gradients for Inf/NaN.
- If overflow: skip weight update, reduce scale (e.g., halve it), retry.
- If no overflow for N steps: increase scale (e.g., double it).
- Benefit: Eliminates the need for manual tuning of a static scaling factor.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us