{"record":{"id":"c6531d92eb0551dc","repo":"jax-ml/jax","slug":"b-scale-shape-mismatch-expected-b-scale-shape-0","errorCode":null,"errorMessage":"B scale shape mismatch: expected ({b_scale.shape[0]}, {k_scales}), got {b_scale.shape}","messagePattern":"B scale shape mismatch: expected \\((.+?), (.+?)\\), got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/experimental/mosaic/gpu/tcgen05.py","lineNumber":492,"sourceCode":"      if b_scale.layout != b_scales_m64_collective_layout():\n        raise ValueError(\n            \"Expected B scales to have a M=64 collective layout, got\"\n            f\" {b_scale.layout}\"\n        )\n    elif m == 128:\n      if b_scale.layout != scales_layout():\n        raise ValueError(\n            f\"Expected B scales to have a M=128 layout, got {b_scale.layout}\"\n        )\n    else:\n      raise AssertionError(\"Should not happen\")\n    if b_scale.shape[0] % 128 or b_scale.shape[0] < n * num_cta:\n      raise ValueError(\n          f\"B scale shape[0] must be a multiple of 128 and >= N={n * num_cta},\"\n          f\" got {b_scale.shape[0]}\"\n      )\n    if b_scale.shape[1] != k_scales:\n      raise ValueError(\n          f\"B scale shape mismatch: expected ({b_scale.shape[0]}, {k_scales}),\"\n          f\" got {b_scale.shape}\"\n      )\n  if is_sparse:\n    sparse_group_elems = 8 if utils.bitwidth(a_element_type) == 4 else 4\n    # Each sparse group has 2 entries.\n    expected_meta_k = k // sparse_group_elems * 2\n    if a_sparse_metadata.shape != (m, expected_meta_k):\n      raise ValueError(\n          f\"A sparse metadata shape mismatch: expected {(m, expected_meta_k)},\"\n          f\" got {a_sparse_metadata.shape}\"\n      )\n    if a_sparse_metadata.dtype != ir.IntegerType.get_signless(2):\n      raise ValueError(\n          \"A sparse metadata dtype mismatch: expected i2, got\"\n          f\" {a_sparse_metadata.dtype}\"\n      )\n","sourceCodeStart":474,"sourceCodeEnd":510,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/experimental/mosaic/gpu/tcgen05.py#L474-L510","documentation":"In block-scaled MMA, the B scale tensor's second dimension must equal k_scales = k // scale_block. This fires when b_scale.shape[1] doesn't match, i.e. the scale count along K differs from what the operands imply.","triggerScenarios":"b_scale.shape[1] != k // scale_block, e.g. k=512, scale_block=32 (k_scales=16) but b_scale has shape (..., 8).","commonSituations":"Transposed B operands where K and N are swapped in the scale tensor; inconsistent scale_block between the A and B scale computation.","solutions":["Regenerate b_scale so shape[1] == k // scale_block","Verify B operand's K dimension and that A and B scales use the same scale_block"],"exampleFix":"# before\nb_scale = make_scales((512, 8))\n# after\nk_scales = k // scale_block\nb_scale = make_scales((512, k_scales))","handlingStrategy":"validation","validationCode":"assert b_scale.shape[1] == k // scale_block","typeGuard":"def valid_b_scale(shape, k, scale_block) -> bool:\n    return shape[1] == k // scale_block","tryCatchPattern":null,"preventionTips":["Generate A and B scales in the same function sharing k and scale_block","Watch for transposed (N, K) mixing when building scales"],"tags":["gpu","mosaic","tcgen05","shape-mismatch","block-scaling"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}