sgl-project/sglang · error · ValueError

Not enough data points for quadratic fitting ({len(L)} < 8).

Error message

Not enough data points for quadratic fitting ({len(L)} < 8). Need at least 8 samples with different sequence lengths.

What it means

The pipeline-parallel chunk-size predictor needs at least 8 (post-warmup-discard) latency samples at different sequence lengths to fit its quadratic f(l)=al²+bl+c model; fewer than 8 remain after dropping the first point.

Source

Thrown at python/sglang/srt/managers/scheduler_pp_mixin.py:1530

    Models latency as: f(l) = a*l^2 + b*l + c
    Predicts next chunk size x such that: f(L+x) - f(L) = target_latency
    """

    def __init__(self):
        self.quadratic_coeff_a = 0.0
        self.linear_coeff_b = 0.0
        self.constant_coeff_c = 0.0
        self.target_latency: Optional[float] = None
        self.is_ready = False

    def fit(self, seq_lens: List[int], latencies: List[float]):
        """Fit quadratic coefficients f(l) = al^2 + bl + c from data points."""
        # Skip the first data point to reduce fitting bias, as the first run is slower without warmup
        L = np.array(seq_lens[1:], dtype=np.float64)
        T = np.array(latencies[1:], dtype=np.float64)

        if len(L) < 8:
            raise ValueError(
                f"Not enough data points for quadratic fitting ({len(L)} < 8). "
                "Need at least 8 samples with different sequence lengths."
            )

        # Build design matrix for f(l) = al^2 + bl + c
        X = np.column_stack([L * L, L, np.ones_like(L)])  # [l^2, l, 1]

        try:
            coeffs, residuals, rank, s = np.linalg.lstsq(X, T, rcond=None)
            if len(coeffs) >= 3:
                fitted_a = float(coeffs[0])  # quadratic coefficient
                fitted_b = float(coeffs[1])  # linear coefficient
                fitted_c = float(coeffs[2])  # constant coefficient
            else:
                raise ValueError("Failed to fit coefficients: insufficient rank")
        except np.linalg.LinAlgError as e:
            raise ValueError(f"Failed to fit f(l) = al^2 + bl + c: {e}")

View on GitHub (pinned to 0132848349)

Solutions

  1. Increase the number of profiling sequence lengths to at least 9 (8 after the first is dropped)
  2. Use the default PP profiling configuration
  3. If writing a test, seed the predictor directly instead of running a short profile
Defensive patterns

Strategy: validation

Validate before calling

assert len(seq_lens) >= 9, 'need >=9 samples (first is dropped); got %d' % len(seq_lens)

Try / catch

try:
    predictor.fit(seq_lens, latencies)
except ValueError as e:
    if 'Not enough data points' in str(e):
        extend_profiling_lengths(); reprofile()
    raise

Prevention

When it happens

Trigger: Running profile_and_init_predictor (PP warmup/chunked-prefill profiling) with a profiling schedule that yields fewer than 9 total samples — e.g. few profiling lengths configured or short profiling budget.

Common situations: Custom or reduced warmup configs; CI/smoke tests that shrink the profiling loop; changes to the number of profiled sequence lengths.

Related errors


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