{"record":{"id":"6990fb185d41b96f","repo":"sgl-project/sglang","slug":"fitted-quadratic-coefficient-a-fitted-a-2e-is-n","errorCode":null,"errorMessage":"Fitted quadratic coefficient a={fitted_a:.2e} is not positive. Attention has O(n^2) complexity, so a must be positive. Check warmup data quality.","messagePattern":"Fitted quadratic coefficient a=(.+?) is not positive\\. Attention has O\\(n\\^2\\) complexity, so a must be positive\\. Check warmup data quality\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/managers/scheduler_pp_mixin.py","lineNumber":1551,"sourceCode":"            )\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\n        # Validate coefficients\n        if fitted_a <= 0:\n            raise ValueError(\n                f\"Fitted quadratic coefficient a={fitted_a:.2e} is not positive. \"\n                \"Attention has O(n^2) complexity, so a must be positive. \"\n                \"Check warmup data quality.\"\n            )\n\n        if fitted_b < 0:\n            logger.warning(\n                f\"Fitted linear coefficient b={fitted_b:.2e} is negative. Setting b=0.\"\n            )\n            fitted_b = 0.0\n\n        self.quadratic_coeff_a = fitted_a\n        self.linear_coeff_b = fitted_b\n        self.constant_coeff_c = fitted_c\n\n        logger.info(\n            f\"[ChunkSizePredictor] Fitted coefficients: a={fitted_a:.2e}, \"\n            f\"b={fitted_b:.2e}, c={fitted_c:.2e}\"","sourceCodeStart":1533,"sourceCodeEnd":1569,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/managers/scheduler_pp_mixin.py#L1533-L1569","documentation":"The fitted quadratic coefficient a<=0, but attention latency must grow quadratically (a>0). This means the warmup latency data is unphysical — noise, flat measurements, or lengths outside the quadratic regime.","triggerScenarios":"Latency samples during profile_and_init_predictor are flat/noisy enough that lstsq fits a<=0 for the l² term (e.g. lengths too small, GPU not warmed up, noisy shared machine).","commonSituations":"Profiling on a busy/shared GPU, very short profiled lengths where quadratic term is negligible, throttling during warmup.","solutions":["Re-run profiling on an idle GPU after full warmup","Use larger/longer profiling sequence lengths so the quadratic term dominates","Increase number of samples to average out noise"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"assert all(t > 0 for t in latencies[1:]), 'non-positive latency sample'","typeGuard":null,"tryCatchPattern":"try:\n    predictor.fit(...)\nexcept ValueError as e:\n    if 'not positive' in str(e):\n        reprofile_on_idle_gpu()\n    raise","preventionTips":["Profile on idle GPUs after warmup","Use longer sequence lengths so the quadratic term dominates noise"],"tags":["pipeline-parallel","profiling","data-quality"],"backgroundTag":"insufficient-data-for-fit","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}