sgl-project/sglang · error · ImportError
The fastokens package is required when --tokenizer-backend=f
Error message
The fastokens package is required when --tokenizer-backend=fastokens. Install it with: pip install 'sglang[fastokens]'
What it means
--tokenizer-backend=fastokens was requested (in get_tokenizer/get_processor), but the optional fastokens package is not installed, so it cannot patch transformers. Install it via the sglang[fastokens] extra.
Source
Thrown at python/sglang/srt/utils/hf_transformers/tokenizer.py:460
# ---------------------------------------------------------------------------
# Public entry point
# ---------------------------------------------------------------------------
_fastokens_patched = False
def _ensure_fastokens_patched():
"""Monkey-patch transformers to use the fastokens backend (once)."""
global _fastokens_patched
if _fastokens_patched:
return
try:
import fastokens
except ImportError:
raise ImportError(
"The fastokens package is required when --tokenizer-backend=fastokens. "
"Install it with: pip install 'sglang[fastokens]'"
) from None
fastokens.patch_transformers()
_fastokens_patched = True
logger.info("fastokens backend enabled - transformers patched successfully")
def get_tokenizer(
tokenizer_name: str,
*args,
tokenizer_mode: str = "auto",
trust_remote_code: bool = False,
tokenizer_revision: Optional[str] = None,
tokenizer_backend: str = "huggingface",
**kwargs,
) -> Union[PreTrainedTokenizer, PreTrainedTokenizerFast]:View on GitHub (pinned to 0132848349)
Solutions
- pip install 'sglang[fastokens]'
- Or drop --tokenizer-backend fastokens and use the default HF tokenizer backend
Example fix
# before: command fails with ImportError # after pip install 'sglang[fastokens]'
Defensive patterns
Strategy: validation
Validate before calling
if tokenizer_backend == 'fastokens':
import importlib.util
assert importlib.util.find_spec('fastokens') is not None, 'pip install sglang[fastokens]' Prevention
- Install the sglang[fastokens] extra before enabling the backend
- Or omit the flag to use the default tokenizer backend
When it happens
Trigger: Passing --tokenizer-backend fastokens in an environment where 'import fastokens' fails.
Common situations: Using the flag after seeing it in docs/benchmarks without installing the optional dependency.
Related errors
- Sparse Video Gen 2 attention backend requires svg package to
- Humming quantization requires `humming-kernels`. Please inst
- hf3fs_fuse.io is not available. Please install the hf3fs_fus
- LMCache is not installed. Please install it by running `pip
- Please install mooncake by following the instructions at htt
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/62aa5416e7f05465.
Report an issue: GitHub.