jax-ml/jax · error · ValueError
Expected 0D shape, but got
Error message
Expected 0D shape, but got {fa.shape} What it means
The Mosaic GPU Pallas lowering generates a static GPU module and therefore requires statically known grid bounds; data-dependent (dynamic) grid dimensions raise NotImplementedError in lower_pipelined_jaxpr_to_module.
Solutions
- Reduce the value to a scalar inside the callback, or declare the output with its true shape
Example fix
// before ret_ty = jax.ShapeDtypeStruct((), jnp.float32) # callback returns (4,) // after inline_mgpu(lambda x: jnp.sum(x), x) # scalar returned
Defensive patterns
Strategy: validation
Validate before calling
assert not fa.shape, fa.shape # scalar output must be 0D
Prevention
- Reduce arrays to scalars before returning scalar-typed outputs
When it happens
Trigger: Declaring an output as scalar (empty-shape ShapeDtypeStruct) while the callback returns a FragmentedArray with a non-empty shape.
Common situations: Forgetting to reduce an array result to a scalar; shape bookkeeping errors in the output type list.
Related errors
- Accumulator and LHS have incompatible shapes. Expected LHS…
- Accumulator and RHS have incompatible shapes. Expected RHS…
- Accumulator and RHS have incompatible shapes. Expected RHS…
- Accumulator shape does not match value shape
- Array shape mismatch: expected
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/8d6fd06c8a70fbec.
Report an issue: GitHub.
Appendix: source
Thrown at jax/_src/pallas/mosaic_gpu/primitives.py:3848
):
if not isinstance(fa, mgpu.FragmentedArray):
raise ValueError(f"Expected a FragmentedArray, but got: {fa}")
if isinstance(result_ty, ir.VectorType):
result_shape = ir.VectorType(result_ty).shape
if fa.shape != tuple(result_shape):
raise ValueError(f"Expected {result_shape} but got {fa.shape}")
if out_layout != mgpu.layouts.to_layout_attr(fa.layout):
raise ValueError(
f"Output layout {out_layout} does not match the layout of the"
f" returned fragmented array {fa.layout}."
)
ir_ret.append(
mgpu.dialect_lowering.fragmented_array_to_ir(fa, result_ty)
)
else: # scalar case.
assert out_layout is None
if fa.shape:
raise ValueError(f"Expected 0D shape, but got {fa.shape}")
if not isinstance(fa.layout, mgpu.WGSplatFragLayout):
raise ValueError(f"Expected WGSplatFragLayout, but got {fa.layout}")
value = fa.registers.item()
ir_ret.append(value)
mgpu.dialect.return_(ir_ret)
@lowering.register_lowering_rule(inline_mgpu_p, mgpu.LoweringSemantics.Warpgroup)
@lowering.register_lowering_rule(inline_mgpu_p, *gpu_core.WGxWARP_SEMANTICS)
def _inline_mgpu_lowering_rule_wg_semantics(
ctx: lowering.LoweringRuleContext,
*flat_args_and_transforms,
mgpu_fn: Callable[..., Any],
flat_arg_types,
flat_ret_ty,
pytree_args,
pytree_ref_transforms,View on GitHub (pinned to 1e1c6a8fc0)