onnxruntime CoreML execution provider leaks ~70-78 KB per inference on macOS (RF-DETR default config)
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Da chiarire
- Stato di attività
- Attiva
- Stack tecnologico
- macos, python
- Ambito
- performance
Direzione di ricerca
Start by reading inference_models/inference_models/models/common/onnx.py, especially get_default_coreml_provider_options, to understand the CoreML options used by default. The standalone reproduction script is on the reporter’s machine and can be attached on request; first ask for it, then compare memory growth with CoreML and CPU providers. Done means the native memory growth per inference is explained and a fix or agreed mitigation is established.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
On macOS, running an ONNX model through onnxruntime's CoreMLExecutionProvider with the options inference_models sets by default for RF-DETR (ModelFormat=MLProgram, MLComputeUnits=CPUAndGPU, see inference_models/inference_models/models/common/onnx.py, get_default_coreml_provider_options) grows process memory by roughly 70-78 KB per session.run call. At 30 inferences per second that is about 1.9-2.0 MB/s, or 6-7 GB per day. The leak is native (not in the Python heap) and is present without any Roboflow code in the loop.
Found while validating an unrelated Workflows feature; it is not caused by that work.
Evidence
Mac M4 Max, macOS 27.0.1, Python 3.10, rfdetr-nano (coco/40 weights). Memory is phys_footprint sampled every second; slopes are linear fits for t >= 30 s.
| Run | Growth |
|---|---|
InferencePipeline + RF-DETR + visualizations, pristine main (18eb2936e) |
+1.95 MB/s, R² 0.98 |
| Model only through the workflow engine | +1.90 MB/s, R² 0.99 |
Model only with ONNXRUNTIME_EXECUTION_PROVIDERS=CPUExecutionProvider |
flat (-0.18 MB/s) |
| Passthrough workflow, no model | flat |
Bare onnxruntime 1.21.1 loop, CoreML MLProgram CPUAndGPU, no Roboflow code |
+1.43 MB/s at 18.4 it/s = 78 KB per call, R² 1.00 |
| Same loop, onnxruntime 1.31.1 (latest) | +1.96 to 2.15 MB/s at 28.7 it/s |
CoreML MLProgram, MLComputeUnits=CPUOnly |
flat, 14.8 it/s |
| CoreML NeuralNetwork format | flat, but 3 it/s and a 3.7 GB footprint |
Objective-C autorelease pool pushed/popped around each run |
still +2.35 MB/s |
tracemalloc shows the Python heap shrinking while RSS grows (94.8 to 84.3 MB traced vs +180 MB process over the same 180 s), so nothing Python-side accumulates. The leak is in the MLProgram GPU path.
Repro
A standalone script that loads the cached rfdetr-nano weights with the same CoreML options and runs a paced loop while sampling memory lives at ~/Code/vision-event-clips/scripts/g1.9/ort_loop.py on Brad's machine (can be attached on request):
python ort_loop.py --provider coreml --seconds 300 --fps 30 --label coreml # leaks
python ort_loop.py --provider cpu --seconds 300 --fps 30 --label cpu # flat
Impact
Any long-running RF-DETR (or other MLProgram-opted-in model) deployment on macOS with the default provider options, e.g. InferencePipeline on a Mac for hours.
Mitigation candidates
MLComputeUnits=CPUOnlyfor CoreML: no leak, about half the throughput (14.8 vs 30 it/s on this model).- Periodic
InferenceSessionrecycling in the ONNX model wrapper. - Upstream report to onnxruntime with the bare-loop repro (1.21.1 and 1.31.1 both affected).
- Lingua principale
- Python
- Stelle
- 2.5k
- Fork
- 340
- Merge medio
- 2g 11h
- PR unite (30g)
- 92
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di roboflow/inference
-
Allow Pillow 13 in inference-sdkForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
roboflow/inference#3335 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
roboflow/inference#3173 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
roboflow/inference#2993 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Add context manager (__enter__ / __exit__) support to InferencePipelineForse già presa @KushagraKanaujia l’ha presa 67 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
roboflow/inference#2744 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
roboflow/inference#1913 · 1 commento · 2 reazioni ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di roboflow/inference
Issue simili
-
area:core-platform effort:S priority:P3 risk:night-safe status:ready type:test
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
randomparity/kdive#3620 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
FinanceFlash/unvibecode#760 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
google-research/google-research#3470 ·
I maintainer di solito rispondono entro 21 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
mrvautin/ha-workouts#11 ·