-
Notifications
You must be signed in to change notification settings - Fork 500
[feat] Support generic remote tokenizer #1307
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
[feat] Support generic remote tokenizer #1307
Conversation
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.
Summary of Changes
Hello @ae86zhizhi, 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 our application's tokenization capabilities by introducing a flexible and robust framework for interacting with remote Large Language Model (LLM) inference engines. The primary goal is to ensure precise token count alignment between the client and the server, which is crucial for accurate model interaction and efficient resource management. This change lays the groundwork for seamless integration with diverse LLM backends while preserving existing functionality.
Highlights
- Generic Remote Tokenizer Framework: I've implemented a new, extensible framework for remote tokenization. This allows direct communication with inference engine tokenizer APIs (e.g., vLLM, SGLang), ensuring perfect alignment between client-side token calculations and server-side processing.
- Engine Adapter Pattern: A flexible adapter pattern has been introduced via the
EngineAdapterinterface. This provides specific implementations for vLLM (with full support for tokenization, detokenization, and chat message handling) and a foundational adapter for SGLang, ready for future expansion. - Robust HTTP Client: A new
HTTPClienthas been developed to handle remote API interactions. It includes essential features like connection pooling (100 max idle, 10 per host), exponential backoff retry logic, and proper resource cleanup to ensure efficient and reliable communication. - Unified Tokenizer Interface & Backward Compatibility: Existing local tokenizers (tiktoken, character-based) have been refactored and integrated into a new factory-based
NewTokenizerfunction. This maintains backward compatibility for existingTokenizerinterfaces and legacy vLLM configurations, ensuring a smooth transition. - Comprehensive Error Handling & Documentation: Custom error types have been added for various failure scenarios, improving the clarity of error messages. Additionally, a detailed
README.mdhas been included to thoroughly document the new package's architecture, usage, and extensibility.
Using Gemini Code Assist
The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and 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 to provide feedback.
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
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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 a well-designed generic remote tokenizer, using an adapter pattern to support multiple inference engines. The refactoring of existing tokenizers, addition of a robust HTTP client, and comprehensive documentation and testing are all excellent. My feedback focuses on minor improvements to further enhance the code, specifically around idiomatic error handling, replacing magic numbers with constants for better maintainability, and clarifying a deprecation comment. Overall, this is a very strong contribution.
Jeffwan
left a comment
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.
seems the change scope is very clear and extensible. Let's quickly polish this one and merge it
pkg/utils/tokenizer/interfaces.go
Outdated
|
|
||
| // TokenizerV2 is an alias for ExtendedTokenizer | ||
| // Deprecated: Use ExtendedTokenizer instead | ||
| type TokenizerV2 = ExtendedTokenizer |
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.
let's remove it. this is kind of confusing since the pr is the first version
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.
unable to resolve my own comments?
|
This PR has been updated with a comprehensive refactoring of the tokenizer package to improve code quality, simplify the API, and enhance maintainability. All commits now include DCO sign-off. Summary of Changes1. API Simplification
2. Code Quality Improvements
3. Enhanced Features
4. Testing and Documentation
Breaking Changes
Benefits
The refactoring maintains full backward compatibility for the core Tokenizer interface while significantly improving the internal implementation. |
autopear
left a comment
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.
See my comments for the revision
20af452 to
78037ba
Compare
This commit introduces a comprehensive tokenizer package refactoring with remote tokenizer support for multiple inference engines (vLLM, SGLang). Core Features: - Implement adapter pattern for different inference engines - Add HTTP client with connection pooling, retry logic, and Retry-After support - Support both tokenize and detokenize operations Signed-off-by: ae86zhizhi <[email protected]>
78037ba to
429c45e
Compare
autopear
left a comment
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.
LGTM
This commit introduces a comprehensive tokenizer package refactoring with remote tokenizer support for multiple inference engines (vLLM, SGLang). Core Features: - Implement adapter pattern for different inference engines - Add HTTP client with connection pooling, retry logic, and Retry-After support - Support both tokenize and detokenize operations Signed-off-by: ae86zhizhi <[email protected]>
Pull Request Description
This PR implements a generic remote tokenizer that communicates directly with inference engines' tokenizer APIs, ensuring perfect alignment between client-side token calculations and server-side processing.
Related Issues
Resolves: #1306
Changes
Core Implementation
RemoteTokenizerinterface and implementation.VLLMAdapter: Full implementation completed with complete tokenize/detokenize support.SGLangAdapter: Basic completion endpoint support (foundation for future enhancement).HTTPClientwith:vLLM Integration (Fully Implemented)
/tokenizeendpoint support with all options./detokenizeendpoint support.add_special_tokensparameter).Error Handling
Backward Compatibility
Tokenizerinterface.Testing
Performance Considerations
Usage
Checklist
README.mdincluded).Future Work