sgl-project/sglang · error · ValueError
Invalid value: {other}
Error message
Invalid value: {other} What it means
Raised by the batch-state __iadd__ (broadcasting a value across forked states) when `other` is not a single appendable value, a list, or a tuple. The multi-state container only supports appending one value to all states or element-wise lists/tuples of the same length.
Source
Thrown at python/sglang/lang/interpreter.py:1096
def __getitem__(self, i: int):
return self.states[i]
def __setitem__(self, i: int, value):
assert self.states[i] == value
def __iadd__(self, other):
if isinstance(other, Callable):
# lambda function
for i in range(len(self.states)):
self.states[i] += other(i)
elif isinstance(other, SglExpr):
for i in range(len(self.states)):
self.states[i] += other
elif isinstance(other, (list, tuple)):
for i in range(len(self.states)):
self.states[i] += other[i]
else:
raise ValueError(f"Invalid value: {other}")
return self
View on GitHub (pinned to 0132848349)
Solutions
- Materialize per-state values as a list with exactly len(states) entries: states += [v1, v2, ...]
- Or append a single str/Sgl primitive to broadcast to all states
- Check len(your_list) == number of forked states before +=
Example fix
# before
states += (f"prompt {i}" for i in range(n)) # generator -> raises
# after
states += [f"prompt {i}" for i in range(n)] # list, len == n_states Defensive patterns
Strategy: type-guard
Validate before calling
if isinstance(other, (list, tuple)):
assert len(other) == len(states), f"need {len(states)} values, got {len(other)}"
states += list(other)
else:
states += other # broadcast single primitive Type guard
def broadcastable(other, n_states: int) -> bool:
if isinstance(other, (list, tuple)):
return len(other) == n_states
return isinstance(other, (str,)) or type(other).__name__.startswith("Sgl") Try / catch
try:
states += other
except ValueError as e:
if "Invalid value" in str(e):
states += list(other) # materialize iterables
else:
raise Prevention
- Materialize generators/comprehensions to list before broadcasting
- Keep per-state value lists length-aligned with fork size
- Prefer broadcasting a single string when all branches share content
When it happens
Trigger: `states += x` where x is a dict, generator, set, or a list whose length != number of forked states; passing a tuple of the wrong arity.
Common situations: Broadcasting per-branch prompts built as a dict comprehension or generator; length mismatch after changing fork(size=N); assuming any iterable works when only list/tuple are accepted.
Related errors
- Unknown type: {type(other)}
- Tried to append None to state.
- Invalid join mode: {mode}
- spt must be a bool when provided
- Unsupported image type: {type(image)}
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/876f9f98250b4927.
Report an issue: GitHub.