[Perf][GLM-5.2] Blackwell decode optimizations (#48597)
Signed-off-by: Peiyuan Zhou <peiyuanzhou1994@gmail.com> Signed-off-by: zhou <zhou@zhoudeMacBook-Pro.local> Signed-off-by: Stefan Koncarevic <stefan.koncarevic@amd.com> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Giancarlo Delfin <32987265+TheEpicDolphin@users.noreply.github.com> Co-authored-by: Thien Tran <gau.nernst@yahoo.com.sg> Co-authored-by: OpenAI Codex <codex@openai.com> Co-authored-by: zhou <zhou@zhoudeMacBook-Pro.local> Co-authored-by: stefankoncarevic <Stefan.Koncarevic@amd.com>
This commit is contained in:
co-authored by
Claude
Giancarlo Delfin
Thien Tran
OpenAI Codex
zhou
stefankoncarevic
parent
0d77325b10
commit
dd72658e7d
@@ -1,8 +1,10 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
|
||||
from vllm.config import VllmConfig
|
||||
from vllm.v1.worker.gpu.spec_decode.autoregressive.speculator import (
|
||||
AutoRegressiveSpeculator,
|
||||
)
|
||||
@@ -10,9 +12,46 @@ from vllm.v1.worker.gpu.spec_decode.eagle.utils import load_eagle_model
|
||||
|
||||
|
||||
class MTPSpeculator(AutoRegressiveSpeculator):
|
||||
def __init__(self, vllm_config: VllmConfig, device: torch.device):
|
||||
super().__init__(vllm_config, device)
|
||||
|
||||
spec_config = vllm_config.speculative_config
|
||||
draft_hf_config = (
|
||||
spec_config.draft_model_config.hf_config
|
||||
if spec_config is not None
|
||||
else None
|
||||
)
|
||||
# Detect index_share_for_mtp_iteration. When True, the proposer
|
||||
# toggles skip_topk so step 0 computes MTP's own indices and
|
||||
# steps 1+ reuse them.
|
||||
self.share_mtp_topk_indices = getattr(
|
||||
draft_hf_config, "index_share_for_mtp_iteration", False
|
||||
)
|
||||
|
||||
def load_draft_model(
|
||||
self,
|
||||
target_model: nn.Module,
|
||||
target_attn_layer_names: set[str],
|
||||
) -> nn.Module:
|
||||
return load_eagle_model(target_model, self.vllm_config)
|
||||
draft_model = load_eagle_model(target_model, self.vllm_config)
|
||||
self.share_mtp_topk_indices = self.share_mtp_topk_indices and hasattr(
|
||||
draft_model.model, "set_skip_topk"
|
||||
)
|
||||
return draft_model
|
||||
|
||||
def on_prefill_end(self, num_reqs: int, num_tokens: int) -> None:
|
||||
# Step 0 (prefill) wrote topk indices for every query token in the
|
||||
# multi-token batch. Compact them down to each request's last token so
|
||||
# steps 1+ can reuse them from the shared buffer.
|
||||
if self.share_mtp_topk_indices and self.num_speculative_steps > 1:
|
||||
self.model.model.compact_topk_indices(self.last_token_indices[:num_reqs])
|
||||
|
||||
def on_multi_step_decode_begin(self, num_reqs: int) -> None:
|
||||
# Switch to reuse mode so draft steps 1+ skip the indexer op and read
|
||||
# the indices that step 0 wrote into the shared buffer.
|
||||
if self.share_mtp_topk_indices:
|
||||
self.model.model.set_skip_topk(True)
|
||||
|
||||
def on_multi_step_decode_end(self, num_reqs: int) -> None:
|
||||
if self.share_mtp_topk_indices:
|
||||
self.model.model.set_skip_topk(False)
|
||||
|
||||
Reference in New Issue
Block a user