{"record":{"id":"4ca23217c41e5dc2","repo":"sgl-project/sglang","slug":"dflash-config-layer-types-must-be-a-sequence-of-at","errorCode":null,"errorMessage":"DFLASH config.layer_types must be a sequence of attention type strings.","messagePattern":"DFLASH config\\.layer_types must be a sequence of attention type strings\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/speculative/dflash_utils.py","lineNumber":401,"sourceCode":"        raise ValueError(\n            \"DFlash layer selection requires num_target_layers >= 4. \"\n            f\"Got num_target_layers={num_target_layers}.\"\n        )\n\n    span = end - start\n    return [\n        int(round(start + (i * span) / (num_draft_layers - 1)))\n        for i in range(num_draft_layers)\n    ]\n\n\ndef get_dflash_layer_types(config: Any) -> Optional[Sequence[str]]:\n    text_config = _get_text_config(config)\n    layer_types = _cfg_get(text_config, \"layer_types\", _cfg_get(config, \"layer_types\"))\n    if layer_types is None:\n        return None\n    if isinstance(layer_types, str) or not isinstance(layer_types, Sequence):\n        raise ValueError(\n            \"DFLASH config.layer_types must be a sequence of attention type strings.\"\n        )\n    return layer_types\n\n\ndef get_dflash_attention_sliding_window_size(config: Any) -> Optional[int]:\n    layer_types = get_dflash_layer_types(config)\n    if layer_types is None or \"sliding_attention\" not in layer_types:\n        return None\n\n    text_config = _get_text_config(config)\n    sliding_window = _cfg_get(\n        text_config, \"sliding_window\", _cfg_get(config, \"sliding_window\")\n    )\n    if sliding_window is None and is_nemotron_35_draft_config(config):\n        sliding_window = _get_dflash_config(config).get(\"swa_window_size\")\n    if sliding_window is None:\n        raise ValueError(","sourceCodeStart":383,"sourceCodeEnd":419,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/speculative/dflash_utils.py#L383-L419","documentation":"Raised by get_dflash_layer_types when config.layer_types exists but is not a non-string Sequence. The DFlash draft attention layout (full vs sliding attention layers) is derived from this list, so a plain string or a non-iterable/None-like value cannot be interpreted. This guards against malformed HF configs or wrong overrides.","triggerScenarios":"get_dflash_layer_types(config) where text_config.layer_types (or config.layer_types) is a str like \"full_attention\" or a dict/int instead of a list of strings such as [\"full_attention\", \"sliding_attention\"].","commonSituations":"A hand-edited HF config.json where layer_types was written as a single string; a config override passing layer_types=\"sliding_attention\"; a newer/older transformers version serializing the field differently.","solutions":["Set config.layer_types (or text_config.layer_types) to a list, e.g. [\"full_attention\"] * 30 + [\"sliding_attention\"] * 2.","If overriding via server args or a draft config, wrap the value in a list.","Reload the config from the upstream model repo to rule out local corruption."],"exampleFix":"# before\nconfig.layer_types = \"full_attention\"\n# after\nconfig.layer_types = [\"full_attention\", \"sliding_attention\"]","handlingStrategy":"type-guard","validationCode":"lt = getattr(getattr(config, 'text_config', config), 'layer_types', None)\nif lt is not None and (isinstance(lt, str) or not isinstance(lt, (list, tuple))):\n    raise TypeError('layer_types must be a list of strings')","typeGuard":"def is_valid_layer_types(v) -> bool:\n    return v is None or (not isinstance(v, str) and isinstance(v, (list, tuple)) and all(isinstance(x, str) for x in v))","tryCatchPattern":null,"preventionTips":["Normalize layer_types to a list when writing or overriding HF configs.","Add a config-lint step that checks container types of list-valued fields."],"tags":["speculative-decoding","dflash","hf-config","type-validation"],"backgroundTag":"invalid-config-type","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}