{"record":{"id":"08a24692d19d4e8b","repo":"sgl-project/sglang","slug":"spt-requires-dq-write-order-to-be-provided","errorCode":null,"errorMessage":"spt requires dq_write_order to be provided","messagePattern":"spt requires dq_write_order to be provided","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/attention/flash_attn/cute/block_sparsity.py","lineNumber":494,"sourceCode":"        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:\n    return any(t is not None for t in (tensors.full_block_cnt, tensors.mask_block_cnt))\n","sourceCodeStart":476,"sourceCodeEnd":512,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/attention/flash_attn/cute/block_sparsity.py#L476-L512","documentation":"Raised when spt mode is enabled but dq_write_order is not supplied. The spt kernel path needs the dq write-order metadata to sequence gradient writes correctly.","triggerScenarios":"Setting BlockSparseTensorsTorch(spt=True) without dq_write_order, then calling normalize_block_sparse_tensors (e.g. via normalize_block_sparse_config_bwd).","commonSituations":"Enabling spt for the backward pass but only preparing the forward's mask/full tensors.","solutions":["Provide dq_write_order as an int32 CUDA tensor with shape equal to mask_block_idx's shape","Or unset spt (leave None/False) if the spt mode is not intended"],"exampleFix":"// before\ntensors = BlockSparseTensorsTorch(cnt, idx, spt=True)\n// after\norder = make_dq_write_order(idx.shape)  # int32, cuda\ntensors = BlockSparseTensorsTorch(cnt, idx, spt=True, dq_write_order=order)","handlingStrategy":"validation","validationCode":"if tensors.spt is not None:\n    assert tensors.dq_write_order is not None, 'spt requires dq_write_order'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When enabling spt, prepare dq_write_order (int32, CUDA, idx-shaped) at the same time","Write a single prep_spt() helper that sets both fields together"],"tags":["block-sparse","spt","missing-argument","backward"],"backgroundTag":"missing-required-parameter","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}