{"record":{"id":"b7e43b2df5720c8f","repo":"sgl-project/sglang","slug":"spt-must-be-a-bool-when-provided","errorCode":null,"errorMessage":"spt must be a bool when provided","messagePattern":"spt must be a bool when provided","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/attention/flash_attn/cute/block_sparsity.py","lineNumber":492,"sourceCode":"    dq_write_order = _check_and_expand_metadata_tensor(\n        \"dq_write_order\",\n        tensors.dq_write_order,\n        tuple(mask_idx.shape),\n        context,\n        hint,\n        mask_cnt.device,\n    )\n    dq_write_order_full = _check_and_expand_metadata_tensor(\n        \"dq_write_order_full\",\n        tensors.dq_write_order_full,\n        tuple(full_idx.shape) if full_idx is not None else expected_index_shape,\n        context,\n        hint,\n        mask_cnt.device,\n    )\n    spt = tensors.spt\n    if spt is not None and not isinstance(spt, bool):\n        raise ValueError(\"spt must be a bool when provided\")\n    if spt is not None and dq_write_order is None:\n        raise ValueError(\"spt requires dq_write_order to be provided\")\n\n    return BlockSparseTensorsTorch(\n        mask_block_cnt=mask_cnt,\n        mask_block_idx=mask_idx,\n        full_block_cnt=full_cnt,\n        full_block_idx=full_idx,\n        cu_total_m_blocks=tensors.cu_total_m_blocks,\n        cu_block_idx_offsets=tensors.cu_block_idx_offsets,\n        block_size=tensors.block_size,\n        dq_write_order=dq_write_order,\n        dq_write_order_full=dq_write_order_full,\n        spt=spt,\n    )\n\n\ndef is_block_sparsity_enabled(tensors: BlockSparseTensorsTorch) -> bool:","sourceCodeStart":474,"sourceCodeEnd":510,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/attention/flash_attn/cute/block_sparsity.py#L474-L510","documentation":"Raised when the spt field of BlockSparseTensorsTorch is provided but is not a Python bool. spt toggles a special kernel mode and is a flag, not a tensor.","triggerScenarios":"Setting tensors.spt = 1, 'true', or a torch tensor instead of True/False before normalize_block_sparse_tensors.","commonSituations":"Loading config from JSON/YAML where spt arrives as a string/int and is assigned verbatim.","solutions":["Coerce to bool when loading config: spt=bool(cfg['spt'])","Assign True/False directly"],"exampleFix":"// before\ntensors.spt = cfg['spt']  # 'true' (str)\n// after\ntensors.spt = bool(cfg['spt'])","handlingStrategy":"type-guard","validationCode":"assert tensors.spt is None or isinstance(tensors.spt, bool)","typeGuard":"def valid_spt(s): return s is None or isinstance(s, bool)","tryCatchPattern":null,"preventionTips":["Coerce config-loaded flags with bool(...)","Never assign tensors or strings to spt"],"tags":["block-sparse","type-error","spt"],"backgroundTag":"invalid-argument-type","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}