microsoft / microsoft/onnxruntime-genai

Back-to-back inferences speed slowdown over time

Open
#737 10 comments 0 reactions 0 assignees View on GitHub
bug ep:DML model:transformer performance
Dominant language
C++
Stars
1.1k
Forks
354
Avg merge
2d 16h
Merged PRs (30d)
85

Description

I am experiencing inference speed slowdown when running our test scripts with just the library alone or using our server.
The slowdown usually happens after half an hour.

### My System

- Intel I7-13850HX
- Nvidia RTX1000 Ada
- 64GB System Ram

### Software

- [Phi-3 Mini 4k with awq 4 bit weights](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx)
- onnxruntime-genai-directml 0.3.0
- onnxruntime-directml 1.18.0

### Sample Code
For simple test, I use the following scripts:

```python
model = og.Model(r"D:\Data\onnx\directml\directml-int4-awq-block-128")
tokenizer = og.Tokenizer(model)
chat_template = '<|user|>\n{input} <|end|>\n<|assistant|>'
tokenizer_stream = tokenizer.create_stream()
text = "What is the capital of France?"
prompt = f'{chat_template.format(input=text)}'
times = []

for i in range(20000):
input_tokens = tokenizer.encode(prompt)
params = og.GeneratorParams(model)
params.try_graph_capture_with_max_batch_size(1)
params.input_ids = input_tokens
generator = og.Generator(model, params)

start = time.time()
result = ""

while not generator.is_done():
generator.compute_logits()
generator.generate_next_token()

new_token = generator.get_next_tokens()[0]
result += tokenizer_stream.decode(new_token)

time_diff = time.time() - start
times.append(time_diff)
print(len(result))
print(time_diff)

del generator
gc.collect()
print(np.mean(times))
```
### Screenshots
Here's a screenshot of the average response times when I test the server with a locust script, the behavior is similar to the script I provided above. You can see the inference time starts to growing significantly after 30 minutes.
![image](https://github.com/user-attachments/assets/20aae078-e4b5-4fcd-b4ea-87c41b419fe5)

### The question
I noticed when I have tokenizer_stream created outside the loop, the inference time increase is slower compared to create tokenizer_stream each time inside the loop. I wonder if the code I used to create and call the models is correct.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running the provided Python loop and the Locust server test, comparing runs with tokenizer_stream created outside versus inside the loop. Measure inference times and resource use through the reported 30-minute slowdown, then use those results to identify the affected lifecycle or backend path; done means the slowdown is reproduced, explained, and covered by a regression test or documented limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.