onnxruntime_backend icon indicating copy to clipboard operation
onnxruntime_backend copied to clipboard

Expose `session.use_device_allocator_for_initializers` in onnxruntime_backend to completely shrink arena

Open zeruniverse opened this issue 2 years ago • 0 comments
trafficstars

Description

memory.enable_memory_arena_shrinkage in ONNXRuntime backend does not release all arena after each run. After some research, I found session.use_device_allocator_for_initializers might need to be 1 in order to make arena shrinkage really work. See references:

https://github.com/microsoft/onnxruntime/issues/9509#issuecomment-951546580

https://github.com/microsoft/onnxruntime/issues/11801#issuecomment-1151505137

To Reproduce

Use any onnx model and config memory.enable_memory_arena_shrinkage to gpu:0. Use --log-verbose=1, execute one inference, and the last arena shrinkage message will tell it does not deallocate all memory.

Expected behavior

Expose session.use_device_allocator_for_initializers just like memory.enable_memory_arena_shrinkage as a configurable param in onnxruntime backend so shrinkage could be more complete.

ort_api->AddSessionConfigEntry(soptions, "session.use_device_allocator_for_initializers", string_value.c_str());

zeruniverse avatar Jan 16 '23 16:01 zeruniverse