fix: Tokenizer memory leak on initial high QPS#368
Open
albertoperdomo2 wants to merge 2 commits intollm-d:release/v0.4.0from
Open
fix: Tokenizer memory leak on initial high QPS#368albertoperdomo2 wants to merge 2 commits intollm-d:release/v0.4.0from
albertoperdomo2 wants to merge 2 commits intollm-d:release/v0.4.0from
Conversation
…zers Signed-off-by: Alberto Perdomo <aperdomo@redhat.com>
Signed-off-by: Alberto Perdomo <aperdomo@redhat.com>
Contributor
Author
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
This PR fixes tokenizer startup memory leak under high concurrency and makes eviction safe for in-flight requests. With recent v0.4.0 testing profiling, the issue was narrowed down to two main bugs:
singleflightload results were not reliably retained in the tokenizer LRU cache, allowing repeated same-model loads during startup bursts.Cache population after
singleflightalways happens in successful loads and ensures one model load is reused by subsequent requests.Tokenizers were never
Closed properly.Cache creation uses
lru.NewWithEvict(...)so cleanup logic runs on eviction.Eviction cleanup could close a tokenizer while it was still in use by active requests.
Use
refcountto manage the lifecycle and lock of tokenizers.Test plan
Create a dev image for the llm-d-inference-scheduler at rh-ee-aperdomo/llm-d-inference-scheduler:v0.4.0 with the fix, and run the benchmarks that showed the leak in the first place.
Related issues