[Fix] Kimi K2.5 support pp (#18434)
Co-authored-by: Ilya Boytsov <ilya.boytsov@aleph-alpha.com> Co-authored-by: ybyang <10629930+whybeyoung@users.noreply.github.com> Co-authored-by: Shangming Cai <csmthu@gmail.com>
This commit is contained in:
co-authored by
Ilya Boytsov
ybyang
Shangming Cai
parent
8d9ee6669e
commit
4a3a787f1e
@@ -2656,7 +2656,17 @@ class DeepseekV2Model(nn.Module):
|
|||||||
pp_proxy_tensors: Optional[PPProxyTensors] = None,
|
pp_proxy_tensors: Optional[PPProxyTensors] = None,
|
||||||
) -> Union[torch.Tensor, PPProxyTensors]:
|
) -> Union[torch.Tensor, PPProxyTensors]:
|
||||||
total_num_layers = self.end_layer - self.start_layer
|
total_num_layers = self.end_layer - self.start_layer
|
||||||
device = input_embeds.device if input_embeds is not None else input_ids.device
|
if self.pp_group.is_first_rank:
|
||||||
|
if input_embeds is None:
|
||||||
|
hidden_states = self.embed_tokens(input_ids)
|
||||||
|
else:
|
||||||
|
hidden_states = input_embeds
|
||||||
|
residual = None
|
||||||
|
else:
|
||||||
|
assert pp_proxy_tensors is not None
|
||||||
|
hidden_states = pp_proxy_tensors["hidden_states"]
|
||||||
|
residual = pp_proxy_tensors["residual"]
|
||||||
|
device = hidden_states.device
|
||||||
zero_allocator = BumpAllocator(
|
zero_allocator = BumpAllocator(
|
||||||
buffer_size=total_num_layers * 2 * (2 if forward_batch.can_run_tbo else 1),
|
buffer_size=total_num_layers * 2 * (2 if forward_batch.can_run_tbo else 1),
|
||||||
dtype=torch.float32,
|
dtype=torch.float32,
|
||||||
@@ -2678,17 +2688,6 @@ class DeepseekV2Model(nn.Module):
|
|||||||
else None
|
else None
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.pp_group.is_first_rank:
|
|
||||||
if input_embeds is None:
|
|
||||||
hidden_states = self.embed_tokens(input_ids)
|
|
||||||
else:
|
|
||||||
hidden_states = input_embeds
|
|
||||||
residual = None
|
|
||||||
else:
|
|
||||||
assert pp_proxy_tensors is not None
|
|
||||||
hidden_states = pp_proxy_tensors["hidden_states"]
|
|
||||||
residual = pp_proxy_tensors["residual"]
|
|
||||||
|
|
||||||
if nsa_use_prefill_cp(forward_batch):
|
if nsa_use_prefill_cp(forward_batch):
|
||||||
if self.pp_group.is_first_rank:
|
if self.pp_group.is_first_rank:
|
||||||
hidden_states = cp_split_and_rebuild_data(forward_batch, hidden_states)
|
hidden_states = cp_split_and_rebuild_data(forward_batch, hidden_states)
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ from sglang.srt.managers.schedule_batch import (
|
|||||||
MultimodalDataItem,
|
MultimodalDataItem,
|
||||||
MultimodalInputs,
|
MultimodalInputs,
|
||||||
)
|
)
|
||||||
from sglang.srt.model_executor.forward_batch_info import ForwardBatch
|
from sglang.srt.model_executor.forward_batch_info import ForwardBatch, PPProxyTensors
|
||||||
from sglang.srt.model_loader.weight_utils import default_weight_loader
|
from sglang.srt.model_loader.weight_utils import default_weight_loader
|
||||||
from sglang.srt.models.deepseek_v2 import DeepseekV3ForCausalLM
|
from sglang.srt.models.deepseek_v2 import DeepseekV3ForCausalLM
|
||||||
from sglang.srt.models.kimi_vl_moonvit import MLP2
|
from sglang.srt.models.kimi_vl_moonvit import MLP2
|
||||||
@@ -722,6 +722,7 @@ class KimiK25ForConditionalGeneration(nn.Module):
|
|||||||
positions: torch.Tensor,
|
positions: torch.Tensor,
|
||||||
forward_batch: ForwardBatch,
|
forward_batch: ForwardBatch,
|
||||||
get_embedding: bool = False,
|
get_embedding: bool = False,
|
||||||
|
pp_proxy_tensors: Optional[PPProxyTensors] = None,
|
||||||
):
|
):
|
||||||
hidden_states = general_mm_embed_routine(
|
hidden_states = general_mm_embed_routine(
|
||||||
input_ids=input_ids,
|
input_ids=input_ids,
|
||||||
@@ -731,6 +732,7 @@ class KimiK25ForConditionalGeneration(nn.Module):
|
|||||||
Modality.IMAGE: self.get_image_feature,
|
Modality.IMAGE: self.get_image_feature,
|
||||||
},
|
},
|
||||||
positions=positions,
|
positions=positions,
|
||||||
|
pp_proxy_tensors=pp_proxy_tensors,
|
||||||
)
|
)
|
||||||
|
|
||||||
return hidden_states
|
return hidden_states
|
||||||
|
|||||||
Reference in New Issue
Block a user