Skip to content

Commit

Permalink
[Bugfix][Hardware][CPU] Fix CPU input_positions creation for text-o…
Browse files Browse the repository at this point in the history
…nly inputs with mrope (#11434)

Signed-off-by: Isotr0py <[email protected]>
  • Loading branch information
Isotr0py authored Dec 24, 2024
1 parent b1b1038 commit 7a5286c
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions vllm/worker/cpu_model_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ class ModelInputData:
def __init__(self, use_mrope: bool):
self.use_mrope = use_mrope
self.input_tokens: List[int] = []
self.input_positions: Optional[
List[int]] = [] if not self.use_mrope else None
self.input_positions: List[int] = []
self.token_type_ids: Optional[List[int]] = []
self.seq_lens: List[int] = []
self.query_lens: List[int] = []
Expand All @@ -130,9 +129,8 @@ def __init__(self, use_mrope: bool):
self.multi_modal_placeholder_maps: Dict[
str, MultiModalPlaceholderMap] = defaultdict(
MultiModalPlaceholderMap)
self.input_mrope_positions: Optional[List[List[int]]] = [
[] for _ in range(3)
] if self.use_mrope else None
self.input_mrope_positions: List[List[int]] = [[]
for _ in range(3)]

def __init__(self,
runner: "CPUModelRunner",
Expand Down Expand Up @@ -167,7 +165,8 @@ def build(self) -> ModelInputForCPU:
device="cpu")
input_positions = torch.tensor(
input_data.input_positions
if not input_data.use_mrope else input_data.input_mrope_positions,
if not any(input_data.input_mrope_positions) else
input_data.input_mrope_positions,
dtype=torch.long,
device="cpu")
token_type_ids = torch.tensor(input_data.token_type_ids,
Expand Down Expand Up @@ -236,7 +235,7 @@ def _compute_decode_input_tokens(self, data: ModelInputData,
block_table = block_table[start_block:]

# For MRotaryEmbedding
if data.input_positions is None:
if seq_data.mrope_position_delta is not None:
next_pos = MRotaryEmbedding.get_next_input_positions(
seq_data.mrope_position_delta,
context_len,
Expand Down Expand Up @@ -309,8 +308,7 @@ def _compute_prompt_input_tokens(self, data: ModelInputData,
data.slot_mapping.extend(slot_mapping)

# The MROPE positions are prepared in _compute_multi_modal_input
if data.input_positions is not None:
data.input_positions.extend(token_positions)
data.input_positions.extend(token_positions)

if data.token_type_ids is not None:
data.token_type_ids.extend(token_types if token_types else [])
Expand Down

0 comments on commit 7a5286c

Please sign in to comment.