sgl-project/sglang · error · RuntimeError

duplicate auxiliary PP tensor {name!r}

Error message

duplicate auxiliary PP tensor {name!r}

What it means

The namespaced key for an auxiliary tensor already exists in the PP tensor dict, indicating the same output name was added twice (duplicate names across outputs or repeated call).

Source

Thrown at python/sglang/srt/sampling/sampling_observer_pp.py:57

    if output is None:
        return
    if not isinstance(output, PipelineParallelAuxiliaryOutput):
        raise RuntimeError(
            "auxiliary output does not support pipeline-parallel transport"
        )

    output_tensors = output.to_pp_tensors()
    if not output_tensors:
        raise RuntimeError("auxiliary PP output must contain at least one tensor")

    for name, tensor in output_tensors.items():
        if not isinstance(name, str) or not name:
            raise RuntimeError("auxiliary PP tensor names must be non-empty strings")
        if not torch.is_tensor(tensor):
            raise RuntimeError(f"auxiliary PP output {name!r} is not a tensor")
        key = f"{_OUTPUT_PREFIX}{name}"
        if key in tensors:
            raise RuntimeError(f"duplicate auxiliary PP tensor {name!r}")
        tensors[key] = tensor


def pop_auxiliary_output_from_pp_tensors(
    tensors: MutableMapping[str, Any],
    observer: Optional[SamplingObserver],
) -> Optional[DeviceAuxiliaryOutput]:
    output_tensors = {
        key.removeprefix(_OUTPUT_PREFIX): value
        for key, value in tensors.items()
        if key.startswith(_OUTPUT_PREFIX)
    }
    if not output_tensors:
        return None
    if observer is None:
        raise RuntimeError("received auxiliary PP output without a sampling observer")
    if not isinstance(observer, PipelineParallelSamplingObserver):
        raise RuntimeError(

View on GitHub (pinned to 0132848349)

Solutions

  1. Namespace the tensor names per output (e.g. 'encoder.logits', 'decoder.logits')
  2. Only add each output once per batch step

Example fix

# before
return {"logits": a}  # in both outputs
# after
return {"encoder_logits": a}  # and {"decoder_logits": b}
Defensive patterns

Strategy: validation

Validate before calling

PREFIX = "sglang_aux_output."  # must match module's _OUTPUT_PREFIX
new_keys = {f"{PREFIX}{k}" for k in output.to_pp_tensors()}
assert not (new_keys & set(tensors)), "name collision"

Prevention

When it happens

Trigger: Calling add_auxiliary_output_to_pp_tensors twice, or multiple outputs whose to_pp_tensors() share a field name.

Common situations: Attaching per-layer auxiliary outputs that each emit e.g. 'logits'; refactoring merged outputs with colliding field names.

Related errors


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