SwinIR-M x4 (real-world SR, GAN) — ONNX (fp32 for DirectML, bf16 for the AMD Ryzen AI NPU)
Fixed-shape ONNX exports of 003_realSR_BSRGAN_DFO_s64w8_SwinIR-M_x4_GAN (SwinIR, medium size,
real-world super-resolution, 4x, trained with the BSRGAN degradation model and a GAN loss) by Jingyun Liang
et al., from the weights published in
JingyunLiang/SwinIR
(003_realSR_BSRGAN_DFO_s64w8_SwinIR-M_x4_GAN.pth, SHA-256
b9afb61e65e04eb7f8aba5095d070bbe9af28df76acd0c9405aeb33b814bcfc6).
*_fp32.onnxruns on any ONNX Runtime execution provider. It is used with DirectML on an AMD iGPU.*_bf16cast.onnxis for the ONNX Runtime VitisAI execution provider of Ryzen AI Software 1.8.0 on an XDNA2 NPU.
Input is RGB in [0, 1], float32, NCHW, 3 channels, 256x256 (a multiple of the 8x8 attention window).
Output is 1024x1024.
Files
| File | Input → output | Precision | Target | SHA-256 |
|---|---|---|---|---|
swinir_nchw_256x256_fp32.onnx | 1x3x256x256 → 1x3x1024x1024 | fp32 | DirectML / CPU | da09789b23d47f40d590157fa292dd6836f811e46479b35d69be5a1c942d6a7f |
swinir_nchw_256x256_bf16cast.onnx | 1x3x256x256 → 1x3x1024x1024 | bf16 (cast) | VitisAI EP | a7a402bf0ca1ed8d2f212dc247389c5d7e165525976d4fe2e99878a46b0a9bc7 |
How the files were made
- Weights → fixed-shape fp32 ONNX with
scripts/npu/export_spandrel.py --tile 256(loads the model through spandrel, opset 17, no dynamic axes, onnxsim). The exporter rewritesSlicenodes with negative bounds into positive ones, because the VAIML compiler of Ryzen AI 1.8.0 crashes on them (amd/RyzenAI-SW#397). The rewrite does not change the computation. - fp32 → bf16:
python -m quark.onnx.tools.convert_fp32_to_bf16 --input swinir_nchw_256x256_fp32.onnx --output swinir_nchw_256x256_bf16cast.onnx --format with_cast(AMD Quark, from the Ryzen AI 1.8.0 environment; no calibration data).
The full procedure is written up in docs/model-conversion.md; the NPU-specific findings for this model are in swinir-npu.md.
Running on the NPU
The VitisAI EP compiles the bf16 model with VAIML when the first session is created. On a Ryzen AI 7 PRO 350
this takes about 65 minutes and up to 25 GB of RAM (close other applications first); the result is cached
(cache_dir / cache_key session options) and later sessions start in seconds. The cache is tied to the
Ryzen AI Software and NPU driver versions, so it is not published here; compile it on the target machine.
Measured on a Ryzen AI 7 PRO 350 (XDNA2 NPU, Radeon 860M, 32 GB LPDDR5-8000, Ryzen AI SW 1.8.0, NPU driver 32.0.203.329), one 854x480 frame → 4x, 256x256 tiles, including tiling and merge, steady state:
| Execution | Time per frame | PSNR vs fp32 output |
|---|---|---|
| iGPU, DirectML, fp32 | 59 s | — |
| NPU, VitisAI EP, bf16, power mode Default | 82 s | 38.5 dB |
| NPU, VitisAI EP, bf16, power mode Turbo | 49 s | 38.5 dB |
This is a slow, high-quality model for still images. Details of the measurement are in tomhda/ryzen-ai-npu-super-resolution-notes.
License and attribution
The model weights are by Jingyun Liang and the SwinIR authors
(JingyunLiang/SwinIR; paper: SwinIR: Image Restoration Using
Swin Transformer, ICCVW 2021), released under the Apache License 2.0. The ONNX files here are format
conversions of those weights and carry the same license; the license text is in
LICENSE-Apache-2.0-SwinIR.txt.
This is an independent, personal conversion. It is not affiliated with or endorsed by AMD or the SwinIR authors. AMD, Ryzen and Ryzen AI are trademarks of Advanced Micro Devices, Inc.
These files are also the model kit of TOGU SCALER, a Windows upscaler that runs them on DirectML and on the Ryzen AI NPU.