Skip to content

[Performance] Memory leak in Python #18749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
franz101 opened this issue Dec 7, 2023 · 6 comments
Closed

[Performance] Memory leak in Python #18749

franz101 opened this issue Dec 7, 2023 · 6 comments
Labels
stale issues that have not been addressed in a while; categorized by a bot

Comments

@franz101
Copy link

franz101 commented Dec 7, 2023

Describe the issue

After deleting a session in python, the memory is still allocated (in the onnx runtime). Over time if multiple sessions are created this leaks to the memory getting overloaded. I attached a simple POC in colab

To reproduce

# RAM % before: 6.8
sessions = [ort.InferenceSession(model_path) for _ in range(500)]
del sessions
print(f"RAM % after: {psutil.virtual_memory().percent}")
# RAM % after: 63.6 (expected below 8%)

Further notebook:
https://colab.research.google.com/drive/1Q8OrYxt2PKGvXiWOw-LRjc7XV5mN7u1u#scrollTo=9UWHzgu76FaF

Urgency

This currently is crashing our production backend written in Python.

Platform

Linux

OS Version

Ubuntu 18.04

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.16.3

ONNX Runtime API

Python

Architecture

X64

Execution Provider

Default CPU

Execution Provider Library Version

No response

Model File

https://colab.research.google.com/drive/1Q8OrYxt2PKGvXiWOw-LRjc7XV5mN7u1u#scrollTo=9UWHzgu76FaF

Is this a quantized model?

Unknown

### Tasks
@franz101
Copy link
Author

franz101 commented Dec 7, 2023

Tagging:
@snnn, @TMVector and @jambayk

@franz101
Copy link
Author

franz101 commented Dec 7, 2023

Interestingly it worked in version onnx 1.8.1 and onnx runtime 1.6.0 (onnx/onnx#3293)
could be related to (#16117)

@yuslepukhin
Copy link
Member

@ShuaiShao93
Copy link

https://stackoverflow.com/questions/21053380/what-does-del-do-exactly

If you look at the notebook, there is gc.collect after del

Copy link
Contributor

This issue has been automatically marked as stale due to inactivity and will be closed in 30 days if no further activity occurs. If further support is needed, please provide an update and/or more details.

@github-actions github-actions bot added the stale issues that have not been addressed in a while; categorized by a bot label Jan 13, 2024
Copy link
Contributor

This issue has been automatically closed due to inactivity. Please reactivate if further support is needed.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale issues that have not been addressed in a while; categorized by a bot
Projects
None yet
Development

No branches or pull requests

3 participants