{"record":{"id":"b380142eb635773c","repo":"sgl-project/sglang","slug":"either-quant-config-or-online-scheme-must-be-provi","errorCode":null,"errorMessage":"Either quant_config or online_scheme must be provided","messagePattern":"Either quant_config or online_scheme must be provided","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/layers/quantization/quark/quark.py","lineNumber":317,"sourceCode":"        online_scheme: Optional[str] = None,\n        dequantization_config: Optional[QuantizationConfig] = None,\n        excluded_fp8_config: Optional[Fp8Config] = None,\n    ):\n        super().__init__()\n        if kv_cache_group is None:\n            kv_cache_group = []\n\n        if online_scheme is not None:\n            assert not is_prequantized\n            if online_scheme == \"quark_mxfp4\":\n                quant_config = self._create_online_mxfp4_config(\n                    model_type=hf_config.model_type\n                )\n            else:\n                raise ValueError(f\"Unsupported online_scheme: {online_scheme}\")\n\n        if quant_config is None:\n            raise ValueError(\"Either quant_config or online_scheme must be provided\")\n\n        self.online_scheme = online_scheme\n        self.quant_config = quant_config\n        self.kv_cache_group = kv_cache_group\n        self.kv_cache_config = kv_cache_config\n        self.pack_method = pack_method\n        self.exclude_layers = cast(list[str], self.quant_config.get(\"exclude\", []))\n        # Both are consumed by _is_draft_layer(), which has to tell an appended\n        # MTP/NextN draft layer from a target-model one. \"No draft stack\" is\n        # spelled None as often as it is spelled absent -- ModelConfig defaults\n        # the same field to None -- so coerce rather than let range() raise.\n        self.num_hidden_layers = getattr(hf_config, \"num_hidden_layers\", None)\n        self.num_nextn_predict_layers = int(\n            getattr(hf_config, \"num_nextn_predict_layers\", 0) or 0\n        )\n        self.is_prequantized = is_prequantized\n        self.dequantization_config = dequantization_config\n        # Load-as-is FP8 config for excluded layers of a mixed-precision source","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/layers/quantization/quark/quark.py#L299-L335","documentation":"QuarkConfig.__init__ requires either an explicit quant_config or a recognized online_scheme; when both are absent (quant_config is None and the online_scheme branch was never taken successfully), construction is rejected with this ValueError. It is a constructor precondition guarding against a useless, unconfigured instance.","triggerScenarios":"Constructing QuarkConfig(hf_config=..., ...) passing neither quant_config nor online_scheme; or passing online_scheme=None/empty with no quant_config (from_config only reaches this when the checkpoint provided no usable quant config and no requantization method).","commonSituations":"Programmatic use of QuarkConfig by subclass/tooling that forgets to forward the quant config; checkpoints with missing or empty quant_config sections combined with a requantization_method of None; refactors that drop the config argument.","solutions":["Pass a quant_config dict from the checkpoint (e.g. the contents of quant_config.json / hf_config.quantization_config), or pass online_scheme=\"quark_mxfp4\".","If loading from a checkpoint, verify the quantization_config section exists and is forwarded: QuarkConfig.from_config(quant_config=config, hf_config=hf_config, ...).","Pre-validate the checkpoint has a quant config before constructing (see validation code)."],"exampleFix":"# before\nqc = QuarkConfig(hf_config=hf_config)  # raises ValueError\n\n# after\nqc = QuarkConfig(quant_config=raw_quant_config, hf_config=hf_config, kv_cache_group=None, kv_cache_config=None)","handlingStrategy":"validation","validationCode":"if quant_config is None and online_scheme not in (\"quark_mxfp4\",):\n    raise ValueError(\"Must pass quant_config or online_scheme='quark_mxfp4'\")\ncfg = QuarkConfig(quant_config=quant_config, hf_config=hf_config, ...)","typeGuard":"def has_quark_config_source(quant_config, online_scheme) -> bool:\n    return quant_config is not None or online_scheme == \"quark_mxfp4\"","tryCatchPattern":"try:\n    QuarkConfig(hf_config=hf_config, **kwargs)\nexcept ValueError as e:\n    if \"quant_config or online_scheme\" in str(e):\n        kwargs[\"quant_config\"] = load_checkpoint_quant_config(model_path)\n    raise","preventionTips":["Assert quantization_config exists in the HF config before constructing QuarkConfig.","Centralize QuarkConfig construction in one factory that fills defaults.","Log which of quant_config/online_scheme was used at startup."],"tags":["quantization","quark","constructor","required-argument","python"],"backgroundTag":"missing-required-config","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}