onnxruntime CoreML execution provider leaks ~70-78 KB per inference on macOS (RF-DETR default config)
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Active
- Tech stack
- macos, python
- Domain
- performance
Research direction
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.
Written by the indexing model from the issue text.
Description
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).
- Dominant language
- Python
- Stars
- 2.5k
- Forks
- 340
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 92
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from roboflow/inference
-
Allow Pillow 13 in inference-sdkMay be free again A pull request for this issue was closed without being merged. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
roboflow/inference#3335 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
roboflow/inference#3173 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
roboflow/inference#2993 · 2 comments ·
Maintainers usually reply within 1 day
-
Add context manager (__enter__ / __exit__) support to InferencePipelinePossibly taken @KushagraKanaujia claimed this 67 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
roboflow/inference#2744 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
roboflow/inference#1913 · 1 comment · 2 reactions ·
Maintainers usually reply within 1 day
All issues in roboflow/inference
Similar issues
-
area:core-platform effort:S priority:P3 risk:night-safe status:ready type:test
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
randomparity/kdive#3620 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
FinanceFlash/unvibecode#760 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
google-research/google-research#3470 ·
Maintainers usually reply within 21 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
mrvautin/ha-workouts#11 ·