sgl-project/sglang · error · ValueError

Unexpected compressed-MLA dst_kv_ptrs length {len(dst_kv_ptr

Error message

Unexpected compressed-MLA dst_kv_ptrs length {len(dst_kv_ptrs)}; expected either {kv_layout_len} (kv_data) or swa_L + {2 * c4_full} (state_data) given compression_ratios (c4={c4_full}, c128={c128_full}, total={len(mla_ratios)}).

What it means

Raised by _mla_slice_ptrs_for_pp when slicing destination KV pointers for pipeline-parallel transfer of compressed-MLA data. It infers whether dst_kv_ptrs is a kv_data list (expected length kv_layout_len) or a state_data list (swa_L + 2*c4_full); if the length fits neither interpretation given the model's compression_ratios, the pointer layout is unrecognized.

Source

Thrown at python/sglang/srt/disaggregation/common/conn.py:1032

        if (
            state_type not in (StateType.SWA, StateType.SWA_RING, StateType.C128_STATE)
            and len(dst_kv_ptrs) == kv_layout_len
        ):
            sliced_dst = (
                list(dst_kv_ptrs[c4_off_s:c4_off_e])
                + list(dst_kv_ptrs[c4_full + c4_off_s : c4_full + c4_off_e])
                + list(dst_kv_ptrs[2 * c4_full + c128_off_s : 2 * c4_full + c128_off_e])
            )
            return src_kv_ptrs, sliced_dst

        # SWA state-data layout. ``swa_L`` is derived from the actual dst
        # length so we tolerate cases where the SWA pool has fewer buffers
        # than ``len(mla_ratios)`` (e.g. nextn padding). C128 state ships as
        # a separate StateType.C128_STATE component and must not be counted
        # here.
        swa_L = len(dst_kv_ptrs) - 2 * c4_full
        if swa_L < 0 or swa_L > len(mla_ratios):
            raise ValueError(
                f"Unexpected compressed-MLA dst_kv_ptrs length "
                f"{len(dst_kv_ptrs)}; expected either {kv_layout_len} "
                f"(kv_data) or swa_L + {2 * c4_full} "
                f"(state_data) given compression_ratios "
                f"(c4={c4_full}, c128={c128_full}, "
                f"total={len(mla_ratios)})."
            )

        swa_s = min(start_layer, swa_L)
        swa_e = min(end_layer, swa_L)
        compress_section_start = swa_L
        indexer_section_start = swa_L + c4_full
        sliced_dst = (
            list(dst_kv_ptrs[swa_s:swa_e])
            + list(
                dst_kv_ptrs[
                    compress_section_start
                    + c4_off_s : compress_section_start

View on GitHub (pinned to 0132848349)

Solutions

  1. Check that the transfer backend's destination allocation for compressed-MLA produces exactly one pointer per entry in compression_ratios (state) or matches kv_layout_len (data)
  2. Log len(dst_kv_ptrs), c4_full, c128_full and len(mla_ratios) at the call site to identify which layout was intended, then fix the allocator accordingly
  3. If model support is the issue, verify compression_ratios for your model are in the expected order/format
Defensive patterns

Strategy: try-catch

Validate before calling

expected_state = swa_L + 2 * c4_full
assert len(dst_kv_ptrs) in (kv_layout_len, expected_state)

Try / catch

try:
    ptrs = _mla_slice_ptrs_for_pp(...)
except ValueError as e:
    logger.error('dst ptr layout unrecognized: %s', e)
    raise

Prevention

When it happens

Trigger: Calling get_mla_kv_ptrs_with_pp / _mla_slice_ptrs_for_pp where dst_kv_ptrs length < 2*c4_full or exceeds len(mla_ratios) + 2*c4_full, e.g. a transfer backend returning wrong number of destination buffers for compressed MLA (DSA/SWA) pools.

Common situations: A new or updated MLA model with unusual compression_ratios (c4/c128 layout) that the slicer doesn't account for; a custom transfer backend building the dst pointer list with missing or extra buffers; nextn/SWA padding edge cases.

Related errors


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