I quantized an audio model to int8 with onnxruntime’s quantize_dynamic, and the Android app’s onnxruntime version couldn’t run it. After a version bump it ran, so I tried the two Android execution providers to speed it up. Neither helped. Both changed the outputs past my tolerance.
TL;DR: quantize_dynamic emits ConvInteger, MatMulInteger and DynamicQuantizeLinear. onnxruntime 1.23.2 has no ConvInteger kernel for int8 (signed) weights, so I moved the app and the JVM tests to 1.31.0. XNNPACK and NNAPI take none of these ops, so stay on the CPU provider and tune its session options.
The setup
The app is an Android app that classifies car sounds. It records 10 s of audio and runs the model on two 5 s windows (160,000 samples each at 32 kHz). The model is an EfficientAT MobileNet audio encoder with small classification heads. It was exported to ONNX and quantized to int8 (7.8 MB). The log-mel front end is part of the ONNX graph. The STFT is two Conv1d layers with fixed DFT kernels, and the mel filterbank is a MatMul. So the app passes in the raw waveform, a [1, 160000] float tensor, and does no DSP in Kotlin. The quantization step leaves the front end in fp32:
import onnx
from onnxruntime.quantization import QuantType, quantize_dynamic
fp32 = onnx.load("model_fp32.onnx")
frontend_node_names = [n.name for n in fp32.graph.node if n.name.startswith("/model/frontend/")]
quantize_dynamic(
"model_fp32.onnx", "model_int8.onnx",
weight_type=QuantType.QInt8,
nodes_to_exclude=frontend_node_names, # the DFT Conv1d + mel MatMul stay fp32
)
JVM unit tests run the same model through the desktop onnxruntime artifact; the app uses onnxruntime-android.
What I expected
I expected an int8 ONNX file to be portable. quantize_dynamic is onnxruntime’s own tool, so I assumed every onnxruntime build could run what it writes. I also expected XNNPACK or NNAPI to beat the plain CPU provider on a quantized convolutional model.
What actually happens
Loading. With onnxruntime 1.23.2, the real int8 encoder couldn’t be loaded. My notes record the cause, not the exact error text: 1.23.2 has no ConvInteger kernel for int8-weight inputs. I fixed it by moving both artifacts to one version (pinned in the Gradle version catalog), so the JVM tests can’t pass on a runtime the phone doesn’t have:
[versions]
onnxruntime = "1.31.0"
[libraries]
onnxruntime-android = { group = "com.microsoft.onnxruntime", name = "onnxruntime-android", version.ref = "onnxruntime" }
onnxruntime-jvm = { group = "com.microsoft.onnxruntime", name = "onnxruntime", version.ref = "onnxruntime" }
Providers. On 1.31.0, on an x86_64 emulator with 4 vCPUs, I compared outputs against the CPU provider with a 1e-3 tolerance:
- XNNPACK: same speed, +15 to +33 MB of native memory, outputs off by up to 9e-3.
- NNAPI: 2x slower, outputs off by up to 9e-3.

The fix
Stay on the CPU provider and set the session options. This is the setup the app ships with:
val threads = (Runtime.getRuntime().availableProcessors() / 2).coerceIn(1, 4)
val opts = OrtSession.SessionOptions().apply {
setIntraOpNumThreads(threads)
setInterOpNumThreads(1)
setExecutionMode(OrtSession.SessionOptions.ExecutionMode.SEQUENTIAL)
setCPUArenaAllocator(true)
setMemoryPatternOptimization(false)
}
val session = env.createSession(modelBytes, opts)
// one direct buffer, reused for every 5 s window
val input = ByteBuffer.allocateDirect(160_000 * 4).order(ByteOrder.nativeOrder()).asFloatBuffer()
fun run(wave: FloatArray, offset: Int) {
input.clear(); input.put(wave, offset, 160_000); input.flip()
OnnxTensor.createTensor(env, input, longArrayOf(1, 160_000)).use { w ->
session.run(mapOf("wave" to w)).use { /* read outputs */ }
}
}
run(FloatArray(160_000), 0) // warm-up right after loading
I measured the app on the emulator with the same recording, 9 analyses per build. The time to result covers both windows, an audio-quality check, a spectrogram and saving the recording. It went from 617–1213 ms (median ~900) to 496–668 ms (median ~530). The native heap after the analyses went from ~61.4 MB to ~51 MB.
Why it works
Both providers fail for the same reason. Dynamic quantization produces integer ops (ConvInteger, MatMulInteger) fed by DynamicQuantizeLinear, which computes the activation scale at run time. Neither XNNPACK nor NNAPI takes those ops. So the heavy part of the model falls back to the CPU provider anyway, with extra copies between the provider and the CPU. That fits what I measured: no speedup, more memory, and with NNAPI a slowdown. I didn’t track down which nodes cause the 9e-3 drift. For me it was enough that both providers missed the tolerance and neither was faster.
What each CPU option bought, as measured:
- Threads. On the desktop JVM, 1 thread took 1219 ms, 2 threads took 886 ms and 4 threads took 487 ms (all outputs identical). 8 threads did no better than 4, so half the cores, capped at 4, is the default.
- Memory pattern off. Native heap of one session after an analysis fell from 45.5 MB to 28.0 MB, with no visible speed change. I kept the arena. Turning it off saved 34 MB but made inference about 20% slower.
- Direct buffer. Each window used to be a
copyOfRangeplus a 640 KB JNI copy. Now it’s aputinto a buffer native code reads directly. - Warm-up. The first
runpays for one-time initialization, and that now happens at load time instead of during the user’s first analysis.
If you’re also weighing static quantization instead, I wrote about a trap with static int8 and tiled inference.
What I did not test
- I didn’t bisect the versions. 1.23.2 failed and 1.31.0 works. I haven’t tested anything in between.
- The 900 → 530 ms gain is for all four changes together. I didn’t measure each change separately in the app, and the standalone benchmark on the emulator was too noisy to rank them.
- All on-device numbers come from one x86_64 emulator. I didn’t run the provider comparison on a real ARM phone, where NNAPI might map to an NPU.
- I didn’t try a QDQ (static) export, which XNNPACK and NNAPI are more likely to accept.
Facts
context: Android app running a quantize_dynamic int8 ONNX audio model (log-mel front end inside the graph) with onnxruntime-android
problem: onnxruntime 1.23.2 had no ConvInteger kernel for int8 weights; XNNPACK and NNAPI don't take ConvInteger/MatMulInteger/DynamicQuantizeLinear and drifted 9e-3
solution: use onnxruntime 1.31.0 (1.23.2 fails) for app and JVM tests; CPU provider, threads = cores/2 in 1..4, memory pattern off, reused direct FloatBuffer, warm-up run
verified_on: 2026-10-26
applies_to: onnxruntime-android 1.31.0, dynamic int8 (QInt8 weights) models, x86_64 Android emulator
does_not_apply_to: QDQ/static-quantized models; real-device NPUs via NNAPI (untested)