sgl-project/sglang · error · ValueError

refiner cu_seqlens live text length must be in [1, {int(text

Error message

refiner cu_seqlens live text length must be in [1, {int(text_embeddings_selected.shape[0])}], got {text_len}

What it means

Raised in MiniMaxH3DiTModel._embed when the live text length (refined_prompt_embeds_length) is <= 0 or exceeds the number of available refined text embedding rows (text_embeddings_selected.shape[0]). The model slices text_pos and text_embeddings by this length, so an out-of-range value would slice incorrectly or produce empty tensors.

Source

Thrown at python/sglang/multimodal_gen/runtime/models/dits/minimax_h3.py:2250

        Returns (decoder_input [S_local, H] bf16, t_emb [M, t_dim] fp32).
        """
        # BCG pads the prompt tensor only to stabilize its input signature.
        # Raw-input callers recover the live length from refiner metadata;
        # request-static refined inputs carry it as a host integer and avoid a
        # per-step device scalar read. Running the refiner at the bucketed M
        # dimension changes GEMM selection and is not bitwise equivalent.
        if refined_prompt_embeds_length is None:
            text_len = int(refiner_cu_seqlens[1].item())
        elif torch.is_tensor(refined_prompt_embeds_length):
            # BCG turns this request-varying host constant into a scalar input
            # so different live lengths can replay one padded-text signature.
            # _embed is an eager graph break, so this value is read outside
            # captured CUDA graphs.
            text_len = int(refined_prompt_embeds_length.item())
        else:
            text_len = int(refined_prompt_embeds_length)
        if text_len <= 0 or text_len > int(text_embeddings_selected.shape[0]):
            raise ValueError(
                "refiner cu_seqlens live text length must be in "
                f"[1, {int(text_embeddings_selected.shape[0])}], got {text_len}"
            )
        text_pos = text_pos[:text_len]
        if refined_prompt_embeds_length is not None:
            text_embed = text_embeddings_selected[:text_len].to(
                device=device, dtype=_BF16_DTYPE
            )
            if int(text_embed.shape[-1]) != self.hidden_size:
                raise ValueError(
                    "refined prompt embeddings must have hidden width "
                    f"{self.hidden_size}, got {int(text_embed.shape[-1])}"
                )
        else:
            text_embed = self.refine_prompt_embeds(
                text_embeddings_selected,
                refiner_cu_seqlens,
                device=device,

View on GitHub (pinned to 0132848349)

Solutions

  1. Verify refined_prompt_embeds_length equals text_embeddings_selected.shape[0] (or is within it) before calling forward
  2. Audit upstream packing/padding logic that computes the live text length for off-by-one or post-truncation mismatch
  3. If the length arrives as a device tensor, ensure it is synced/read correctly relative to graph breaks (per the comment in the source)

Example fix

// before
out = model.forward(..., refined_prompt_embeds_length=n_live, ...)
// after
assert 1 <= int(n_live) <= text_embeddings.shape[0], n_live
out = model.forward(..., refined_prompt_embeds_length=n_live, ...)
Defensive patterns

Strategy: validation

Validate before calling

n = int(refined_prompt_embeds_length.item()) if torch.is_tensor(refined_prompt_embeds_length) else int(refined_prompt_embeds_length)
assert 1 <= n <= text_embeddings_selected.shape[0], (n, text_embeddings_selected.shape[0])

Prevention

When it happens

Trigger: Calling forward with refined_prompt_embeds_length that is zero, negative, or larger than the row count of the supplied refined text embeddings tensor (e.g. padding/token-count bookkeeping that disagrees with the embedding batch dimension).

Common situations: Mismatch between the token count recorded by the scheduler/packing code and the actual rows in refined text embeddings after padding, truncation, or sequence packing; device-sync issues reading the length tensor after CUDA graph capture.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/9ab04984a0eb0d92. Report an issue: GitHub.