{"record":{"id":"4f9b961ff798a076","repo":"vllm-project/vllm","slug":"a-must-have-at-least-1-dimension","errorCode":null,"errorMessage":"`a` must have at least 1 dimension.","messagePattern":"`a` must have at least 1 dimension\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"vllm/_custom_ops.py","lineNumber":4096,"sourceCode":"        a: torch.Tensor, b: torch.Tensor, xh_e2m1: torch.Tensor, xh_e8m0: torch.Tensor\n    ):\n        return xh_e2m1, xh_e8m0\n\n\nif hasattr(torch.ops._qutlass_C, \"fusedQuantizeMxAbsMax\"):\n\n    @register_fake(\"_qutlass_C::fusedQuantizeMxAbsMax\")\n    def _fake_fused_quantize_mx_absmax(\n        a: torch.Tensor, b: torch.Tensor, xh_e2m1: torch.Tensor, xh_e8m0: torch.Tensor\n    ):\n        return xh_e2m1, xh_e8m0\n\n\ndef fusedQuantizeMx(\n    a: torch.Tensor, b: torch.Tensor, *, method: Literal[\"quest\", \"abs_max\"] = \"quest\"\n) -> tuple[torch.Tensor, torch.Tensor]:\n    if a.dim() == 0:\n        raise ValueError(\"`a` must have at least 1 dimension.\")\n    if a.size(-1) % 32 != 0:\n        raise ValueError(f\"last dim of `a` must be divisible by 32, got {a.size(-1)}.\")\n    if b.device != a.device:\n        raise ValueError(\"`a` and `b` must be on the same device.\")\n\n    xh_e2m1 = torch.empty(\n        *a.shape[:-1], a.size(-1) // 2, dtype=torch.uint8, device=a.device\n    )\n\n    rows, cols = a.numel() // a.size(-1), a.size(-1) // 32\n    n_row_blocks = cdiv(rows, 128)\n    n_col_blocks = cdiv(cols, 4)\n    padded_rows = n_row_blocks * 128\n    padded_cols = n_col_blocks * 4\n\n    xh_e8m0 = torch.empty(\n        padded_rows, padded_cols, dtype=torch.float8_e8m0fnu, device=a.device\n    )","sourceCodeStart":4078,"sourceCodeEnd":4114,"githubUrl":"https://github.com/vllm-project/vllm/blob/c794754062d49a8fdb63ab3c5215b488b865030c/vllm/_custom_ops.py#L4078-L4114","documentation":"fusedQuantizeMx() packs tensor `a` into MX FP4 (e2m1) blocks with e8m0 shared scales; the kernel's launch math (rows = numel/last_dim, col blocks of 32) requires a to be at least 1-D. A 0-dim scalar tensor (a.dim() == 0) cannot be block-quantized, so it is rejected up front.","triggerScenarios":"Calling vllm._custom_ops.fusedQuantizeMx(a, b) where a was created via torch.tensor(3.0), .item()-like reduction to scalar shape, or .squeeze() over all dims.","commonSituations":"Aggressive squeeze() in preprocessing pipelines collapsing a (1,1,d) K-quantization tensor to 0-d; passing a scalar similarity instead of a row vector in sparse-attention (quest) index quantization.","solutions":["Keep at least one dimension: use .reshape(1, -1) or .unsqueeze(0) on the scalar tensor before calling","Fix upstream code that over-squeezes (replace x.squeeze() with x.squeeze(-2) or dimension-specific squeeze)"],"exampleFix":"# before\nq, s = ops.fusedQuantizeMx(score.squeeze(), b)  # 0-dim -> raises\n# after\nq, s = ops.fusedQuantizeMx(score.reshape(1, -1), b)","handlingStrategy":"validation","validationCode":"assert a.dim() >= 1, f\"a must be >=1-D, got shape {tuple(a.shape)}\"","typeGuard":"def is_quantizable_mx(a: torch.Tensor) -> bool:\n    return a.dim() >= 1 and a.size(-1) % 32 == 0","tryCatchPattern":null,"preventionTips":["Audit all .squeeze() calls in the tensor pipeline feeding MX quantization","Normalize inputs with a = a.reshape(-1, a.size(-1)) when shape provenance is unclear"],"tags":["quantization","mx-format","fp4","validation","shape"],"backgroundTag":null,"analyzedSha":"c794754062d49a8fdb63ab3c5215b488b865030c","analyzedAt":"2026-08-14T21:17:39.825Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}