{"record":{"id":"455029b41ceec44f","repo":"xai-org/x-algorithm","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":"phoenix/xrex/cutedsl/ranker_fa4/block_sparsity.py","lineNumber":484,"sourceCode":"        context,\n        hint,\n        mask_cnt.device,\n    )\n    valid_block_lower = _check_and_expand_metadata_tensor(\n        \"valid_block_lower\",\n        tensors.valid_block_lower,\n        metadata_block_shape,\n        context,\n        hint,\n        mask_cnt.device,\n    )\n    if (valid_block_upper is None) != (valid_block_lower is None):\n        raise ValueError(\n            \"valid_block_upper and valid_block_lower must both be provided or both be None\"\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        diag_block_cnt=diag_cnt,\n        diag_block_idx=diag_idx,\n        dq_write_order_diag=dq_write_order_diag,\n        valid_block_upper=valid_block_upper,","sourceCodeStart":466,"sourceCodeEnd":502,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/phoenix/xrex/cutedsl/ranker_fa4/block_sparsity.py#L466-L502","documentation":"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.","triggerScenarios":"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'.","commonSituations":"Config loaded from YAML where booleans were quoted; converting from a settings object that stores ints; passing a 0-d tensor by accident.","solutions":["Pass a literal bool: tensors.spt = True/False or None","When loading from config, coerce: bool(cfg['spt']) if cfg.get('spt') is not None else None","Leave it None if unused"],"exampleFix":"# before\ntensors.spt = np.bool_(True)\n\n# after\ntensors.spt = True  # plain Python bool (or None)","handlingStrategy":"type-guard","validationCode":"assert tensors.spt is None or isinstance(tensors.spt, bool), type(tensors.spt)","typeGuard":"def is_valid_spt(v) -> bool:\n    return v is None or type(v) is bool","tryCatchPattern":null,"preventionTips":["Coerce config values: bool(v) if v is not None else None","Don't pass numpy/torch scalars into dataclass fields typed bool"],"tags":["block-sparsity","type-validation","config"],"backgroundTag":"invalid-argument-type","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}