{"record":{"id":"0836cd0e3fae14a7","repo":"sgl-project/sglang","slug":"unsupported-encoder-folding-mode-mode-r","errorCode":null,"errorMessage":"Unsupported encoder folding mode: {mode!r}","messagePattern":"Unsupported encoder folding mode: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/encoders/base.py","lineNumber":46,"sourceCode":")\nfrom sglang.multimodal_gen.runtime.platforms import AttentionBackendEnum\n\n\ndef get_folding_tp_group(config: EncoderConfig):\n    \"\"\"Return the TP group selected for an encoder.\"\"\"\n    mode = config.parallel_folding_mode\n    if mode == \"sp\":\n        return get_sp_group()\n    if mode == \"world\":\n        # the whole single-replica DiT (all GPUs), regardless of tp/sp/cfg.\n        return get_world_group()\n    if mode == \"replica\":\n        # the ranks serving this rank's pipeline replica (== world when\n        # dp_size is 1); the shape-independent choice for explicit folding\n        return get_replica_group()\n    if mode is None:\n        return get_tp_group()\n    raise ValueError(f\"Unsupported encoder folding mode: {mode!r}\")\n\n\n# measured on 2/4xH100: folding wins only for wide encoders (T5-XXL 4096: -20%\n# at batch 1, R-insensitive); narrower ones lose to the per-layer all_reduce\n# (Qwen3 2560: +35%, CLIP 768: +50%)\nFOLD_MIN_HIDDEN_SIZE = 4096\n# below this width the encoder stays latency-bound across batch sizes, so\n# data-parallel encoding saves no compute and the all_gather is a pure loss\n# (CLIP 768: dp slower at every batch/R measured)\nDP_MIN_HIDDEN_SIZE = 1024\n\n\ndef _encoder_dims(config: EncoderConfig):\n    \"\"\"Best-effort (hidden, attention_heads, mlp_intermediate) from a config,\n    spelled differently across families (hidden_size/d_model, num_heads, d_ff).\"\"\"\n\n    def first(names):\n        for name in names:","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/encoders/base.py#L28-L64","documentation":"Raised by get_folding_tp_group when the encoder folding mode string is neither 'replica' nor None. Only two modes exist: replica folding (replica TP group) and default TP (None → get_tp_group()).","triggerScenarios":"Passing an unknown mode such as 'fold', 'dp', or a typo to get_folding_tp_group from load_model, finalize_encoder_folding, or encoder __init__.","commonSituations":"Custom folding configuration strings from server args or a config file that do not match the two accepted values.","solutions":["Use mode='replica' for replica-based folding","Use mode=None for the default TP group","Check the spelling of the folding mode in your server args / config"],"exampleFix":"# before\ngroup = get_folding_tp_group(mode=\"fold\")\n# after\ngroup = get_folding_tp_group(mode=\"replica\")  # or None","handlingStrategy":"validation","validationCode":"assert mode in (None, \"replica\"), f\"bad folding mode {mode!r}\"","typeGuard":"def is_supported_folding_mode(mode) -> bool:\n    return mode is None or mode == \"replica\"","tryCatchPattern":null,"preventionTips":["Restrict folding-mode config values at server-args parsing time"],"tags":["encoder-folding","config-validation","tp-group"],"backgroundTag":"unsupported-config-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}