{"record":{"id":"7f3d26f8c6954610","repo":"jax-ml/jax","slug":"got-unexpected-to-value-allowed-to-values-are","errorCode":null,"errorMessage":"Got unexpected `to` value. Allowed `to` values are: {_allowed_pcast_to}","messagePattern":"Got unexpected `to` value\\. Allowed `to` values are: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/parallel.py","lineNumber":3043,"sourceCode":"\n_pcast_funcs = {\n    ('invarying', 'varying'): core.pvary,\n    ('invarying', 'reduced'): preduced,\n    ('varying', 'unreduced'): vary_unreduced_cast,\n    ('reduced', 'varying'): core.reduced_vary_cast,\n}\n\n_allowed_pcast_to = {'unreduced', 'reduced', 'varying'}\n\ndef pcast(x, axis_name, *, to: str):\n  if isinstance(axis_name, (set, frozenset)):\n    raise TypeError(f\"{axis_name=} must be a tuple or a str. Got {axis_name}\")\n  axes = (axis_name,) if not isinstance(axis_name, tuple) else axis_name\n  if not axis_name:\n    return x\n\n  if to not in _allowed_pcast_to:\n    raise ValueError(\n        \"Got unexpected `to` value. Allowed `to` values are:\"\n        f\" {_allowed_pcast_to}\")\n\n  def bind(leaf):\n    from_ = _get_from(core.typeof(leaf), axes, 'jax.lax.pcast')\n    func = _pcast_funcs.get((from_, to), None)\n    if func is None:\n      raise ValueError(f\"Unsupported pcast from={from_}, {to=}\")\n    return func(leaf, axes)\n  return tree_util.tree_map(bind, x)\n\ndef _emit_async_start_custom_call(\n    target_name, ctx, x, cfg, called_computations=None\n):\n  out_aval, = ctx.avals_out\n  future_type = mlir.aval_to_ir_type(ctx.module_context, out_aval.inner_aval)\n\n  cfg = dict(cfg)","sourceCodeStart":3025,"sourceCodeEnd":3061,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/parallel.py#L3025-L3061","documentation":"`jax.lax.pcast`'s `to` keyword must be one of 'unreduced', 'reduced', or 'varying' (the set `_allowed_pcast_to`). Any other string raises this ValueError listing the allowed values.","triggerScenarios":"Calling `pcast(x, 'dev', to='invarying')`, `to='varying '` (typo/whitespace), or a placeholder like `to=None`/`to='auto'`.","commonSituations":"Assuming pcast can target every axis state including 'invarying'; typos or dynamically built `to` strings from config; older snippets using a different API vocabulary.","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"],"exampleFix":"# before\npcast(x, 'dev', to='invarying')\n# after\n# invarying is not a valid target; pick one of:\npcast(x, 'dev', to='varying')","handlingStrategy":"validation","validationCode":"ALLOWED = {'unreduced', 'reduced', 'varying'}\nassert to in ALLOWED, f'to must be one of {ALLOWED}'","typeGuard":"def is_valid_to(to: str) -> bool:\n    return to in {'unreduced', 'reduced', 'varying'}","tryCatchPattern":null,"preventionTips":["Use a Literal['unreduced','reduced','varying'] type annotation on wrappers"],"tags":["jax","pcast","invalid-argument"],"backgroundTag":"invalid-enum-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}