xai-org/x-algorithm · error · ValueError

spt must be a bool when provided

Error message

spt must be a bool when provided

What it means

The optional spt field on BlockSparseTensorsTorch must be a Python bool when provided. Passing a tensor, int, numpy bool, or string fails this isinstance check.

Source

Thrown at phoenix/xrex/cutedsl/ranker_fa4/block_sparsity.py:484

        context,
        hint,
        mask_cnt.device,
    )
    valid_block_lower = _check_and_expand_metadata_tensor(
        "valid_block_lower",
        tensors.valid_block_lower,
        metadata_block_shape,
        context,
        hint,
        mask_cnt.device,
    )
    if (valid_block_upper is None) != (valid_block_lower is None):
        raise ValueError(
            "valid_block_upper and valid_block_lower must both be provided or both be None"
        )
    spt = tensors.spt
    if spt is not None and not isinstance(spt, bool):
        raise ValueError("spt must be a bool when provided")
    if spt is not None and dq_write_order is None:
        raise ValueError("spt requires dq_write_order to be provided")

    return BlockSparseTensorsTorch(
        mask_block_cnt=mask_cnt,
        mask_block_idx=mask_idx,
        full_block_cnt=full_cnt,
        full_block_idx=full_idx,
        cu_total_m_blocks=tensors.cu_total_m_blocks,
        cu_block_idx_offsets=tensors.cu_block_idx_offsets,
        block_size=tensors.block_size,
        dq_write_order=dq_write_order,
        dq_write_order_full=dq_write_order_full,
        spt=spt,
        diag_block_cnt=diag_cnt,
        diag_block_idx=diag_idx,
        dq_write_order_diag=dq_write_order_diag,
        valid_block_upper=valid_block_upper,

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Pass a literal bool: tensors.spt = True/False or None
  2. When loading from config, coerce: bool(cfg['spt']) if cfg.get('spt') is not None else None
  3. Leave it None if unused

Example fix

# before
tensors.spt = np.bool_(True)

# after
tensors.spt = True  # plain Python bool (or None)
Defensive patterns

Strategy: type-guard

Validate before calling

assert tensors.spt is None or isinstance(tensors.spt, bool), type(tensors.spt)

Type guard

def is_valid_spt(v) -> bool:
    return v is None or type(v) is bool

Prevention

When it happens

Trigger: Setting tensors.spt = 1, spt = torch.tensor(True), or spt = np.bool_(True) before normalize_block_sparse_config(_bwd); also a config deserialized from JSON/YAML where the value stayed a string 'true'.

Common situations: Config loaded from YAML where booleans were quoted; converting from a settings object that stores ints; passing a 0-d tensor by accident.

Understand the failure class

Background: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.

Related errors


AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28). Data as JSON: /api/errors/455029b41ceec44f. Report an issue: GitHub.