[Bugfix] Add replacement of _compute_slot_mapping_kernel on CPU (#37987)
Signed-off-by: jiang1.li <jiang1.li@intel.com>
This commit is contained in:
@@ -309,7 +309,7 @@ class AWQMarlinConfig(QuantizationConfig):
|
||||
group_size = quant_config.get("group_size")
|
||||
zero_point = quant_config.get("zero_point")
|
||||
|
||||
if not (current_platform.is_cuda_alike() or current_platform.is_cpu()):
|
||||
if not current_platform.is_cuda_alike():
|
||||
return False
|
||||
|
||||
if quant_method != "awq":
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
"""
|
||||
Contains replacement functions to fallback Triton usages in CPU backend
|
||||
"""
|
||||
|
||||
from collections.abc import Callable
|
||||
|
||||
import torch
|
||||
|
||||
|
||||
class _FuncWrapper:
|
||||
def __init__(self, func: Callable) -> None:
|
||||
self.func = func
|
||||
|
||||
def __getitem__(self, *args, **kwargs) -> Callable:
|
||||
return self.func
|
||||
|
||||
|
||||
# For _compute_slot_mapping_kernel in vllm/v1/worker/block_table.py
|
||||
def _compute_slot_mapping_kernel_impl(
|
||||
num_tokens: int,
|
||||
max_num_tokens: int,
|
||||
query_start_loc: torch.Tensor, # [num_reqs + 1], int32
|
||||
positions: torch.Tensor, # [num_tokens], int64
|
||||
block_table: torch.Tensor, # [max_num_reqs, max_num_blocks_per_req], int32
|
||||
block_table_stride: int, # max_num_blocks_per_req
|
||||
block_size: int,
|
||||
slot_mapping: torch.Tensor, # [max_num_tokens], int64
|
||||
TOTAL_CP_WORLD_SIZE: int,
|
||||
TOTAL_CP_RANK: int,
|
||||
CP_KV_CACHE_INTERLEAVE_SIZE: int,
|
||||
PAD_ID: int,
|
||||
BLOCK_SIZE: int,
|
||||
) -> None:
|
||||
assert TOTAL_CP_WORLD_SIZE == 1, "Context Parallelism is not supported on CPU."
|
||||
torch.ops._C.compute_slot_mapping_kernel_impl(
|
||||
query_start_loc,
|
||||
positions,
|
||||
block_table,
|
||||
slot_mapping,
|
||||
block_size,
|
||||
)
|
||||
|
||||
|
||||
compute_slot_mapping_kernel = _FuncWrapper(_compute_slot_mapping_kernel_impl)
|
||||
@@ -6,6 +6,7 @@ from typing import Any
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
|
||||
import vllm.utils.cpu_triton_utils as cpu_tl
|
||||
from vllm.config import VllmConfig
|
||||
from vllm.logger import init_logger
|
||||
from vllm.model_executor.model_loader import get_model
|
||||
@@ -28,6 +29,7 @@ class CPUModelRunner(GPUModelRunner):
|
||||
self.cascade_attn_enabled = False
|
||||
|
||||
self._postprocess_tensors()
|
||||
self._postprocess_triton()
|
||||
|
||||
def _postprocess_tensors(self) -> None:
|
||||
# Note: replace device tensors with cpu tensors
|
||||
@@ -52,6 +54,13 @@ class CPUModelRunner(GPUModelRunner):
|
||||
if isinstance(v, CpuGpuBuffer):
|
||||
v.gpu = v.cpu
|
||||
|
||||
def _postprocess_triton(self) -> None:
|
||||
import vllm.v1.worker.block_table
|
||||
|
||||
vllm.v1.worker.block_table._compute_slot_mapping_kernel = (
|
||||
cpu_tl.compute_slot_mapping_kernel
|
||||
)
|
||||
|
||||
@instrument(span_name="Loading (CPU)")
|
||||
def load_model(self, load_dummy_weights: bool = False) -> None:
|
||||
if load_dummy_weights:
|
||||
|
||||
Reference in New Issue
Block a user