[refactor] Migrate the first override families: Mistral/Pixtral dtype, MiniMaxM2, MiMoV2 (stack 7/15) (#30069)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
df6491d80c
commit
8d8f17e28c
@@ -29,13 +29,21 @@ Two declaration forms, keyed on ``hf_config.architectures[0]``:
|
||||
from __future__ import annotations
|
||||
|
||||
import dataclasses
|
||||
import logging
|
||||
from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, Tuple
|
||||
|
||||
from sglang.srt.arg_groups.arg_utils import model_overridable_fields
|
||||
from sglang.srt.runtime_context import resolve_flag_leaf
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Constant per-architecture overrides (populated by the migration sweeps).
|
||||
MODEL_OVERRIDES: Dict[str, Dict[str, Any]] = {}
|
||||
MODEL_OVERRIDES: Dict[str, Dict[str, Any]] = {
|
||||
# These models run in bfloat16 regardless of the requested dtype
|
||||
# (faithful port of the legacy unconditional arch branch).
|
||||
"MistralLarge3ForCausalLM": {"dtype": "bfloat16"},
|
||||
"PixtralForConditionalGeneration": {"dtype": "bfloat16"},
|
||||
}
|
||||
|
||||
# Derived per-architecture override providers, in registration order.
|
||||
_MODEL_OVERRIDE_FNS: Dict[str, List[Callable[..., dict]]] = {}
|
||||
@@ -83,6 +91,41 @@ def collect_model_override_declarations(
|
||||
return declarations
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Derived per-family declarations (faithful ports of legacy arch branches).
|
||||
# Callables read the PRISTINE server_args, never write; logging is kept
|
||||
# verbatim from the legacy branch for operator-visible fidelity.
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def _register_for(*architectures: str):
|
||||
"""Register one provider for several architectures (family lists)."""
|
||||
|
||||
def decorator(fn: Callable[..., dict]) -> Callable[..., dict]:
|
||||
for architecture in architectures:
|
||||
register_model_override(architecture)(fn)
|
||||
return fn
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
# Keep in sync with MIMO_V2_MODEL_ARCHS (server_args.py / configs/hf_config.py).
|
||||
@_register_for("MiMoV2ForCausalLM", "MiMoV2FlashForCausalLM")
|
||||
def _mimo_v2_overrides(server_args: Any, hf_config: Any) -> dict:
|
||||
if server_args.speculative_algorithm == "EAGLE":
|
||||
logger.info("Enable multi-layer EAGLE speculative decoding for MiMoV2 model.")
|
||||
return {"enable_multi_layer_eagle": True}
|
||||
return {}
|
||||
|
||||
|
||||
@_register_for("MiniMaxM2ForCausalLM")
|
||||
def _minimax_m2_overrides(server_args: Any, hf_config: Any) -> dict:
|
||||
logger.info(
|
||||
"Enable TF32 matmul for MiniMaxM2ForCausalLM model to improve gate gemm performance."
|
||||
)
|
||||
return {"enable_tf32_matmul": True}
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class OverrideRecord:
|
||||
"""Provenance of one resolved write: ``base`` is the value before this
|
||||
|
||||
@@ -306,6 +306,13 @@ class Flags(_StaticFlags):
|
||||
moe: MoeFlags = dataclasses.field(default_factory=MoeFlags)
|
||||
capture: CaptureFlags = dataclasses.field(default_factory=CaptureFlags)
|
||||
|
||||
# -- resolved config leaves (flat; materialized at publish) --------------
|
||||
# Pristine user requests stay on the matching server_args fields; these
|
||||
# leaves carry the model-resolved values.
|
||||
dtype: str = "auto"
|
||||
enable_tf32_matmul: bool = False
|
||||
enable_multi_layer_eagle: bool = False
|
||||
|
||||
def freeze(self) -> None:
|
||||
for field in dataclasses.fields(self):
|
||||
value = getattr(self, field.name)
|
||||
|
||||
@@ -572,6 +572,7 @@ class ServerArgs:
|
||||
'* "float32" for FP32 precision.'
|
||||
),
|
||||
choices=["auto", "half", "float16", "bfloat16", "float", "float32"],
|
||||
model_overridable=True,
|
||||
),
|
||||
] = "auto"
|
||||
quantization: A[
|
||||
@@ -653,7 +654,10 @@ class ServerArgs:
|
||||
] = None # For flash_rl load format
|
||||
enable_tf32_matmul: A[
|
||||
bool,
|
||||
"Enable float32 matmuls to use TensorFloat32 precision for better performance (via torch.set_float32_matmul_precision). CUDA only.",
|
||||
Arg(
|
||||
help="Enable float32 matmuls to use TensorFloat32 precision for better performance (via torch.set_float32_matmul_precision). CUDA only.",
|
||||
model_overridable=True,
|
||||
),
|
||||
] = False
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
@@ -1595,7 +1599,10 @@ class ServerArgs:
|
||||
] = False
|
||||
enable_multi_layer_eagle: A[
|
||||
bool,
|
||||
"Enable multi-layer Eagle speculative decoding.",
|
||||
Arg(
|
||||
help="Enable multi-layer Eagle speculative decoding.",
|
||||
model_overridable=True,
|
||||
),
|
||||
] = False
|
||||
speculative_adaptive: A[
|
||||
bool,
|
||||
@@ -3741,12 +3748,6 @@ class ServerArgs:
|
||||
)
|
||||
apply_declarations_to_server_args(self, self._resolved_overrides)
|
||||
|
||||
if model_arch in [
|
||||
"MistralLarge3ForCausalLM",
|
||||
"PixtralForConditionalGeneration",
|
||||
]:
|
||||
self.dtype = "bfloat16"
|
||||
|
||||
if model_arch in [
|
||||
"DeepseekV4ForCausalLM",
|
||||
]:
|
||||
@@ -4205,11 +4206,8 @@ class ServerArgs:
|
||||
f"attention TP size is {expected_attn_tp_size}."
|
||||
)
|
||||
|
||||
if self.speculative_algorithm == "EAGLE":
|
||||
self.enable_multi_layer_eagle = True
|
||||
logger.info(
|
||||
"Enable multi-layer EAGLE speculative decoding for MiMoV2 model."
|
||||
)
|
||||
# enable_multi_layer_eagle for EAGLE moved to the override registry
|
||||
# (arg_groups/overrides.py: _mimo_v2_overrides).
|
||||
|
||||
if self.enable_hierarchical_cache:
|
||||
if not envs.SGLANG_ENABLE_UNIFIED_RADIX_TREE.get():
|
||||
@@ -4518,11 +4516,8 @@ class ServerArgs:
|
||||
elif model_arch in ["ZayaForCausalLM"]:
|
||||
self._handle_mamba_radix_cache(model_arch=model_arch)
|
||||
|
||||
elif model_arch in ["MiniMaxM2ForCausalLM"]:
|
||||
self.enable_tf32_matmul = True
|
||||
logger.info(
|
||||
"Enable TF32 matmul for MiniMaxM2ForCausalLM model to improve gate gemm performance."
|
||||
)
|
||||
# MiniMaxM2ForCausalLM (enable_tf32_matmul) moved to the override registry
|
||||
# (arg_groups/overrides.py: _minimax_m2_overrides).
|
||||
|
||||
if (
|
||||
model_arch in ["Qwen3VLForConditionalGeneration"]
|
||||
|
||||
Reference in New Issue
Block a user