microsoft / microsoft/onnxruntime

[Feature Request] Manual VRAM flushing or automatic flushing after OOM error

Open
#11,740 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request
Dominant language
C++
Stars
21.9k
Forks
4.2k
Avg merge
4d 8h
Merged PRs (30d)
179

Description

I implement automatic CUDA out-of-memory detection in my program that detects when an image is too large and tiles it accordingly. This is done via catching when an OOM error happens and increasing the amount it splits until it is able to run properly. However, this requires being able to clear the VRAM being used before trying again, which ONNX seems to a) not do automatically, and b) not have any option of doing. I would prefer to not have to continually redefine an inference session every time I want to clear memory.

Therefore, I would like to have a method that allows the VRAM being used to process the input to be flushed.

System information

  • ONNX Runtime version: 1.11.1

Describe the solution you'd like

I would like to have a method available that allows the current in-use VRAM to be cleared without having to define a new session. Or at the very least, VRAM should be flushed when an out-of-memory error happens (similar to how PyTorch handles it)

Describe alternatives you've considered
I attempted to redefine the session variable, yet I get a "MemoryError: bad allocation" when I attempt to do that. Besides, if I were to define a new session every time I wanted to try a new split factor, it would take a long time to initialize every time, which I would like to avoid.

Additional context
Basically just go look at what torch does. It clears out the VRAM automatically when it encounters a CUDA OOM, which allows the feature I described to work. NCNN does not clear automatically, however since it just uses manually defined Vulkan blob allocators, I am able to flush it myself. However, neither option is available with onnxruntime

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no source files, tests, or entry points; begin by locating ONNX Runtime’s CUDA out-of-memory handling and the lifetime of an inference session’s GPU allocations. Compare the requested manual flush and post-OOM behavior with session reuse, and define done as reclaiming VRAM without recreating the session while allowing a retry after OOM.

Written by the indexing model from the issue text.

Assessment

Domain
machine-learning, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.