sgl-project/sglang · error · ValueError
cache_salt should be a list or a string.
Error message
cache_salt should be a list or a string.
What it means
Raised when cache_salt is neither None, str, nor list. The normalizer accepts None (skip), a str (broadcast), or a list[str] (per-request); anything else is rejected before dispatch.
Source
Thrown at python/sglang/srt/managers/io_struct.py:816
def _normalize_cache_salt(self, num):
"""Normalize cache_salt for batch processing."""
if self.cache_salt is None:
return
if isinstance(self.cache_salt, str):
value = self.cache_salt or None
self.cache_salt = [value] * num
elif isinstance(self.cache_salt, list):
if len(self.cache_salt) != self.batch_size:
raise ValueError(
"The length of cache_salt should be equal to the batch size."
)
if any(not isinstance(value, str) for value in self.cache_salt):
raise ValueError("Every cache_salt should be a string.")
self.cache_salt = [value or None for value in self.cache_salt]
self.cache_salt = self.cache_salt * self.parallel_sample_num
else:
raise ValueError("cache_salt should be a list or a string.")
def _normalize_bootstrap_params(self, num):
"""Normalize bootstrap parameters for batch processing."""
# Normalize bootstrap_host
if self.bootstrap_host is None:
self.bootstrap_host = [None] * num
elif not isinstance(self.bootstrap_host, list):
self.bootstrap_host = [self.bootstrap_host] * num
elif isinstance(self.bootstrap_host, list):
self.bootstrap_host = self.bootstrap_host * self.parallel_sample_num
# Normalize bootstrap_port
if self.bootstrap_port is None:
self.bootstrap_port = [None] * num
elif not isinstance(self.bootstrap_port, list):
self.bootstrap_port = [self.bootstrap_port] * num
elif isinstance(self.bootstrap_port, list):
self.bootstrap_port = self.bootstrap_port * self.parallel_sample_numView on GitHub (pinned to 0132848349)
Solutions
- Use str, list[str], or None
- Convert tuples: list(tuple)
Example fix
// before
cache_salt=('s1','s2')
// after
cache_salt=['s1','s2'] Defensive patterns
Strategy: type-guard
Validate before calling
cache_salt = list(cache_salt) if isinstance(cache_salt, tuple) else cache_salt
Type guard
def valid_salt(s): return s is None or isinstance(s, (str, list))
Prevention
- Document accepted types: None | str | list[str]
When it happens
Trigger: cache_salt=42, cache_salt=('s1','s2') (tuple), or a dict.
Common situations: Passing tuple from an API layer, or numeric salt ids.
Related errors
- Every cache_salt should be a string.
- SGLang currently only supports inferring LoRA target modules
- extra_key should be a list or a string.
- The length of cache_salt should be equal to the batch size.
- Input 'data' must be a torch.Tensor, but got {type(data)}
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/be1278bc5c3fcb8e.
Report an issue: GitHub.