sgl-project/sglang · error · ValueError

spt must be a bool when provided

Error message

spt must be a bool when provided

What it means

The `spt` argument to the block-sparse attention op must be a boolean when provided. Pass True/False or omit it; None is only allowed when omitted.

Solutions

  1. Coerce to bool when loading config: spt=bool(cfg['spt'])
  2. Assign True/False directly

Example fix

// before
tensors.spt = cfg['spt']  # 'true' (str)
// after
tensors.spt = bool(cfg['spt'])
Defensive patterns

Strategy: type-guard

Validate before calling

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

Type guard

def valid_spt(s): return s is None or isinstance(s, bool)

Prevention

When it happens

Trigger: Setting tensors.spt = 1, 'true', or a torch tensor instead of True/False before normalize_block_sparse_tensors.

Common situations: Loading config from JSON/YAML where spt arrives as a string/int and is assigned verbatim.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/b7e43b2df5720c8f. Report an issue: GitHub.

Appendix: source

Thrown at python/sglang/kernels/ops/attention/flash_attn/cute/block_sparsity.py:492

    dq_write_order = _check_and_expand_metadata_tensor(
        "dq_write_order",
        tensors.dq_write_order,
        tuple(mask_idx.shape),
        context,
        hint,
        mask_cnt.device,
    )
    dq_write_order_full = _check_and_expand_metadata_tensor(
        "dq_write_order_full",
        tensors.dq_write_order_full,
        tuple(full_idx.shape) if full_idx is not None else expected_index_shape,
        context,
        hint,
        mask_cnt.device,
    )
    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,
    )


def is_block_sparsity_enabled(tensors: BlockSparseTensorsTorch) -> bool:

View on GitHub (pinned to 0132848349)