{"record":{"id":"c85599949f53c7b5","repo":"sgl-project/sglang","slug":"mask-strategy-cannot-be-none-for-slidingtileattent","errorCode":null,"errorMessage":"mask_strategy cannot be None for SlidingTileAttention","messagePattern":"mask_strategy cannot be None for SlidingTileAttention","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/layers/attention/backends/sliding_tile_attn.py","lineNumber":208,"sourceCode":"        )\n        return self.tile(qkv)\n\n    def postprocess_output(\n        self,\n        output: torch.Tensor,\n        attn_metadata: SlidingTileAttentionMetadata,\n    ) -> torch.Tensor:\n        return self.untile(output)\n\n    def forward(\n        self,\n        q: torch.Tensor,\n        k: torch.Tensor,\n        v: torch.Tensor,\n        attn_metadata: SlidingTileAttentionMetadata,\n    ) -> torch.Tensor:\n        if self.mask_strategy is None:\n            raise ValueError(\"mask_strategy cannot be None for SlidingTileAttention\")\n        if self.mask_strategy[0] is None:\n            raise ValueError(\"mask_strategy[0] cannot be None for SlidingTileAttention\")\n\n        timestep = attn_metadata.current_timestep\n        forward_context: ForwardContext = get_forward_context()\n        forward_batch = forward_context.forward_batch\n        if forward_batch is None:\n            raise ValueError(\"forward_batch cannot be None\")\n        # pattern:'.double_blocks.0.attn.impl' or '.single_blocks.0.attn.impl'\n        layer_idx = int(self.prefix.split(\".\")[-3])\n        if attn_metadata.STA_param is None or len(attn_metadata.STA_param) <= layer_idx:\n            raise ValueError(\"Invalid STA_param\")\n        STA_param = attn_metadata.STA_param[layer_idx]\n\n        text_length = q.shape[1] - self.img_seq_length\n        has_text = text_length > 0\n\n        query = q.transpose(1, 2).contiguous()","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/layers/attention/backends/sliding_tile_attn.py#L190-L226","documentation":"STA forward needs a loaded timestep-indexed mask strategy (loaded in __init__ from the mask JSON). If self.mask_strategy is None the tile masks cannot be selected for the current timestep, so forward refuses to run.","triggerScenarios":"Calling forward on a SlidingTileAttentionBackend whose mask_strategy attribute is None — instance bypassed __init__, or the attribute was cleared/reset.","commonSituations":"Mocking/deepcopying backends in tests that drop the attribute; partial init after a swallowed config-load error; serialization frameworks skipping large list attributes.","solutions":["Ensure the backend is constructed normally so mask_strategy loads from the JSON","If it is None, re-run the load: self.mask_strategy = dict_to_3d_list(json.load(open(path)))","Guard at init: fail fast if the mask file cannot be loaded rather than at forward time"],"exampleFix":"# before\nout = sta_backend.forward(q, k, v, meta)  # mask_strategy is None\n# after\nif sta_backend.mask_strategy is None:\n    sta_backend.mask_strategy = dict_to_3d_list(json.load(open(mask_strategy_path)))\nout = sta_backend.forward(q, k, v, meta)","handlingStrategy":"validation","validationCode":"assert backend.mask_strategy is not None, \"mask_strategy not loaded; check mask file path in __init__\"","typeGuard":"def sta_ready(b) -> bool:\n    return getattr(b, \"mask_strategy\", None) is not None","tryCatchPattern":"try:\n    out = b.forward(q, k, v, meta)\nexcept ValueError as e:\n    if \"mask_strategy\" in str(e):\n        b.mask_strategy = dict_to_3d_list(json.load(open(mask_path)))\n        out = b.forward(q, k, v, meta)","preventionTips":["Ensure backends are constructed via their real __init__ (no mocking that drops state)","Re-validate state after deepcopy/serialization"],"tags":["sliding-tile-attention","mask-strategy","none-check","forward"],"backgroundTag":"required-state-missing","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}