-
Notifications
You must be signed in to change notification settings - Fork 1
add quantization support and response caching for performance improvements #40
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @lukehinds, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the performance and memory efficiency of the LLM inference server by integrating quantization techniques and a robust response caching system. It also introduces a more resilient asynchronous model loading process and lays the architectural foundation for advanced features like request batching and KV cache management. These changes aim to provide faster response times, reduce memory footprint, and improve the overall stability and observability of the service. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces significant performance and architectural improvements. The addition of quantization, response caching, and asynchronous model loading are excellent enhancements. The new ModelProvider and ChatTemplate traits greatly improve the codebase's modularity and extensibility. My review focuses on a few areas for improvement, including resolving a potential panic in a new health check endpoint, improving efficiency in lock handling, and updating documentation to reflect the new architecture. Overall, this is a very strong contribution.
| } else { | ||
| vec![] | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If model_state.get_model().await returns an error (e.g., due to a poisoned lock), the function silently returns an empty list of models. This could be misleading for clients. It would be better to log the error to aid in debugging.
} else if let Err(e) = model_lock {
tracing::error!("Failed to acquire model lock in list_models: {}", e);
vec![]
} else {
vec![]
};| batches_created, | ||
| avg_batch_size, | ||
| queue_size: self.queue_size.load(Ordering::Relaxed), | ||
| total_wait_ms: 0, // TODO: track this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This TODO indicates an unimplemented metric. Tracking total_wait_ms is valuable for monitoring scheduler performance. You can implement this by adding an AtomicU64 for total_wait_ms to the BatchScheduler struct, and then updating it in create_batch like this:
let total_wait: u64 = requests.iter().map(|r| r.wait_time().as_millis() as u64).sum();
self.total_wait_ms.fetch_add(total_wait, Ordering::Relaxed);Finally, you can use this new atomic value here to complete the implementation.
| pub struct Model<M: ModelInitializer> { | ||
| tokenizer: Tokenizer, | ||
| model: M, | ||
| device: Device, | ||
| logits_processor: LogitsProcessor, | ||
| cache: M::Cache, | ||
| dtype: DType, | ||
| pub tokenizer: Tokenizer, | ||
| pub model: M, | ||
| pub device: Device, | ||
| pub dtype: DType, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fields of the Model struct are public. This breaks encapsulation, allowing external code to modify the internal state of the model directly (e.g., swapping the tokenizer). It would be safer to make these fields private and provide public read-only accessor methods (getters) for the fields that need to be accessed externally.
A few performance improvements