jax-ml/jax · error · ValueError

Expected B scales to have a M=64 collective layout, got {b_s

Error message

Expected B scales to have a M=64 collective layout, got {b_scale.layout}

What it means

For collective (multi-CTA) block-scaled MMA with M=64, the B scale tensor must use the special layout b_scales_m64_collective_layout(). This mirrors the M=64 collective MMA instruction's scale lanes across CTAs.

Source

Thrown at jax/experimental/mosaic/gpu/tcgen05.py:475

        raise ValueError(
            "Scale element type mismatch: expected f8e8m0fnu or f8e4m3fn, got"
            f" {scale_element_type}"
        )
    else:
      raise NotImplementedError(
          f"Unsupported element type for block scaling: {a_element_type}"
      )
    k_scales = k // scale_block
    if a_scale.shape != (TMEM_ROWS, k_scales):
      raise ValueError(
          f"A scale shape mismatch: expected ({TMEM_ROWS}, {k_scales}), got"
          f" {a_scale.shape}"
      )
    if a_scale.layout != scales_layout():
      raise ValueError(f"A scale layout {a_scale.layout} is not supported")
    if collective and m == 64:
      if b_scale.layout != b_scales_m64_collective_layout():
        raise ValueError(
            "Expected B scales to have a M=64 collective layout, got"
            f" {b_scale.layout}"
        )
    elif m == 128:
      if b_scale.layout != scales_layout():
        raise ValueError(
            f"Expected B scales to have a M=128 layout, got {b_scale.layout}"
        )
    else:
      raise AssertionError("Should not happen")
    if b_scale.shape[0] % 128 or b_scale.shape[0] < n * num_cta:
      raise ValueError(
          f"B scale shape[0] must be a multiple of 128 and >= N={n * num_cta},"
          f" got {b_scale.shape[0]}"
      )
    if b_scale.shape[1] != k_scales:
      raise ValueError(
          f"B scale shape mismatch: expected ({b_scale.shape[0]}, {k_scales}),"

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Set b_scale layout to b_scales_m64_collective_layout() when collective=True and m=64
  2. Or use m=128 (with plain scales_layout) if collective M=64 isn't required

Example fix

# before
b_scale = TensorMemRefView(buf, shape, dt, layout=scales_layout())
# after (collective, m=64)
b_scale = TensorMemRefView(buf, shape, dt, layout=b_scales_m64_collective_layout())
Defensive patterns

Strategy: validation

Validate before calling

from jax.experimental.mosaic.gpu import tcgen05
expected = tcgen05.b_scales_m64_collective_layout() if (collective and m == 64) else None
assert expected is None or b_scale.layout == expected

Prevention

When it happens

Trigger: Calling mma(..., collective=True, m=64) with b_scale.layout != b_scales_m64_collective_layout().

Common situations: Reusing dense M=128 kernel scale layouts in a 2-CTA collective M=64 configuration; forgetting to switch layouts when enabling collective mode.

Related errors


AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27). Data as JSON: /api/errors/ed9886a497e4eecf. Report an issue: GitHub.