A small PyTorch model trained slower on a ROCm iGPU than on the CPU, and the shared NVR detector got 20x slower

I moved a small audio classifier’s training from the CPU to the integrated AMD GPU of the same box, expecting a free speedup. On a quiet host the GPU step was slower, every process paid three minutes of kernel compilation despite a persistent cache, and the camera detector sharing that GPU slowed down up to 20x.

TL;DR: for a model of this size on a Radeon 680M iGPU, train on the CPU. If you must use the GPU while another service depends on it, poll that service’s latency and fall back to the CPU when it degrades.

The setup

The model belongs to an Android app that diagnoses car sounds. It uses an EfficientAT MobileNet encoder, mn10, with the bigger mn20 and mn30 as candidates. A home server retrains it nightly and hourly, in a cgroup capped at 4 GB of RAM.

The server’s GPU is a Radeon 680M (gfx1035), an iGPU that ROCm does not officially support. PyTorch 2.14.1+rocm7.2 runs on it by spoofing the gfx1030 target through HSA_OVERRIDE_GFX_VERSION, the same trick as in my earlier post about the Radeon 860M. Its 4 GB VRAM carve-out stayed almost empty: tensors lived in GTT, system RAM mapped for the GPU.

The same GPU runs the ONNX object detector of Frigate, an open-source NVR (network video recorder) watching 7 cameras. Its /api/stats endpoint reports the detector’s inference_speed in ms.

What I expected

A GPU, even integrated, should beat 8 CPU threads on convolutions. The first benchmark agreed. Batch 16, random 5 s clips at 32 kHz and SpecAugment on, on a host already busy with other jobs (load average around 22):

Config s/step first step
CPU fp32 4.11 5.5 s
GPU fp32 1.88 249 s
GPU fp16 autocast + GradScaler 1.40 211 s

A 2.9x speedup with fp16 (bf16 autocast was no faster on the GPU and 7x slower on the CPU). The 200+ s first step looked like a one-off JIT cost that MIOpen’s on-disk cache would absorb.

What actually happens

Then I measured real runs on a quiet host.

Three bar charts: an mn10 training step takes 0.9 s on CPU and 1.5 s on the GPU; MIOpen kernel compilation costs 194 s with a cold cache and 184 s with a warm one; Frigate's detector inference time goes from 55 ms idle to 213 ms with mn20 training on the GPU and 1155 ms with mn30

  • The GPU lost. An mn10 step took about 1.5 s on the GPU against about 0.9 s on the CPU. The earlier win came from a saturated CPU.
  • The cache barely helped. I pointed MIOPEN_USER_DB_PATH and MIOPEN_CUSTOM_CACHE_DIR at a persistent directory. Compilation still cost 194 s cold and 184 s warm, per process. A tenth of a 30-minute hourly job.
  • Frigate suffered. The detector went from 55 ms per inference to anywhere between 130 and 1155 ms during GPU training.

Nor did the bigger encoders need it. On the CPU, 3 epochs on the same 3,180-window training subset, tested on 82 held-out videos:

Encoder int8 size train time top-3 macro accuracy
mn10 7.8 MB 455–468 s 0.506 / 0.479 (seeds 1, 2)
mn20 16.5 MB 897–965 s 0.452 / 0.465
mn30 31.0 MB 1,543 s 0.423

Twice the cost for no gain on this small dataset. mn10 stayed.

The fix

The GPU path is now off. While it was on, a guard watched Frigate and moved training back to the CPU. A minimal generic version:

import json, time, urllib.request

def detector_ms(url="http://127.0.0.1:5000/api/stats"):
    with urllib.request.urlopen(url, timeout=3) as r:
        stats = json.load(r)
    speeds = [d.get("inference_speed") for d in stats.get("detectors", {}).values()]
    return max(float(s) for s in speeds if isinstance(s, (int, float)))

class GpuGuard:
    """Trips when the detector stays above factor x baseline for sustain_s seconds."""
    def __init__(self, baseline_ms, factor=2.0, sustain_s=120, interval_s=15, read=detector_ms):
        self.limit, self.sustain_s, self.interval_s = factor * baseline_ms, sustain_s, interval_s
        self.read, self.last, self.slow_since, self.tripped = read, 0.0, None, False

    def poll(self):
        now = time.monotonic()
        if self.tripped or now - self.last < self.interval_s:
            return self.tripped
        self.last = now
        if self.read() > self.limit:
            self.slow_since = self.slow_since or now
            self.tripped = now - self.slow_since > self.sustain_s
        else:
            self.slow_since = None
        return self.tripped

Take the baseline with detector_ms() before the job, call guard.poll() every step, and on True move the model and every tensor in optimizer.state to the CPU. Against a fake stats server (55 ms, then 213 ms) it tripped once the slowdown outlasted sustain_s. On the real server it tripped for mn20 (213 ms) and mn30 (1155 ms) after 2 to 5 minutes.

Why it works

My reading, not profiled: a small MobileNet is bound by kernel launches and memory traffic, and this iGPU reads the same DDR as the CPU, so the GPU’s bandwidth advantage is gone. Two processes on one GPU are not isolated either: the detector’s kernels queue behind the training kernels.

Two details matter:

  • Frigate’s inference_speed is a rolling average. Right after a GPU job it still read 128 ms against 55 ms quiet. A baseline sampled at that moment doubles the threshold. The production version stores the lowest pre-job value seen as the reference and expires it after 24 hours.
  • Falling back to the CPU changes the memory profile. After the switch, the mn20 and mn30 runs were killed by the 4 GB cap: DataLoader worker processes each hold their own copy of the data. On the CPU path, use num_workers=0.

What I did not test

One iGPU, one ROCm/PyTorch pair. No discrete GPU, where the conclusion is very likely different. The encoder comparison ran 3 epochs on a subset, so it does not say what a long-trained mn20 would do; the gaps are within the noise. I did not try other ways to skip MIOpen compilation (find modes, precompiled kernels).

Facts

context: Training a small EfficientAT MobileNet audio classifier with PyTorch ROCm on a Radeon 680M iGPU shared with Frigate's detector
problem: GPU step 1.5 s vs CPU 0.9 s, ~3 min MIOpen compile per process despite the cache, Frigate detector 55 ms -> up to 1155 ms
solution: Train on the CPU; on the GPU, fall back to CPU when Frigate inference_speed stays above 2x a quiet baseline for 2 min
verified_on: 2026-10-28
applies_to: PyTorch 2.14.1+rocm7.2, Radeon 680M gfx1035 (gfx1030 override), small CNNs on a shared GPU
does_not_apply_to: Discrete or dedicated GPUs, large models

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Retour en haut