Skip to content

Mixed Precision & Quantization ​

Super-resolution networks operate on dense high-resolution feature maps where memory bandwidth dominates latency. Reducing numerical precision unlocks substantial speedups, but restoration models are notoriously sensitive to quantization noise in shallow and reconstruction layers.

Automatic Mixed Precision (AMP) ​

During training and GPU inference, SoraSR supports both BF16 and FP16:

FormatExponent BitsMantissa BitsDynamic RangeRecommendation
fp32823±3.4×1038Reference accuracy & loss scaling baseline
bf1687±3.4×1038Preferred on Ampere / Hopper / Ada GPUs (no GradScaler needed)
fp16510±6.5×104Preferred for TensorRT inference on Turing / Ampere / Ada

Attention Accumulation in FP16

Keep softmax normalization and LayerNorm statistics in fp32. SoraSR automatically forces fp32 inside attention score scaling and residual accumulation when precision: fp16 is selected to prevent NaN divergence on high-contrast patches.

Post-Training Quantization (PTQ) ​

INT8 quantization compresses weights and activations by 4x relative to FP32, cutting DRAM traffic significantly. However, uniform INT8 quantization across all layers typically costs 0.4–0.9 dB PSNR on Set14/Urban100.

SoraSR mitigates this drop using Sensitivity-Guided Mixed-Precision PTQ:

  1. Calibration Set — Run 128 diverse high-resolution crops (covering sharp text, foliage, skin tones, and low-light gradients) through an entropy/percentile observer (99.99% clipping).
  2. Per-Layer Sensitivity Profiling — Measure PSNR delta when quantizing each module independently while holding the rest in FP16.
  3. Selective FP16 Fallback — Keep the top 10% most sensitive layers in FP16, always including:
    • Entry shallow feature convolution (conv_first)
    • Final sub-pixel reconstruction head (upsampler, conv_last)
    • Residual skip additions with wide activation variance

Quantization-Aware Training (QAT) ​

When strict INT8 throughput is required with < 0.15 dB PSNR degradation, insert fake-quantization observers and fine-tune for 20k–40k steps at a reduced learning rate (1e-5):

bash
sorasr train \
  --config configs/qat_sorasr_s_x4.yaml \
  --resume checkpoints/sorasr_s_x4_fp32.pt \
  --work-dir runs/sorasr_s_x4_qat

Observed Accuracy vs. Latency (SoraSR-S x4, 720p → 4K on RTX 4090) ​

Precision ModeUrban100 PSNR (dB)Latency (ms)VRAM (GB)
PyTorch FP3226.84118.23.9
PyTorch BF1626.8354.62.3
TensorRT FP1626.8229.41.6
TensorRT INT8 (Uniform PTQ)26.1919.81.1
TensorRT INT8 (Mixed PTQ + QAT)26.7421.51.2

Released under the Apache-2.0 License.