sgl-project/sglang · error · ValueError
Unknown match_type: '{match_type}'. Must be 'BFS' or 'PROB'.
Error message
Unknown match_type: '{match_type}'. Must be 'BFS' or 'PROB'. What it means
The ngram corpus only accepts match_type of 'BFS' or 'PROB' (mapped via _MATCH_TYPE_MAP). Any other string raises immediately in __init__.
Source
Thrown at python/sglang/kernels/ops/speculative/ngram_corpus.py:58
@tvm_ffi.register_object("sgl.NgramCorpus")
class NgramCorpusFFI(tvm_ffi.Object):
__slots__ = ("__dict__",)
def __init__(
self,
capacity: int,
max_trie_depth: int,
min_bfs_breadth: int,
max_bfs_breadth: int,
draft_token_num: int,
match_type: str,
external_sam_budget: int = 0,
external_corpus_max_tokens: int = 10000000,
) -> None:
mt = _MATCH_TYPE_MAP.get(match_type)
if mt is None:
raise ValueError(
f"Unknown match_type: '{match_type}'. Must be 'BFS' or 'PROB'."
)
self.__ffi_init__(
capacity,
max_trie_depth,
min_bfs_breadth,
max_bfs_breadth,
draft_token_num,
mt,
external_sam_budget,
external_corpus_max_tokens,
)
self._draft_token_num = draft_token_num
def insert(self, batch_tokens: List[List[int]]) -> None:
tokens_flat, offsets = _to_csr(batch_tokens)
self.async_insert(tokens_flat, offsets) # type: ignore
View on GitHub (pinned to 0132848349)
Solutions
- Use exactly 'BFS' or 'PROB' (case-sensitive).
- Check _MATCH_TYPE_MAP keys in ngram_corpus.py for the accepted values.
- Validate/normalize the spec config string before constructing.
Example fix
// before corpus = NgramCorpus(..., match_type='bfs') // after corpus = NgramCorpus(..., match_type='BFS')
Defensive patterns
Strategy: validation
Validate before calling
assert match_type in ('BFS', 'PROB'), match_type Type guard
def is_valid_match_type(s: str) -> bool:
return s in ('BFS', 'PROB') Prevention
- Uppercase-normalize and validate the config value before construction.
When it happens
Trigger: Passing match_type='bfs' (lowercase), 'prob_sample', or a typo like 'PRO ' to the ngram corpus constructor.
Common situations: Config files with lowercase or renamed speculation settings (e.g. porting from vLLM-style 'greedy'/'sample' ngram params to this API).
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- This browser cannot encode H.264 MP4
- --speculative-draft-window-size must be positive, got {}.
- DFLASH requires --speculative-dflash-block-size to be positi
- --speculative-draft-window-size must be >= --speculative-num
- DSpark requires --speculative-dspark-block-size to be positi
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/a8ae5c892d2876f6.
Report an issue: GitHub.