vllm-project/vllm · error · ValueError

`a` and `b` must be on the same device.

Error message

`a` and `b` must be on the same device.

What it means

fusedQuantizeMx() takes two device-resident tensors (a: the values to quantize, b: e.g. a per-row factor/scale input) and passes both straight into the _qutlass_C CUDA kernel. Mixed devices (a on cuda:0, b on cpu or cuda:1) would crash or silently corrupt inside the kernel, so the wrapper enforces same-device up front.

Source

Thrown at vllm/_custom_ops.py:4100

if hasattr(torch.ops._qutlass_C, "fusedQuantizeMxAbsMax"):

    @register_fake("_qutlass_C::fusedQuantizeMxAbsMax")
    def _fake_fused_quantize_mx_absmax(
        a: torch.Tensor, b: torch.Tensor, xh_e2m1: torch.Tensor, xh_e8m0: torch.Tensor
    ):
        return xh_e2m1, xh_e8m0


def fusedQuantizeMx(
    a: torch.Tensor, b: torch.Tensor, *, method: Literal["quest", "abs_max"] = "quest"
) -> tuple[torch.Tensor, torch.Tensor]:
    if a.dim() == 0:
        raise ValueError("`a` must have at least 1 dimension.")
    if a.size(-1) % 32 != 0:
        raise ValueError(f"last dim of `a` must be divisible by 32, got {a.size(-1)}.")
    if b.device != a.device:
        raise ValueError("`a` and `b` must be on the same device.")

    xh_e2m1 = torch.empty(
        *a.shape[:-1], a.size(-1) // 2, dtype=torch.uint8, device=a.device
    )

    rows, cols = a.numel() // a.size(-1), a.size(-1) // 32
    n_row_blocks = cdiv(rows, 128)
    n_col_blocks = cdiv(cols, 4)
    padded_rows = n_row_blocks * 128
    padded_cols = n_col_blocks * 4

    xh_e8m0 = torch.empty(
        padded_rows, padded_cols, dtype=torch.float8_e8m0fnu, device=a.device
    )

    if not hasattr(torch.ops, "_qutlass_C"):
        raise RuntimeError(
            "The `_qutlass_C` extension is not loaded. "

View on GitHub (pinned to c794754062)

Solutions

  1. Move b to a.device: ops.fusedQuantizeMx(a, b.to(a.device))
  2. Create b directly on the target device (torch.ones(..., device=a.device)) instead of on CPU

Example fix

# before
b = torch.load("scale.pt")                 # cpu tensor
q, s = ops.fusedQuantizeMx(a, b)
# after
b = torch.load("scale.pt").to(a.device)
q, s = ops.fusedQuantizeMx(a, b)
Defensive patterns

Strategy: validation

Validate before calling

assert b.device == a.device, f"device mismatch: a={a.device} b={b.device}"

Type guard

def same_device(a: torch.Tensor, b: torch.Tensor) -> bool:
    return a.device == b.device

Prevention

When it happens

Trigger: Calling vllm._custom_ops.fusedQuantizeMx(a, b) where b was created with device='cpu' or on another GPU (cuda:1) while a is on cuda:0; or b deserialized/loaded from safetensors to CPU and never moved.

Common situations: Forgetting .to(input.device) on a scale/bias tensor loaded from a checkpoint; multi-GPU tensor-parallel code where b was created on the rank-local device but a was already moved.

Related errors


AI-assisted analysis of vllm-project/vllm@c794754062 (2026-08-14). Data as JSON: /api/errors/e9e25c349f9d0ddf. Report an issue: GitHub.