{"record":{"id":"c60e0c3653fc02ce","repo":"sgl-project/sglang","slug":"not-enough-data-points-for-quadratic-fitting-len","errorCode":null,"errorMessage":"Not enough data points for quadratic fitting ({len(L)} < 8). Need at least 8 samples with different sequence lengths.","messagePattern":"Not enough data points for quadratic fitting \\((.+?) < 8\\)\\. Need at least 8 samples with different sequence lengths\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/managers/scheduler_pp_mixin.py","lineNumber":1530,"sourceCode":"    Models latency as: f(l) = a*l^2 + b*l + c\n    Predicts next chunk size x such that: f(L+x) - f(L) = target_latency\n    \"\"\"\n\n    def __init__(self):\n        self.quadratic_coeff_a = 0.0\n        self.linear_coeff_b = 0.0\n        self.constant_coeff_c = 0.0\n        self.target_latency: Optional[float] = None\n        self.is_ready = False\n\n    def fit(self, seq_lens: List[int], latencies: List[float]):\n        \"\"\"Fit quadratic coefficients f(l) = al^2 + bl + c from data points.\"\"\"\n        # Skip the first data point to reduce fitting bias, as the first run is slower without warmup\n        L = np.array(seq_lens[1:], dtype=np.float64)\n        T = np.array(latencies[1:], dtype=np.float64)\n\n        if len(L) < 8:\n            raise ValueError(\n                f\"Not enough data points for quadratic fitting ({len(L)} < 8). \"\n                \"Need at least 8 samples with different sequence lengths.\"\n            )\n\n        # Build design matrix for f(l) = al^2 + bl + c\n        X = np.column_stack([L * L, L, np.ones_like(L)])  # [l^2, l, 1]\n\n        try:\n            coeffs, residuals, rank, s = np.linalg.lstsq(X, T, rcond=None)\n            if len(coeffs) >= 3:\n                fitted_a = float(coeffs[0])  # quadratic coefficient\n                fitted_b = float(coeffs[1])  # linear coefficient\n                fitted_c = float(coeffs[2])  # constant coefficient\n            else:\n                raise ValueError(\"Failed to fit coefficients: insufficient rank\")\n        except np.linalg.LinAlgError as e:\n            raise ValueError(f\"Failed to fit f(l) = al^2 + bl + c: {e}\")\n","sourceCodeStart":1512,"sourceCodeEnd":1548,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/managers/scheduler_pp_mixin.py#L1512-L1548","documentation":"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.","triggerScenarios":"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.","commonSituations":"Custom or reduced warmup configs; CI/smoke tests that shrink the profiling loop; changes to the number of profiled sequence lengths.","solutions":["Increase the number of profiling sequence lengths to at least 9 (8 after the first is dropped)","Use the default PP profiling configuration","If writing a test, seed the predictor directly instead of running a short profile"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"assert len(seq_lens) >= 9, 'need >=9 samples (first is dropped); got %d' % len(seq_lens)","typeGuard":null,"tryCatchPattern":"try:\n    predictor.fit(seq_lens, latencies)\nexcept ValueError as e:\n    if 'Not enough data points' in str(e):\n        extend_profiling_lengths(); reprofile()\n    raise","preventionTips":["Keep the default profiling schedule","When customizing, ensure at least 9 distinct lengths"],"tags":["pipeline-parallel","profiling","chunked-prefill"],"backgroundTag":"insufficient-data-for-fit","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}