{"record":{"id":"8ea87d8494338d32","repo":"xai-org/x-algorithm","slug":"name-must-have-dtype-torch-int32","errorCode":null,"errorMessage":"{name} must have dtype torch.int32","messagePattern":"(.+?) must have dtype torch\\.int32","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"phoenix/xrex/cutedsl/ranker_fa4/block_sparsity.py","lineNumber":267,"sourceCode":"        expected_index_shape = (*expected_index_shape[:3], idx.shape[3])\n    expanded_idx = _expand_sparsity_tensor(\n        idx, expected_index_shape, f\"{name}_block_idx\", context, hint\n    )\n    return expanded_cnt, expanded_idx\n\n\ndef _check_and_expand_metadata_tensor(\n    name: str,\n    tensor: torch.Tensor | None,\n    expected_shape: Tuple[int, ...],\n    context: str | None,\n    hint: str | Callable[[], str] | None,\n    device: torch.device,\n) -> torch.Tensor | None:\n    if tensor is None:\n        return None\n    if tensor.dtype != torch.int32:\n        raise ValueError(f\"{name} must have dtype torch.int32\")\n    if tensor.device != device:\n        raise ValueError(f\"{name} must be on the same device as block sparse tensors\")\n    if not tensor.is_cuda:\n        raise ValueError(f\"{name} must live on CUDA\")\n    return _expand_sparsity_tensor(tensor, expected_shape, name, context, hint)\n\n\ndef get_block_sparse_expected_shapes(\n    batch_size: int,\n    num_head: int,\n    seqlen_q: int,\n    seqlen_k: int,\n    m_block_size: int,\n    n_block_size: int,\n    q_stage: int,\n) -> Tuple[Tuple[int, int, int], Tuple[int, int, int, int]]:\n    m_block_size_effective = q_stage * m_block_size\n    expected_m_blocks = ceildiv(seqlen_q, m_block_size_effective)","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/phoenix/xrex/cutedsl/ranker_fa4/block_sparsity.py#L249-L285","documentation":"Raised by _check_and_expand_metadata_tensor (called from normalize_block_sparse_tensors) when an auxiliary metadata tensor (e.g. a seqlen or schedule tensor) is provided but its dtype is not torch.int32. The kernels read these as 32-bit integers, so float/int64 tensors are rejected.","triggerScenarios":"Passing a metadata tensor created with default dtype (float32), torch.long/int64 (e.g. from torch.tensor([...])), or torch.int16 to the block-sparse normalization path.","commonSituations":"Building metadata with torch.tensor(list) which defaults to int64; converting from numpy int64 arrays; mixing dtypes when metadata comes from a different component than the block tensors.","solutions":["Cast the tensor: t = t.to(torch.int32)","Create it with dtype=torch.int32 from the start","Add a pre-call dtype assert"],"exampleFix":"# before\nseqlens = torch.tensor([128, 256, 64])  # int64\n\n# after\nseqlens = torch.tensor([128, 256, 64], dtype=torch.int32, device='cuda')","handlingStrategy":"validation","validationCode":"assert meta is None or meta.dtype == torch.int32, f\"expected int32, got {meta.dtype}\"","typeGuard":"def is_int32(t: torch.Tensor) -> bool:\n    return t.dtype == torch.int32","tryCatchPattern":null,"preventionTips":["Always pass dtype=torch.int32 when creating metadata tensors","Cast with .to(torch.int32) at the boundary of your pipeline"],"tags":["pytorch","dtype","block-sparsity","validation"],"backgroundTag":"pytorch-wrong-tensor-dtype","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}