microsoft / microsoft/onnxruntime-genai

.Net How to free GPU memory after each inference

Open
#1,131 8 comments 0 reactions 1 assignee View on GitHub

@RyanUnderhill is already working on this.

Since Apr 9, 2025.

bug enhancement performance
Dominant language
C++
Stars
1.1k
Forks
354
Avg merge
2d 16h
Merged PRs (30d)
85

Description

I am using Phi3.5mini-cuda-fp16 With A Nvida GPU (24G Memory).

When i load model Memory is 8490MiB in use.

![Image](https://github.com/user-attachments/assets/0d708988-4e50-487d-82dc-a9253144dca1)

When I entered an inference of about 3K tokens, the GPU Memory used 10580MiB

![Image](https://github.com/user-attachments/assets/5ea2f74a-4692-4a5d-aad1-946212ce5f2e)

If I continue the conversation afterwards, GPU memory will continue to rise

![Image](https://github.com/user-attachments/assets/4aaf51e1-bd57-4ef7-bba9-c0b0e2737be7)

If I am not having a conversation, even if I leave it for an hour, the memory will not decrease.

I don't know if this is a bug, as this phenomenon seems to have existed since 0.4, and the same goes for 0.5.2
**Or did I miss something?**

This is My code ,I did not forget to release any object, of course, the Model object was not released because we need to reuse it
![Image](https://github.com/user-attachments/assets/94fbd666-0d1b-42db-a062-f207bcfbda23)

Contributor guide

No contributing guide indexed for this repository

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.