---
title: NAFNet-SIDD-width32-LiteRT
canonical_url: "https://www.modelscope.cn/models/litert-community/NAFNet-SIDD-width32-LiteRT"
md_url: "https://www.modelscope.cn/models/litert-community/NAFNet-SIDD-width32-LiteRT.md"
repository: litert-community/NAFNet-SIDD-width32-LiteRT
last_updated: 2026-09-08
license: mit
pipeline_tag: image-to-image
tasks:
  - image-to-image
base_model:
  - megvii-research/NAFNet
base_model_relation: quantized
library_name:
  - pytorch
frameworks:
  - pytorch
downloads: 18
stars: 0
tags:
  - litert
  - tflite
  - on-device
  - android
  - gpu
  - image-restoration
  - denoising
  - nafnet
---

# NAFNet-SIDD-width32-LiteRT

> NAFNet-SIDD-width32-LiteRT - litert-community 在 ModelScope 开源的模型。Measured on device (edge-compat): Galaxy S26 · LiteRT 2.2.0 · GPU (ML Drift) · 37.3 ms p50 (2026-08-26); Galaxy S26 · LiteRT 2.2.0 · NPU (QNN/HTP) · 26.3 ms p50 (2026-08-26); Raspberry Pi 5 ·…

litert-community/NAFNet-SIDD-width32-LiteRT 是 ModelScope 魔搭社区上的image-to-image模型，采用 mit 许可，基于 megvii-research/NAFNet 构建。

- **Repository**: litert-community/NAFNet-SIDD-width32-LiteRT
- **License**: mit
- **Tasks**: image-to-image
- **Base model**: megvii-research/NAFNet
- **Tags**: litert, tflite, on-device, android, gpu, image-restoration, denoising, nafnet
- **Downloads**: 18
- **Stars**: 0
- **Last updated**: 2026-09-08

Source: https://www.modelscope.cn/models/litert-community/NAFNet-SIDD-width32-LiteRT

---

Measured on device (edge-compat): Galaxy S26 · LiteRT 2.2.0 · GPU (ML Drift) · 37.3 ms p50 (2026-08-26); Galaxy S26 · LiteRT 2.2.0 · NPU (QNN/HTP) · 26.3 ms p50 (2026-08-26); Raspberry Pi 5 · LiteRT 2.2.0.dev20260804 · CPU/XNNPACK, 4 threads · 1040 ms p50 (2026-08-31); browser · Chromium 151 on M4 Max · LiteRT.js 2.5.3 · WebGPU · 23.6 ms p50 · output differs from CPU (max rel diff 0.23) (2026-08-11). Record: https://github.com/john-rocky/edge-compat/blob/main/cards/nafnet-sidd-width32/CARD.md

# NAFNet-SIDD-width32 — LiteRT (on-device image denoising, fully-GPU)

[NAFNet](https://github.com/megvii-research/NAFNet) (Nonlinear Activation Free Network, ECCV 2022) image
restoration, converted to **LiteRT** and running **fully on the `CompiledModel` GPU** (ML Drift) on Android.
This is the **SIDD-width32** variant — real-image **denoising**. NAFNet is a U-Net of NAFBlocks with **no
activation functions** (SimpleGate = channel-split multiply), so the whole network is a clean CNN on the GPU.

![NAFNet-SIDD — noisy input | denoised (on-device LiteRT GPU)](samples/sample.png)

## On-device (Pixel 8a, Tensor G3 — verified)

| | |
|---|---|
| nodes on GPU | **2179 / 2179** LITERT_CL (full residency) |
| inference | **~46 ms** (256×256) |
| size | 62.5 MB (fp16) |
| accuracy | device output **== PyTorch (corr 0.999999)** — re-authoring is numerically exact |

```
image[1,3,256,256] (RGB [0,1]) →[GPU: NAFNet U-Net]→ denoised[1,3,256,256]
```

## Minimal usage

**Android (Kotlin, CompiledModel GPU)**

```kotlin
val model = CompiledModel.create(context.assets, "nafnet_sidd_width32_fp16.tflite",
    CompiledModel.Options(Accelerator.GPU), null)
val inputs = model.createInputBuffers()
val outputs = model.createOutputBuffers()
inputs[0].writeFloat(chw)            // [1,3,256,256] RGB in [0,1], NCHW
model.run(inputs, outputs)
val denoised = outputs[0].readFloat()    // [1,3,256,256] in [0,1]
```

**Python (desktop verification)**

```python
import numpy as np
from PIL import Image
from ai_edge_litert.interpreter import Interpreter

img = Image.open("noisy.jpg").convert("RGB").resize((256, 256))
x = (np.asarray(img, np.float32) / 255.0).transpose(2, 0, 1)[None]   # [1,3,256,256]

it = Interpreter(model_path="nafnet_sidd_width32_fp16.tflite"); it.allocate_tensors()
it.set_tensor(it.get_input_details()[0]["index"], x); it.invoke()
y = it.get_tensor(it.get_output_details()[0]["index"])[0]            # [3,256,256], [0,1]
Image.fromarray((y.transpose(1, 2, 0).clip(0, 1) * 255).astype(np.uint8)).save("restored.png")
```

A complete Android sample (image picker + before/after) is in the official
[google-ai-edge/litert-samples](https://github.com/google-ai-edge/litert-samples) repo under
`compiled_model_api/image_restoration`.

## How it converts (litert-torch)

Pure CNN (no activations). Three numerically-exact re-authorings, the headline being **SafeLayerNorm**:
NAFNet's residual stream grows large (|x|≈175 at the bottleneck), so the LayerNorm channel reductions
`Σ_c x` and `Σ_c (x−μ)²` (~15M) **overflow fp16 (max 65504)** on the Mali delegate (which computes in fp16
regardless of the model dtype) → a grid artifact. Doing the reductions in a down-scaled `x/S` domain (S=128)
and rescaling is exact and fp16-safe. Plus the Simplified Channel Attention `AdaptiveAvgPool2d(1)` →
`mean(3).mean(2)`, and the upsample `Conv2d(1×1)+PixelShuffle(2)` → depth-to-space `ZeroStuffConvT2d`.

Result: banned ops NONE, all tensors ≤4D, tflite-vs-torch corr **1.0**, device-vs-torch corr **1.0**.

A complete Android sample (image picker + before/after) is in the official
[google-ai-edge/litert-samples](https://github.com/google-ai-edge/litert-samples) repo under
`compiled_model_api/image_restoration` (push this `.tflite` in place of the deblur model).

## Performance

Measured on a **Pixel 8a** (Tensor G3, Android 16) with the standard TFLite [`benchmark_model`](https://ai.google.dev/edge/litert/models/measurement) tool — 10 warm-up runs then 50 timed runs, reported as the tool's mean.

| Runtime | Backend | Graph on GPU | Latency |
|---|---|---|---|
| LiteRT `CompiledModel` (`LITERT_CL`) | GPU | 2179 / 2179 | ~46 ms |
| TFLite `benchmark_model` (`TfLiteGpuDelegateV2`) | GPU (OpenCL) | 2179 / 2179 | 109.9 ms |
| TFLite `benchmark_model` | CPU (XNNPACK, 4 threads) | — | XNNPACK declined the graph |

**The two GPU rows are different runtimes, not a contradiction.** The `LITERT_CL` figure is the one recorded when this model shipped, taken through LiteRT's own `CompiledModel` accelerator — the path the Kotlin sample app and the LiteRT API use. The `TfLiteGpuDelegateV2` figure is the classic TFLite OpenCL delegate, measured with a tool anyone can download and re-run. They agree on how much of the graph the GPU takes; they disagree on speed, and the classic delegate is the slower of the two here. Read the `TfLiteGpuDelegateV2` row as a reproducible floor, not as this model's speed on LiteRT.

XNNPACK declines these fp16 graphs — it reports `failed to delegate DEPTHWISE_CONV_2D` and then fails to allocate tensors — so there is no usable CPU number. Disabling XNNPACK falls back to reference kernels, which measured about 20× slower than the GPU on models of this size and would not represent CPU inference anyone would ship.

## Snapdragon NPU (Hexagon)

The NPU is **1.42x faster** than the GPU (26.30 ms against 37.26 ms) and loads 7.14x faster (223 ms against 1594 ms).

| backend | compiled | inference (median / min) | load |
|---|---|---:|---:|
| NPU (Hexagon v81) | on-device JIT | 26.30 ms / 25.71 ms | 223 ms |
| GPU (Adreno) | — | 37.26 ms / 36.39 ms | 1594 ms |

Measured on a **Samsung Galaxy S26** (Snapdragon 8 Elite Gen 5 / SM8850, Hexagon v81, Android 16) with LiteRT `CompiledModel` 2.2.0, one accelerator per process, 5 warm-up runs then N=50 timed runs, median reported. Every run held thermal status `NONE` throughout. Headroom 0.72, where 1.0 is the throttling threshold.

**The NPU rows ran the published file unchanged.** LiteRT compiled it for the Hexagon on the device at first load. That first compile took 66 s here. The `load` column above is the cached load every later run pays. Recipe and the runtime libraries it needs: [NPU guide](https://github.com/john-rocky/hf-to-litertlm/blob/main/docs/android-npu.md).

GPU wiring: [GPU guide](https://github.com/john-rocky/hf-to-litertlm/blob/main/docs/android-gpu.md).

## Raspberry Pi 5 (CPU)

Measured on a Raspberry Pi 5 Model B Rev 1.1 (8 GB, Raspberry Pi OS 64-bit) with the LiteRT [`benchmark_model`](https://ai.google.dev/edge/litert/models/measurement) tool from litert-cli-nightly 0.2.0.dev20260805: CPU inference (XNNPACK, 4 threads), 3 invocations per file of 10 warm-up plus 50 timed runs (the tool caps a phase at 150 s, so very slow graphs run fewer — the Runs column is the actual timed total). The latency is the median across invocations; the spread is the min–max over all timed runs. No thermal throttling occurred during these runs (`vcgencmd get_throttled` stayed `0x0`).

| File | Inference (median) | Spread (min–max) | Runs | Peak memory |
|---|---:|---:|---:|---:|
| `nafnet_sidd_width32_fp16.tflite` | 1,039.8 ms | 1,032.8–1,084.5 ms | 150 | 369 MB |

## License

[MIT](https://github.com/megvii-research/NAFNet/blob/main/LICENSE). Upstream:
[megvii-research/NAFNet](https://github.com/megvii-research/NAFNet); weights NAFNet-SIDD-width32.
