Skip to content

Commit 9678c7b

Browse files
committed
mem: disable ONNX mem_pattern and cpu_mem_arena to reduce idle memory
Set enable_mem_pattern=False and enable_cpu_mem_arena=False on SessionOptions for both YoloX and Detectron2 ONNX sessions. These flags control pre-allocation strategies that trade memory for speed on repeated inference. With both disabled, peak memory drops ~36% (553→351 MB) on the YoloX model with negligible latency impact.
1 parent 44da8d8 commit 9678c7b

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
- Store routing in LayoutElement
44

5+
### Enhancement
6+
- Disable ONNX Runtime memory pattern and CPU memory arena on YoloX and Detectron2 sessions to reduce idle memory after inference
7+
58
## 1.5.2
69

710
### Fix

unstructured_inference/models/detectron2onnx.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,13 @@ def initialize(
115115
]
116116
providers = [provider for provider in ordered_providers if provider in available_providers]
117117

118+
sess_options = onnxruntime.SessionOptions()
119+
sess_options.enable_mem_pattern = False
120+
sess_options.enable_cpu_mem_arena = False
121+
118122
self.model = onnxruntime.InferenceSession(
119123
model_path,
124+
sess_options=sess_options,
120125
providers=providers,
121126
)
122127
self.model_path = model_path

unstructured_inference/models/yolox.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,13 @@ def initialize(self, model_path: str, label_map: dict):
8080
]
8181
providers = [provider for provider in ordered_providers if provider in available_providers]
8282

83+
sess_options = onnxruntime.SessionOptions()
84+
sess_options.enable_mem_pattern = False
85+
sess_options.enable_cpu_mem_arena = False
86+
8387
self.model = onnxruntime.InferenceSession(
8488
model_path,
89+
sess_options=sess_options,
8590
providers=providers,
8691
)
8792

0 commit comments

Comments
 (0)