Skip to content
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

how to release gpu memory when use onnxruntime with fastapi #22899

Open
SZ-ing opened this issue Nov 20, 2024 · 1 comment
Open

how to release gpu memory when use onnxruntime with fastapi #22899

SZ-ing opened this issue Nov 20, 2024 · 1 comment
Labels
api issues related to all other APIs: C, C++, Python, etc.

Comments

@SZ-ing
Copy link

SZ-ing commented Nov 20, 2024

This is probably a repetitive problem, but I still haven't found how to solve it.

I used FastAPI to build API interfaces and used onnxruntime to load models. However, due to the limited number of models and gpu memory, I hope to release this part of the occupied gpu memory after each interface call is completed. But it seems that I can never fully release it, and there will still be some models occupying gpu memory.

I want to know if there is any way to solve this problem for Python.

@amarin16 amarin16 added the api issues related to all other APIs: C, C++, Python, etc. label Nov 20, 2024
@skottmckay
Copy link
Contributor

The infererence session will have the weights for the model in memory at a minimum. Unless you free the session that will always remain the case.

You can potentially reduce memory usage by sharing allocators between sessions. The python API has create_and_register_allocator which calls into CreateAndRegisterAllocator mentioned in 'Share allocator(s) between sessions' here. This reduces the amount of unused memory from having multiple arenas, each with their own over-allocation.

See #6411 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api issues related to all other APIs: C, C++, Python, etc.
Projects
None yet
Development

No branches or pull requests

3 participants