-
Notifications
You must be signed in to change notification settings - Fork 99
[Refactor] Refactor the grammar compiler to improve maintainability. #470
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?
[Refactor] Refactor the grammar compiler to improve maintainability. #470
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.
Pull Request Overview
This PR refactors the grammar compiler code to improve maintainability by extracting large monolithic functions into smaller, more focused helper functions. The main changes involve consolidating tokenizer-related parameters into a TokenizerInfo object and breaking down complex token mask calculation logic into separate methods.
Key Changes
- Method signatures refactored to use
TokenizerInfoparameter instead of multiple individual parameters - Large function bodies extracted into smaller, focused helper methods (
GetFirstCharacterMask,CheckAllPossibleTokens,CheckTokensInInterval, etc.) MultiThreadCompileGrammarsplit intoTagDispatchOptimizationandGenerateTokenMaskCacheForScannableStates
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Yuchuan <[email protected]>
Signed-off-by: Yuchuan <[email protected]>
Signed-off-by: Yuchuan <[email protected]>
Signed-off-by: Yuchuan <[email protected]>
Signed-off-by: Yuchuan <[email protected]>
Signed-off-by: Yuchuan <[email protected]>
Signed-off-by: Yuchuan <[email protected]>
Signed-off-by: Yuchuan <[email protected]>
Signed-off-by: Yuchuan <[email protected]>
Signed-off-by: Yuchuan <[email protected]>
Signed-off-by: Yuchuan <[email protected]>
4efa142 to
2289d4b
Compare
This PR refactors the structure of the grammar compiler to improve maintainability, and it doesn't change the logic of the grammar compiler.
In this PR, the workflow of
MultiThreadCompileGrammarcan be represented as: