-
Notifications
You must be signed in to change notification settings - Fork 892
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Grammar] Integrate with XGrammar (#635)
This PR integrates with XGrammar: https://github.com/mlc-ai/xgrammar. Prior to this PR, grammar is supported by the grammar portion of MLC-LLM compiled into the model WASM. That portion is now a standalone project XGrammar. Therefore, this PR adds `mlc-ai/web-xgrammar` as part of the dependency and remove `src/grammar.ts`. We update `llm_chat.ts` accordingly for xgrammar's APIs. In addition, besides `json_schema`, we now also support requests with EBNF-formatted strings by using the following in the chat completion request. See `examples/json-schema`'s `ebnfGrammarExample()` for a full example. ```typescript response_format: { type: "grammar", grammar: jsonGrammarStr, } as webllm.ResponseFormat, ``` We also add the following performance info: - Add `grammar_init_ms` and `grammar_per_token_ms` to `CompletionUsage.extra` when using grammar - Add `time_to_first_token_s` (TTFT) and `time_per_output_token_s` (TPOT), `e2e_latency_s` to `CompletionUsage.extra` We also add `ignore_eos` to `Completion` and `ChatCompletion` requests, which can be useful for benchmarking purposes.
- Loading branch information
1 parent
6504047
commit c6b1b4e
Showing
13 changed files
with
467 additions
and
301 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.