[Spec][Ngram] 6/N: Load an external corpus and construct a Suffix Automaton#21425
Merged
hnyls2002 merged 21 commits intosgl-project:mainfrom Apr 6, 2026
Merged
[Spec][Ngram] 6/N: Load an external corpus and construct a Suffix Automaton#21425hnyls2002 merged 21 commits intosgl-project:mainfrom
hnyls2002 merged 21 commits intosgl-project:mainfrom
Conversation
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Move external corpus ingestion into the suffix automaton constructor so the SAM lifecycle matches one-time startup loading and no longer exposes a separate mutable build step. Made-with: Cursor
13 tasks
2d5cfef to
7a61d97
Compare
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Adapt SAM external corpus feature to the new ngram architecture:
- Move suffix_automaton.{h,cpp} to jit_kernel/csrc/ngram_corpus/
- Use TVM FFI instead of pybind11 for SAM loading methods
- Change match_state_ key from std::string to int64_t state_ids
- Add SAM budget splitting to stateful batchMatch overload
- Wire external corpus params through FFI constructor
- Keep both stateless and stateful batchMatch overloads
Collaborator
|
/rerun-test test_ngram_corpus.py test_server_args.py test_ngram_speculative_decoding.py |
Collaborator
|
/tag-and-rerun-ci |
Contributor
|
✅ ✅ |
This was referenced Apr 6, 2026
JustinTong0323
pushed a commit
to JustinTong0323/sglang
that referenced
this pull request
Apr 7, 2026
Fridge003
pushed a commit
that referenced
this pull request
Apr 7, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Part of Ngram refactoring series #21052
Following #21243
We want to support loading an external corpus and constructing a Suffix Automaton for suffix matching during drafting.
Modifications
--speculative-ngram-external-corpus-path,--speculative-ngram-external-sam-budget, andspeculative_ngram_external_corpus_max_tokensspeculative_ngram_external_corpus_max_tokensas a proxy to avoid CPU OOM during SAM construction (SAM memory overhead is ~2 * external_corpus_tokens_count)Accuracy Tests
Verify with these tests locally
Benchmarking and Profiling
This change affects server start time. Here is a quick script to benchmark it against the external corpus size
https://gist.github.com/kpham-sgl/00c547a6fb7ab431ad2a09e42e371bd2
We can look into optimizing this in later PRs
[TODO] Run any speculative decoding here with external corpus dataset to see how this help speedup Ngram speculative decoding
Checklist
Review Process
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci