{"record":{"id":"69d4dde8fc874ec1","repo":"jax-ml/jax","slug":"reduced-vary-cast-input-cannot-be-varying-across-t","errorCode":null,"errorMessage":"reduced_vary_cast input cannot be varying across the axis_name provided. Got x={aval.str_short(True)} and axis_name={axes}","messagePattern":"reduced_vary_cast input cannot be varying across the axis_name provided\\. Got x=(.+?) and axis_name=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/parallel.py","lineNumber":2982,"sourceCode":"    partial(_raise_valueerror, 'reduced_vary_cast'))\nmlir.register_lowering(core.reduced_vary_cast_p, lambda ctx, x, *, axes: [x])\n\ndef _reduced_vary_cast_abstract_eval(aval, *, axes):\n  assert isinstance(axes, tuple)\n  _check_axis_names(axes, 'reduced_vary_cast')\n  if not aval.mat.reduced:\n    raise ValueError('reduced_vary_cast only accepts inputs that are'\n                     f' reduced. Got {aval.str_short(True)}')\n  # If the intersection between aval.mat.reduced and axes is empty, error\n  if not (aval.mat.reduced & set(axes)):\n    raise ValueError(\n        \"reduced_vary_cast is a Reduced->Varying collective. This\"\n        \" means that the axis names mentioned in `axes` passed to\"\n        \" `reduced_vary_cast` must be present in\"\n        f\" `jax.typeof(x).mat.reduced`. Got axes={axes} and\"\n        f\" jax.typeof(x).mat.reduced={aval.mat.reduced}\")\n  if aval.mat.varying & set(axes):\n    raise ValueError(\n        \"reduced_vary_cast input cannot be varying across the axis_name\"\n        f\" provided. Got x={aval.str_short(True)} and axis_name={axes}\")\n  if aval.mat.unreduced:\n    check_unreduced_kind('reduced_vary_cast', aval.mat, UnreducedKind.sum)\n\n  new_reduced = frozenset(i for i in aval.mat.reduced if i not in axes)\n  out_vma = aval.mat.varying | frozenset(axes)\n  return aval.update(manual_axis_type=aval.mat.update(\n    varying=out_vma, reduced=new_reduced))\ncore.reduced_vary_cast_p.def_abstract_eval(_reduced_vary_cast_abstract_eval)\n\ndef _reduced_vary_cast_transpose_rule(cts, x, *, axes):\n  assert ad.is_undefined_primal(x)\n  return (vary_unreduced_cast(cts, axis_name=axes),)\nad.deflinear2(core.reduced_vary_cast_p, _reduced_vary_cast_transpose_rule)\n\ndef _reduced_vary_cast_batcher(vals_in, dims_in, *, axes):\n  raise NotImplementedError","sourceCodeStart":2964,"sourceCodeEnd":3000,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/parallel.py#L2964-L3000","documentation":"`reduced_vary_cast` requires the input not be varying across the axes being cast; the abstract eval rejects inputs where `aval.mat.varying & set(axes)` is non-empty, because casting a varying axis to varying is contradictory.","triggerScenarios":"Calling reduced_vary_cast over an axis the input still varies along (e.g. after gathering/splitting re-introduced variation, or on a fresh broadcasted value).","commonSituations":"State-machine mistakes in manual axis tracking where a value is believed reduced but a preceding op actually re-varied it.","solutions":["First reduce over that axis (e.g. psum) or use the appropriate Varying->Varying/Unreduced cast","Verify `jax.typeof(x).mat` at each stage and fix the preceding op","Use `pcast(..., to='varying')` for state-aware dispatch"],"exampleFix":"// before\ny = reduced_vary_cast(x, 'dev')  # x varying over 'dev'\n// after\ny = vary_appropriate_op(x, 'dev')  # reduce or leave varying; pcast(x,'dev',to='varying') is a no-op path","handlingStrategy":"type-guard","validationCode":"t = jax.typeof(x)\nassert not (set(axes) & t.mat.varying), 'input varies over cast axes; reduce first'","typeGuard":"def not_varying_over(x, axes) -> bool:\n    return not (set(axes) & jax.typeof(x).mat.varying)","tryCatchPattern":null,"preventionTips":["Track axis state through each op in comments or a small state object"],"tags":["jax","named-axes","manual-parallelism"],"backgroundTag":"jax-manual-axis-state-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}