[Model] Use standard ModelOpt config for Inkling NVFP4 (#48990)
Signed-off-by: mgoin <mgoin64@gmail.com>
This commit is contained in:
@@ -43,20 +43,19 @@ from vllm.utils.multi_stream_utils import maybe_execute_in_parallel
|
||||
from vllm.utils.torch_utils import aux_stream
|
||||
|
||||
from ..configs import InklingModelConfig
|
||||
from ..nvfp4 import FLOAT4_E2M1_MAX, FLOAT8_E4M3_MAX
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from vllm.model_executor.layers.fused_moe.routed_experts import (
|
||||
RoutedExperts,
|
||||
)
|
||||
|
||||
from ..nvfp4 import InklingNvfp4Config
|
||||
from vllm.model_executor.layers.quantization import QuantizationConfig
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Gate / expert selection
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
_INKLING_LL_BF16_MAX_TOKENS = 64
|
||||
_NVFP4_INPUT_SCALE_DENOMINATOR = torch.finfo(torch.float8_e4m3fn).max * 6.0
|
||||
|
||||
|
||||
def _linear_with_fp32_out(x: torch.Tensor, weight: torch.Tensor) -> torch.Tensor:
|
||||
@@ -412,10 +411,9 @@ class InklingMoE(nn.Module):
|
||||
def __init__(
|
||||
self,
|
||||
config: InklingModelConfig,
|
||||
layer_id: int,
|
||||
*,
|
||||
prefix: str = "",
|
||||
nvfp4_config: InklingNvfp4Config | None = None,
|
||||
quant_config: QuantizationConfig | None = None,
|
||||
) -> None:
|
||||
super().__init__()
|
||||
# Overfit to the served checkpoint: sigmoid gate renormalized after
|
||||
@@ -436,22 +434,6 @@ class InklingMoE(nn.Module):
|
||||
use_gate_bias=config.use_gate_bias,
|
||||
)
|
||||
|
||||
moe_quant_config = None
|
||||
if nvfp4_config is not None and nvfp4_config.experts_quantized(layer_id):
|
||||
from vllm.model_executor.layers.quantization.modelopt import (
|
||||
ModelOptNvFp4Config,
|
||||
)
|
||||
|
||||
# The Inkling checkpoint is ModelOpt NVFP4; exclusion is decided per
|
||||
# layer right here, so no exclude list is needed.
|
||||
moe_quant_config = ModelOptNvFp4Config(
|
||||
quant_method="NVFP4",
|
||||
is_checkpoint_nvfp4_serialized=True,
|
||||
kv_cache_quant_algo=None,
|
||||
exclude_modules=[],
|
||||
group_size=nvfp4_config.group_size,
|
||||
)
|
||||
|
||||
# TRTLLM MoE kernels assume equal, contiguous per-rank expert slabs
|
||||
# (local_expert_offset = ep_rank * local_num_experts), so pad the
|
||||
# expert count to a multiple of the EP size. A no-op for the usual
|
||||
@@ -464,7 +446,7 @@ class InklingMoE(nn.Module):
|
||||
hidden_size=config.hidden_size,
|
||||
intermediate_size=config.intermediate_size,
|
||||
renormalize=False,
|
||||
quant_config=moe_quant_config,
|
||||
quant_config=quant_config,
|
||||
prefix=f"{prefix}.experts",
|
||||
custom_routing_function=self._select_routed,
|
||||
router_logits_dtype=torch.float32,
|
||||
@@ -476,11 +458,6 @@ class InklingMoE(nn.Module):
|
||||
self.experts.moe_config.skip_final_all_reduce = True
|
||||
|
||||
self._routed_sel: tuple[torch.Tensor, torch.Tensor, torch.Tensor] | None = None
|
||||
# The sinks are always bf16; fail loudly on a checkpoint that
|
||||
# quantizes them instead of silently misloading.
|
||||
assert nvfp4_config is None or not nvfp4_config.shared_experts_quantized(
|
||||
layer_id
|
||||
), f"layer {layer_id}: NVFP4 shared experts are not supported"
|
||||
|
||||
sink_experts_cls = (
|
||||
InklingSinkExpertsLinear
|
||||
@@ -589,7 +566,7 @@ class InklingMoE(nn.Module):
|
||||
f"bad {projection} input_amax: {amax}"
|
||||
)
|
||||
input_scale = getattr(experts, f"{projection}_input_scale")
|
||||
input_scale.data.fill_(amax / (FLOAT8_E4M3_MAX * FLOAT4_E2M1_MAX))
|
||||
input_scale.data.fill_(amax / _NVFP4_INPUT_SCALE_DENOMINATOR)
|
||||
return [f"experts.routed_experts.{projection}_input_scale"]
|
||||
|
||||
param = getattr(experts, key)
|
||||
|
||||
Reference in New Issue
Block a user