sgl-project/sglang · error · ValueError

memory_size must be positive

Error message

memory_size must be positive

What it means

The transport memory pool's constructor validates that memory_size (the pooled byte budget) is positive before allocating the backing CUDA byte tensor. Zero or negative sizes indicate a misconfigured pool budget and are rejected immediately.

Source

Thrown at python/sglang/srt/multimodal/transport/memory_pool.py:172


class StreamOrderedMmFeaturePool:
    """Bounded GPU pool with generation-safe producer/consumer leases."""

    def __init__(
        self,
        *,
        memory_size: int,
        byte_tensor: torch.Tensor,
        base_address: int,
        device_id: int,
        consumer_count: int,
        recycle_interval: float,
        transport_name: str,
        max_inflight_slices: int = DEFAULT_MAX_INFLIGHT_SLICES,
    ) -> None:
        if memory_size <= 0:
            raise ValueError("memory_size must be positive")
        if consumer_count <= 0:
            raise ValueError("consumer_count must be positive")
        if max_inflight_slices <= 0:
            raise ValueError("max_inflight_slices must be positive")
        if recycle_interval <= 0:
            raise ValueError("recycle_interval must be positive")
        if (
            not byte_tensor.is_cuda
            or byte_tensor.device.index != device_id
            or byte_tensor.dtype != torch.uint8
            or not byte_tensor.is_contiguous()
            or byte_tensor.numel() < memory_size
        ):
            raise ValueError(
                "byte_tensor must be a sufficiently large contiguous uint8 tensor "
                f"on cuda:{device_id}"
            )

View on GitHub (pinned to 0132848349)

Solutions

  1. Set a positive memory_size (bytes) for the pool
  2. Verify unit parsing of the memory budget flag
  3. Check that reserved-size subtractions can't push the final size below 1

Example fix

# before
MemoryPoolTransport(memory_size=0, ...)
# after
MemoryPoolTransport(memory_size=512 * 1024 * 1024, ...)
Defensive patterns

Strategy: validation

Validate before calling

if memory_size is None or int(memory_size) <= 0:
    raise ValueError('memory_size must be positive bytes')

Prevention

When it happens

Trigger: Constructing the multimodal transport memory pool with memory_size <= 0 — e.g. budget flag parsed as 0 bytes or a size computation underflowing to a negative value.

Common situations: Budget flags set to 0 or omitted with broken defaults; unit confusion (MB vs bytes) truncating to 0; arithmetic that subtracts reserved sizes below zero.

Related errors


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