mem: Disable ONNX memory pattern on layout model sessions
Summary
ONNX Runtime's memory pattern (SessionOptions.enable_mem_pattern) plans buffers from the first run's allocations and keeps them resident for reuse. For the YoloX layout model this keeps about 120 MiB more RSS per session without making later runs faster. This disables it for the YoloX and Detectron2 sessions and keeps the CPU memory arena on.
Supersedes #495, which disabled both enable_mem_pattern and enable_cpu_mem_arena behind an ONNX_DISABLE_MEMORY_ARENA env var. Measured separately, the arena doesn't save memory here, and the pattern is safe to turn off by default, so this drops the arena change and the env var. #495 also could no longer be updated in place, and its tip had an unresolved conflict marker in CHANGELOG.md.
Impact
Single YoloX session, 1×3×1024×768 input, warm runs (macOS, CPU provider):
| Options | Peak RSS | Per run |
|---|---|---|
| default | ~700 MiB | 0.85–0.90 s |
enable_mem_pattern=False (this PR) | 580 MiB | 0.83–0.88 s |
| both disabled (#495 with env var) | 641 MiB | 0.86 s |
enable_cpu_mem_arena=False only | 758 MiB | 1.21 s |
End to end, process_file_with_model on sample-docs/layout-parser-paper.pdf (16 pages, YoloX), two paired runs:
| Peak RSS | Output hash | |
|---|---|---|
main | 1008 / 1013 MiB | 34aee4cf5cdb |
| this PR | 893 / 892 MiB | 34aee4cf5cdb |
The hash covers every page's element coordinates, probabilities and class ids. Wall time was no slower; it was noisy on a busy machine.
Verification
- New tests assert that both models create their session with
enable_mem_pattern=Falseandenable_cpu_mem_arena=True. They fail onmainand pass here. make test: 381 passed, 1 skipped.ruff check/ruff format --checkclean.
Measured only with the CPU execution provider; enable_mem_pattern is a CPU-side planning option, but a CUDA/TensorRT check before release would confirm.
Version bumped to 1.6.17 with a CHANGELOG entry. #530 and #531 also target 1.6.17, so later merges need the next patch version.