Skip to content
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

[Refactor] Refactor GrammarMatcherBase #151

Merged
merged 1 commit into from
Jan 13, 2025

Conversation

Ubospica
Copy link
Collaborator

This PR refactors the GrammarMatcherBase for simpler logic. It mainly updates the ExpandEquivalentStackElements (renamed from ExpandStackElement) function: it elegantly utilizes recursion to make it a lot simpler than the previous version.

This PR also fixes a bug in parser which could lead to incorrect parsing for character class stars. Check out the test.

@Ubospica Ubospica force-pushed the main-dev/2025-01-11-try-refactor branch from 006e656 to 8c06816 Compare January 13, 2025 18:47
@Ubospica Ubospica merged commit 5703f39 into mlc-ai:main Jan 13, 2025
1 check passed
@Ubospica
Copy link
Collaborator Author

Performance:

pytest /home/yixind/xgrammar/tests/python/test_grammar_matcher_json.py::test_json_pressure
pytest /home/yixind/xgrammar/tests/python/test_grammar_matcher_json.py::test_fill_next_token_bitmask
  • Json pressure:
    • Prev: 328.732 us, 964.586 us
    • Now: 355.181 us, 883.275 us
  • Compile Grammar:
    • Prev:
      Time to init GrammarMatcher: 25143.588 us
      Time to init GrammarMatcher: 78032.158 us
      Time to init GrammarMatcher: 24902.84 us
      
    • Now:
      Time to init GrammarMatcher: 25587.555 us
      Time to init GrammarMatcher: 74758.774 us
      Time to init GrammarMatcher: 24317.109 us
      

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant