jax-ml/jax · error · ValueError
Got unexpected `to` value. Allowed `to` values are
Error message
Got unexpected `to` value. Allowed `to` values are: {_allowed_pcast_to} What it means
pcast changes an array's axis-type status (unreduced/reduced/varying); the target kind given in `to` is not one of the three supported values, so the dispatch table lookup fails and the guard reports the allowed set.
Solutions
- Use exactly one of 'unreduced', 'reduced', 'varying'
- If targeting invarying, restructure: invarying is not a cast target — reshape/gather instead
- Validate dynamic `to` values against the allowed set before calling
Example fix
# before pcast(x, 'dev', to='invarying') # after # invarying is not a valid target; pick one of: pcast(x, 'dev', to='varying')
Defensive patterns
Strategy: validation
Validate before calling
ALLOWED = {'unreduced', 'reduced', 'varying'}
assert to in ALLOWED, f'to must be one of {ALLOWED}' Type guard
def is_valid_to(to: str) -> bool:
return to in {'unreduced', 'reduced', 'varying'} Prevention
- Use a Literal['unreduced','reduced','varying'] type annotation on wrappers
When it happens
Trigger: Calling `pcast(x, 'dev', to='invarying')`, `to='varying '` (typo/whitespace), or a placeholder like `to=None`/`to='auto'`.
Common situations: Assuming pcast can target every axis state including 'invarying'; typos or dynamically built `to` strings from config; older snippets using a different API vocabulary.
Understand the failure class
Background: "invalid argument", "unknown mode", "not supported": invalid enum-like argument errors explained — this error's family across 19 libraries.
Related errors
- must be a tuple or a str. Got
- Can only infer one dimension
- Invalid mode ' ' for np.take
- megacore_mode must be one of ['kv_head', 'batch', None]
- method can only be 'linear', 'lower', 'higher', 'midpoint'…
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/7f3d26f8c6954610.
Report an issue: GitHub.
Appendix: source
Thrown at jax/_src/lax/parallel.py:3043
_pcast_funcs = {
('invarying', 'varying'): core.pvary,
('invarying', 'reduced'): preduced,
('varying', 'unreduced'): vary_unreduced_cast,
('reduced', 'varying'): core.reduced_vary_cast,
}
_allowed_pcast_to = {'unreduced', 'reduced', 'varying'}
def pcast(x, axis_name, *, to: str):
if isinstance(axis_name, (set, frozenset)):
raise TypeError(f"{axis_name=} must be a tuple or a str. Got {axis_name}")
axes = (axis_name,) if not isinstance(axis_name, tuple) else axis_name
if not axis_name:
return x
if to not in _allowed_pcast_to:
raise ValueError(
"Got unexpected `to` value. Allowed `to` values are:"
f" {_allowed_pcast_to}")
def bind(leaf):
from_ = _get_from(core.typeof(leaf), axes, 'jax.lax.pcast')
func = _pcast_funcs.get((from_, to), None)
if func is None:
raise ValueError(f"Unsupported pcast from={from_}, {to=}")
return func(leaf, axes)
return tree_util.tree_map(bind, x)
def _emit_async_start_custom_call(
target_name, ctx, x, cfg, called_computations=None
):
out_aval, = ctx.avals_out
future_type = mlir.aval_to_ir_type(ctx.module_context, out_aval.inner_aval)
cfg = dict(cfg)View on GitHub (pinned to 1e1c6a8fc0)