Production FP16 conversion of an in-browser image inpainting model
ClearPix fixed severe quality degradation in its FP16 LaMa watermark-removal model by identifying sixteen BatchNorm variance tensors that exceeded FP16's numeric range and were silently clamped during ONNX conversion. Rescaling the BatchNorm variance, scale, and epsilon values with mathematically equivalent power-of-two transformations produced a fully FP16 model matching FP32 quality while reducing the compressed download size by 52%.
- Reported result
- The corrected model used 606 FP16 initializers with no FP32 residue, matched FP32 at 29.73 versus 29.74 dB on 14 masked-region acceptance cases, achieved 66.5 dB browser-runtime agreement against FP32, and reduced the Brotli-compressed download from 179.2 MiB to 86.3 MiB, a 52% reduction.
- Key limitation
- FP16 did not improve speed on the deployed WASM execution provider: inference slowed from 11.4 to 17.4 seconds per tile because WASM lacked native FP16 convolution kernels and inserted casts.
Task solved
Convert and deploy a large FP32 image-inpainting model as a fully FP16 browser model without degrading output quality, while reducing the amount of data users must download.
How it was done
The model powers ClearPix's client-side watermark remover and related browser media tools. The original FP16 conversion averaged 15.8 dB versus 29.7 dB for FP32 because BatchNorm running_var tensors above FP16's maximum value were silently clamped. The investigation and fix took approximately one to two days.
- Tools
- LaMa inpainting model with ONNX Runtime Web
What was checked
Reported result
- The corrected model used 606 FP16 initializers with no FP32 residue, matched FP32 at 29.73 versus 29.74 dB on 14 masked-region acceptance cases, achieved 66.5 dB browser-runtime agreement against FP32, and reduced the Brotli-compressed download from 179.2 MiB to 86.3 MiB, a 52% reduction.
- The FP16 path is live in ClearPix's image upscaler and supports its browser-based media tools.
Problems / limitations
FP16 did not improve speed on the deployed WASM execution provider: inference slowed from 11.4 to 17.4 seconds per tile because WASM lacked native FP16 convolution kernels and inserted casts. The fix is model-specific and requires auditing tensor ranges and validating quality in the target runtime. INT8 quantization remained unusable for this model.
Original source
Umasou / Dev.to
Open source discussion