#1024·rf-detr

Expand model export format support

Author: BordaCreated May 4, 2026Updated Sep 23, 2026
Labelsenhancement

Expand model export format support

Updated 2026-07-30 — re-audited against develop @ c3294a5 (version 1.9.0). Since this issue was opened, the TFLite runtime failure has been fixed, TensorRT has been promoted to a first-class format=, and ExecuTorch + native CoreML have landed. Original text preserved where still accurate; per-format sections now cite the PR that added the capability and the release that shipped it.

Context

RF-DETR now exposes five first-class export formats through RFDETR.export(format=...). This issue audits the broader CV deployment ecosystem, records current coverage on develop, and tracks the remaining gaps.

Industry-share figures below are directional estimates, not precise telemetry — they aggregate signals from the Ultralytics export ecosystem, ONNX/TensorRT/CoreML deployment surveys, edge-AI framework reviews, and visible community usage.

Current state in develop

Verified by inspection of src/rfdetr/export/ and RFDETR.export() in src/rfdetr/detr.py:

  • RFDETR.export(format=...) accepts "onnx" (default), "tflite", "tensorrt" (alias "trt"), "executorch" (alias "pte"), and "coreml" (detr.py:1431).
  • src/rfdetr/export/ is now a package with per-backend subpackages: _onnx/, _tflite/, _tensorrt.py, _executorch/, _coreml/, plus a shared ExporterProtocol in protocols.py and dispatch in _backend.py.
  • The TFLite runtime failure flagged in the original issue is resolved. Fixed by #1041 (onnx2tf 2.4) and #1054 (ONNX-level GridSample rewrite), both released in 1.7.0; numerical parity with predict() closed by #1131 in 1.8.2.
  • TensorRT is no longer a --tensorrt CLI post-step shelling out to trtexec — it builds through the TensorRT Python API via polygraphy (#853, 1.9.0).
  • TorchScript remains in-process only via optimize_for_inference(compile=True) → torch.jit.trace. Not a saveable export format. Unchanged.
  • Optional dependency groups in pyproject.toml: [onnx], [tensorrt], [tensorrt-bench], [tflite], [executorch], [coreml].
  • Unreleased on develop: output_name + unified artifact naming across all backends (#1250).

Overview

Format Status on develop (1.9.0) Added by Released in Est. industry share RF-DETR architectural risk
ONNX ✅ First-class pre-existing — ~30% (server) Low — F.grid_sample exports cleanly
TensorRT ✅ First-class format="tensorrt" #853, #1231 1.9.0 ~30% (server) Low — no custom plugins
TFLite / LiteRT ✅ Functional (FP32/FP16/INT8) #920, #1041, #1054, #1131 1.7.0 / 1.8.2 ~30% (edge) Medium — GridSample rewrite carries the path
ExecuTorch (umbrella) ✅ First-class format="executorch" #1142 1.9.0 ~3–5% (edge, growing) Medium — fixed batch only
├ backend="xnnpack" ✅ Portable CPU, fp32 #1142 1.9.0 — (spans all edge CPU) Low
├ backend="coreml" ✅ ANE/GPU/CPU delegate, fp16 #1142 1.9.0 — (see CoreML) Medium — ANE partitioning
└ backend="qnn" ✅ Snapdragon HTP, fp16 #1142 1.9.0 ~5–8% (edge) High — HTP op coverage, on-device unvalidated
CoreML (native) ✅ First-class format="coreml" #1235 1.9.0 ~15% (edge) Medium — ANE fallback, numeric-parity flakiness
TorchScript / .pt ⚠️ In-process only, not saveable — — ~20% (server) Low — native PyTorch
OpenVINO IR ⚠️ In-process only, works via ONNX externally #1238 — ~5% (server) Low — IR consumes ONNX directly
ONNX Runtime Mobile/Web ❌ No direct hook (consumes ONNX as-is) — — ~10% (edge) Low
Hailo HEF ❌ Missing — — ~2–3% (edge) High — grid_sample is the sticking point
Rockchip RKNN ❌ Missing — — ~2–3% (edge) High — grid_sample + mandatory INT8
NCNN / MNN ❌ Missing — — ~3–5% (edge) Medium — DETR-family op coverage uneven

A note on how these rows relate

The rows above are not all the same kind of thing, and treating them as peers is what makes the export surface confusing to read. There are two axes:

  • Serialization target — what artifact lands on disk: .onnx, .trt, .tflite, .pte, .mlpackage.
  • Delegation backend — what hardware actually executes the graph at runtime.

ONNX, TFLite, TensorRT, and native CoreML collapse both axes into one: the file format implies the runtime. ExecuTorch does not. It is a wrapper runtime with a pluggable backend layer — one .pte serialization, with the hardware target chosen at export time by the backend argument and baked into the delegated subgraphs. So format="executorch" is not a peer of format="coreml"; it is a container that can contain a CoreML delegate, a Qualcomm HTP delegate, or an XNNPACK CPU fallback.

Practical consequence: ExecuTorch's row in the table is not really "~3–5% of edge" — its addressable share is the union of whatever backends are wired into it. Today that union already covers Apple silicon and Snapdragon HTP, i.e. it overlaps both the CoreML and QNN rows. Upstream ExecuTorch also ships Vulkan, MPS, Arm Ethos-U, and Cadence backends that RF-DETR has not wired; each is a backend= addition rather than a new export format, which is a materially cheaper unit of work than any of the remaining ❌ rows. That is the main reason to think of ExecuTorch as strategic surface rather than as one more format.

Per-format report

ONNX

Why it matters. Universal exchange format and the foundation for nearly every downstream target — TensorRT, OpenVINO, ORT Mobile/Web, ORT desktop, onnx2tf → TFLite, Hailo SDK, RKNN compiler. Effectively the single source of truth for deployment.

Status. First-class. Opset 17 default (_onnx/exporter.py:170), dynamic batch supported, backbone-only and segmentation-head outputs wired in.

RF-DETR specifics. Deformable attention uses F.grid_sample (pure PyTorch) — exports cleanly without custom plugins.

Remaining work. None blocking. Opset default is still 17; consider raising to 18/19 to unlock newer ops in downstream consumers.


TensorRT

Why it matters. Production default on NVIDIA datacenter GPUs and Jetson edge devices. Layer fusion, kernel auto-tuning, and FP16/INT8 yield 2–5× over raw ONNX Runtime on the same hardware.

Status. ✅ Resolved — the API asymmetry called out in the original issue is gone. RFDETR.export(format="tensorrt") (alias "trt") builds the engine through the TensorRT Python API via polygraphy, with no trtexec subprocess (#853, 1.9.0). An explicit fp16 argument was added in #1231 (1.9.0), and the builder automatically downgrades to FP32 with a warning on TensorRT builds that do not expose the FP16 flag. Engine filenames carry an _fp16 / _fp32 suffix.

RF-DETR specifics. Pure-PyTorch deformable attention means no custom TRT plugins. Engines remain hardware-locked — rebuild per GPU arch (Turing / Ampere / Ada / Hopper).

Remaining work.

  1. INT8 calibration support (currently FP32/FP16 only).
  2. Optional: metadata sidecar with build args for reproducibility.

TorchScript

Status. Unchanged — implemented via torch.jit.trace inside optimize_for_inference (detr.py:1232), not exposed as a standalone export format.

Remaining work. Still the same open decision, and the original recommendation now looks stronger: leave it as an in-process optimization. With format="executorch" shipped, the torch.export-native path is available and TorchScript has no remaining unique role.


TFLite / LiteRT

Why it matters. ~30% of edge CV deployment runs through TFLite — Android (NNAPI), Coral Edge TPU, microcontrollers, and increasingly cross-platform via the LiteRT rebrand.

Status. ✅ Functional. The non-functional-artifact bug that was the top priority in the original issue is fixed:

PR What it did Released in
#920 Initial TFLite export, FP32/FP16/INT8 + calibration-data API 1.7.0
#1041 Move to onnx2tf ≥ 2.4 1.7.0
#1053 Decode segmentation masks in TFLite inference 1.7.0
#1015 Sigmoid scoring + shape-based output fallback 1.7.0
#1054 ONNX-level GridSample → bilinear-Gather rewrite 1.7.0
#1131 Match predict() preprocessing and mask decoder 1.8.2

The root cause was the GridSample lowering, exactly as suspected. onnx2tf's built-in handler lowers GridSample to tf.gather_nd(batch_dims=1), which TFLite's GatherNd does not support, and the replace_to_pseudo_operators=["GridSample"] path produced numerically wrong logit magnitudes. #1054 instead rewrites every GridSample node in the ONNX graph — before onnx2tf runs — into an explicit four-corner bilinear-sampling subgraph that is mathematically identical to F.grid_sample for mode="bilinear" (_tflite/converter.py:91, :402). Six rewrites, one per decoder layer. Patched artifacts carry a _gs_patched infix in the filename; this is the standard RF-DETR path.

Remaining work.

  1. CLI plumbing is still open — --tflite, --quantization, --calibration-data, --max-images are still unregistered in the argparser (TODO at src/rfdetr/export/main.py:326). Until then, TFLite export is Python-API only.
  2. Document a known-good INT8 calibration recipe (image count, normalization, expected AP delta).
  3. Explicitly scope supported targets: GPU delegate vs. NNAPI vs. Edge TPU. Edge TPU is likely out of scope (INT8-only, restricted op set, and the bilinear subgraph is unlikely to map).

ExecuTorch — a multi-backend wrapper, not a single target

Why it matters. PyTorch's modern edge runtime, replacing PyTorch Mobile. The important structural point is that ExecuTorch is not one deployment target — it is a delegation layer over many. The .pte container is constant; what varies is which partitioner claims which subgraphs and which vendor runtime executes them. Adding hardware coverage through ExecuTorch means adding a backend= value, not implementing a new exporter, so the marginal cost of each additional target is far below what a standalone format (Hailo, RKNN, OpenVINO) costs. That makes ExecuTorch the highest-leverage row in the table even though its standalone adoption share is the smallest.

Status. ✅ Shipped — RFDETR.export(format="executorch") (alias "pte"), added in #1142, released in 1.9.0. Requires pip install rfdetr[executorch] (executorch>=1.3,<2.0, validated on 1.3.1). backend is required (there is no default — the SoC/runtime choice is not inferable) and accepts:

backend= Executes on Precision Extra requirement Artifact portability
"xnnpack" Any edge CPU fp32 none Portable across devices
"coreml" Apple ANE / GPU / CPU fp16 coremltools Portable across Apple devices
"qnn" Qualcomm Snapdragon HTP fp16 ExecuTorch source build against QAIRT SDK; soc (e.g. "SM8650") SoC-locked — recompile per chipset

Each backend takes a different route through the toolchain rather than sharing one lowering path. XNNPACK and CoreML go through the generic to_edge_transform_and_lower partitioner (_executorch/converter.py:165); QNN needs its own entry point (to_edge_transform_and_lower_to_qnn) plus a non-strict export shim, because ExecuTorch 1.3.1 exports with strict=True, which RF-DETR's graph does not survive (_executorch/converter.py:194). Expect any future backend to need comparable per-backend handling — "wrapper" describes the artifact and the API, not the implementation effort.

The feasibility question in the original issue is answered: torch.export accepts the RF-DETR forward.

Backends upstream ExecuTorch supports that RF-DETR has not wired. Vulkan (cross-vendor mobile GPU), MPS (Apple GPU without the CoreML stack), Arm Ethos-U (microNPU), and Cadence/HiFi DSP. None of these require a new export format — each is a partitioner plug-in behind the same format="executorch" call. Vulkan is the most interesting unclaimed one, since it is the only path in the whole table that would reach Android GPUs across vendors without going through TFLite/NNAPI.

Overlap to be aware of. backend="coreml" and format="coreml" target the same silicon by different routes — a delegated .pte versus a native .mlpackage. They are not interchangeable, and the .mlpackage route is the better-tested one for detection and segmentation today.

Limitations. dynamic_batch=True raises NotImplementedError — fixed batch size only, across all backends. QNN additionally bakes the target SoC into the .pte.

Remaining work.

  1. On-device validation of the QNN path (accuracy + latency on real Snapdragon HTP) — the export path exists but the numbers do not.
  2. Evaluate the Vulkan backend as the cheapest route to broad Android GPU coverage.
  3. Document the backend-selection decision explicitly in docs/learn/export.md so users stop reading format="executorch" as a target rather than a container.

CoreML

Why it matters. Apple Silicon (M1–M4) + iPhone Neural Engine cover ~15% of the on-device CV market and are the de facto platform for privacy-preserving on-device inference.

Status. ✅ Shipped — RFDETR.export(format="coreml") produces a native .mlpackage (mlprogram) via torch.export + coremltools, with no ONNX step (#1235, released 1.9.0). Requires pip install rfdetr[coreml].

Note the distinction, since it is a live source of confusion: format="coreml" produces a .mlpackage, while format="executorch", backend="coreml" produces a .pte that delegates to CoreML at runtime. Passing format="coreml", backend="coreml" does not fall through to the ExecuTorch path.

RF-DETR specifics.

  • compute_precision defaults to FP32 for tight CPU parity; pass coreml_precision="fp16" for a smaller ANE-oriented bundle at the cost of numeric drift.
  • dynamic_batch=True raises NotImplementedError — fixed shapes are required for reliable ANE/GPU scheduling, matching the ANE-fallback concern raised in the original issue.
  • [coreml] pins torch<2.12 because of a CoreML/eager numeric-parity divergence bisected on 2026-07-28: on RFDETRNano with random-init weights, torch<2.12 failed ~1/6 repeat runs versus ~6/7 on torch>=2.12. The pin reduces the failure rate; it does not eliminate it. Root cause looks like a coremltools MIL lowering regression exposed by torch 2.12's export graph.
  • Detection and segmentation are covered by end-to-end tests; keypoint models are untested.

Remaining work.

  1. Root-cause the coremltools MIL numeric divergence upstream and lift the torch<2.12 cap.
  2. Benchmark ANE vs. GPU vs. CPU scheduling and document the fallback boundary so users have realistic latency expectations.
  3. Validate or explicitly exclude keypoint models.

OpenVINO IR

Why it matters. Default for industrial CV on Intel CPUs/iGPUs/VPUs. ~5% of server CV deployment.

Status. ❌ Still no first-class export. The only references in the repo are two documentation mentions in docs/learn/export.md. Works externally via the exported ONNX.

RF-DETR specifics. No architecture concerns — OpenVINO consumes ONNX directly, and GridSample-9 is a supported operator, so the deformable-attention path does not need the TFLite-style rewrite.

Remaining work. This is now the largest remaining gap in the table. Minimum viable version is a documentation recipe ("use the exported ONNX with ovc"); a format="openvino" wrapper that emits IR directly would match the symmetry the other four formats now have, with optional NNCF INT8 as a later phase.


ONNX Runtime Mobile / Web

Status. ❌ No direct hook. Works via the existing ONNX export.

RF-DETR specifics. Browser/WebGPU remains the most interesting target — in-browser RF-DETR demos for Roboflow Universe.

Remaining work.

  1. Document a known-good ORT Web recipe with the WebGPU EP and a latency ballpark.
  2. Validate segmentation-head outputs in ORT Mobile.

Hailo HEF, Rockchip RKNN, NCNN / MNN

Why they matter. NPU-specific runtimes covering the long tail of edge deployment — Hailo-8/15 industrial accelerators, RK3588 smart cameras, and Tencent/Alibaba mobile stacks.

Status. ❌ Missing across the board. (Qualcomm QNN, previously grouped here, is now reachable as an ExecuTorch backend and has moved under that row.)

Worth asking before building any of these standalone. Qualcomm was absorbed as a backend= value rather than as a new exporter, and Arm Ethos-U is available upstream on the same terms. The question for Hailo/RKNN/NCNN is therefore whether each vendor has (or would accept) an ExecuTorch partitioner, in which case the work collapses into the existing format="executorch" surface. Only where no such path exists does a standalone exporter make sense.

RF-DETR specifics (shared concerns).

  • F.grid_sample op coverage is the recurring blocker. #1054 established a working precedent — an ONNX-level rewrite into primitive gather/arithmetic ops — that could be reused for these toolchains, which materially lowers the estimated cost of each.
  • INT8 quantization is mandatory for most of these NPUs, and INT8 of the attention path typically regresses AP without QAT.

Remaining work. Still appropriate to defer to community contributions. Hailo is the highest-value if forced to pick.


Recommended priorities

P0 — Finish what shipped

  1. Wire TFLite CLI flags (src/rfdetr/export/main.py:326 TODO) — the only remaining piece of the original P0 block.
  2. Root-cause the CoreML numeric-parity divergence and lift the torch<2.12 pin.

P1 — Close the last first-class gap

  1. OpenVINO — either a documented ONNX recipe or a format="openvino" wrapper.
  2. On-device validation of the ExecuTorch QNN path.
  3. Expand ExecuTorch backend coverage (Vulkan first) — cheapest available hardware-reach per unit of work, since it reuses the shipped format="executorch" surface rather than adding an exporter.
  4. TensorRT INT8 calibration.

P2 — Documentation rather than code

  1. ONNX Runtime Web/Mobile recipe (browser demo enablement).
  2. INT8 calibration recipe for TFLite; ANE fallback boundary for CoreML.
  3. Document format="executorch" as a container with a required backend choice, not a target.
  4. Raise the default ONNX opset from 17.

P3 — Defer to community

  1. Hailo, RKNN, NCNN/MNN — check for an ExecuTorch partitioner first; otherwise reuse the #1054 GridSample-rewrite pattern.

Resolved since this issue was opened

  • Diagnose and fix the TFLite runtime failure → #1041, #1054 (1.7.0), #1131 (1.8.2)
  • Unify TensorRT under format="tensorrt" → #853 (1.9.0)
  • CoreML — largest deployable surface gap → #1235 (1.9.0)
  • ExecuTorch feasibility check → #1142 (1.9.0), including the QNN backend — which also absorbed the Qualcomm line item from the original P3 block

Industry-share figures are directional estimates. Happy to refine any per-format section with better data or counter-arguments.