xai-org/x-algorithm · error · ValueError
{name} must have dtype torch.int32
Error message
{name} must have dtype torch.int32 What it means
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.
Source
Thrown at phoenix/xrex/cutedsl/ranker_fa4/block_sparsity.py:267
expected_index_shape = (*expected_index_shape[:3], idx.shape[3])
expanded_idx = _expand_sparsity_tensor(
idx, expected_index_shape, f"{name}_block_idx", context, hint
)
return expanded_cnt, expanded_idx
def _check_and_expand_metadata_tensor(
name: str,
tensor: torch.Tensor | None,
expected_shape: Tuple[int, ...],
context: str | None,
hint: str | Callable[[], str] | None,
device: torch.device,
) -> torch.Tensor | None:
if tensor is None:
return None
if tensor.dtype != torch.int32:
raise ValueError(f"{name} must have dtype torch.int32")
if tensor.device != device:
raise ValueError(f"{name} must be on the same device as block sparse tensors")
if not tensor.is_cuda:
raise ValueError(f"{name} must live on CUDA")
return _expand_sparsity_tensor(tensor, expected_shape, name, context, hint)
def get_block_sparse_expected_shapes(
batch_size: int,
num_head: int,
seqlen_q: int,
seqlen_k: int,
m_block_size: int,
n_block_size: int,
q_stage: int,
) -> Tuple[Tuple[int, int, int], Tuple[int, int, int, int]]:
m_block_size_effective = q_stage * m_block_size
expected_m_blocks = ceildiv(seqlen_q, m_block_size_effective)View on GitHub (pinned to 24c60942c5)
Solutions
- Cast the tensor: t = t.to(torch.int32)
- Create it with dtype=torch.int32 from the start
- Add a pre-call dtype assert
Example fix
# before seqlens = torch.tensor([128, 256, 64]) # int64 # after seqlens = torch.tensor([128, 256, 64], dtype=torch.int32, device='cuda')
Defensive patterns
Strategy: validation
Validate before calling
assert meta is None or meta.dtype == torch.int32, f"expected int32, got {meta.dtype}" Type guard
def is_int32(t: torch.Tensor) -> bool:
return t.dtype == torch.int32 Prevention
- Always pass dtype=torch.int32 when creating metadata tensors
- Cast with .to(torch.int32) at the boundary of your pipeline
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- {name}_block_cnt and {name}_block_idx must be on the same de
- {name}_block tensors must live on CUDA
- {name} must be on the same device as block sparse tensors
- {name} must live on CUDA
- mask_block_cnt and mask_block_idx must be provided for block
AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28).
Data as JSON: /api/errors/8ea87d8494338d32.
Report an issue: GitHub.