{"record":{"id":"825774dce0a17a75","repo":"sgl-project/sglang","slug":"krea-2-sequence-parallelism-does-not-support-ragge","errorCode":null,"errorMessage":"Krea-2 sequence parallelism does not support ragged/padded multi-prompt batches; use a single prompt or --tp-size.","messagePattern":"Krea-2 sequence parallelism does not support ragged/padded multi-prompt batches; use a single prompt or --tp-size\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/configs/pipeline_configs/krea2.py","lineNumber":89,"sourceCode":"        patch = self.dit_config.arch_config.patch\n        vsf = self.get_vae_scale_factor()\n        h_tok = int(batch.height) // vsf // patch\n        w_tok = int(batch.width) // vsf // patch\n\n        img_ids = torch.zeros(h_tok, w_tok, 3, device=device)\n        img_ids[..., 1] = torch.arange(h_tok, device=device)[:, None]\n        img_ids[..., 2] = torch.arange(w_tok, device=device)[None, :]\n        img_pos = img_ids.reshape(h_tok * w_tok, 3).unsqueeze(0).expand(b, -1, -1)\n        txt_pos = torch.zeros(b, txt_len, 3, device=device)\n\n        sp_world_size = get_sp_world_size()\n        if sp_world_size > 1:\n            # Shard the image RoPE positions to match the denoise stage's latent\n            # sharding; the text prefix stays replicated (kept out of the all-to-all\n            # via num_replicated_prefix). The masked path is incompatible with\n            # replicated-prefix, so ragged multi-prompt batches aren't supported.\n            if text_mask is not None and not bool(text_mask.all()):\n                raise ValueError(\n                    \"Krea-2 sequence parallelism does not support ragged/padded \"\n                    \"multi-prompt batches; use a single prompt or --tp-size.\"\n                )\n            img_pos = self._shard_img_pos_for_sp(img_pos, sp_world_size)\n            return {\"pos\": torch.cat([txt_pos, img_pos], dim=1), \"mask\": None}\n\n        pos = torch.cat([txt_pos, img_pos], dim=1)\n        img_mask = torch.ones(b, h_tok * w_tok, dtype=torch.bool, device=device)\n        if text_mask is None:\n            txt_mask = torch.ones(b, txt_len, dtype=torch.bool, device=device)\n        else:\n            txt_mask = text_mask.to(device=device).bool()\n        mask = torch.cat([txt_mask, img_mask], dim=1)\n        return {\"pos\": pos, \"mask\": mask}\n\n    @staticmethod\n    def _shard_img_pos_for_sp(img_pos, sp_world_size):\n        # This rank's contiguous image-position slice, padded to a multiple of","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/configs/pipeline_configs/krea2.py#L71-L107","documentation":"Krea-2's sequence-parallel (SP) path shards image RoPE positions across SP ranks while keeping the text prefix replicated (via num_replicated_prefix). The masked-text path (used for ragged/padded multi-prompt batches) is incompatible with replicated-prefix all-to-all, so the pipeline rejects any batch where the text mask contains padding/multiple prompts.","triggerScenarios":"Running Krea-2 generation with --sp-size > 1 (sp_world_size > 1) and a batch containing multiple prompts or padded text, i.e. text_mask is not None and not all True — for example passing a list of prompts of differing lengths so the tokenizer pads them, hitting _build_pos_and_mask via prepare_pos_cond_kwargs/prepare_neg_cond_kwargs.","commonSituations":"Switching from single-prompt to multi-prompt or batched generation on a multi-GPU SP deployment; enabling sequence parallelism on an existing batched workload; using reference-image duplication with several prompts while SP is on.","solutions":["Use a single prompt per batch when SP is enabled (one prompt per request)","Disable/avoid sequence parallelism for multi-prompt batches — use tensor parallelism (--tp-size) instead","If batching is required, ensure all prompts tokenize to identical lengths so no padding mask is produced (text_mask.all() is True)","Check that the server was not started with an SP size > 1 for this model if you need ragged batches"],"exampleFix":"# before\nprompts = [\"a cat\", \"a much longer prompt about a dog\"]  # padded batch with --sp-size 2\n\n# after\n# one prompt per generate call with SP enabled\nimage = pipe(prompt=\"a cat\")\n# or launch server with --tp-size 2 instead of --sp-size 2 for batching","handlingStrategy":"validation","validationCode":"sp = get_sp_world_size()\nif sp > 1:\n    assert len(prompts) == 1 or all_equal_tokenized_lengths(prompts, tokenizer), \\\n        \"Krea-2 SP does not support ragged multi-prompt batches\"","typeGuard":null,"tryCatchPattern":"except ValueError as e:\n    if \"ragged/padded multi-prompt\" in str(e):\n        # fall back to single-prompt requests or TP\n        for p in prompts: run_single(p)","preventionTips":["Run multi-prompt workloads with --tp-size, not --sp-size, on Krea-2","Keep batch size 1 when SP is enabled","Log sp_world_size at request time to catch misconfigured deployments"],"tags":["sglang","krea-2","sequence-parallelism","multi-prompt","batching","diffusion"],"backgroundTag":"parallelism-unsupported-batch-shape","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}