-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alex Chi <[email protected]>
- Loading branch information
Showing
14 changed files
with
176 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
export PYTORCH_ENABLE_MPS_FALLBACK=1 | ||
export VLLM_TARGET_DEVICE=cpu | ||
pip uninstall vllm | ||
python setup.py install | ||
vllm serve Qwen/Qwen2.5-0.5B-Instruct --dtype float16 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Common dependencies | ||
-r requirements-common.txt | ||
|
||
# Dependencies for CPUs | ||
torch==2.5.1; platform_machine == "ppc64le" or platform_machine == "aarch64" or platform_system == "Darwin" | ||
|
||
# required for the image processor of minicpm-o-2_6, this must be updated alongside torch | ||
torchaudio; platform_machine != "ppc64le" | ||
torchaudio==2.5.1; platform_machine == "ppc64le" | ||
|
||
# required for the image processor of phi3v, this must be updated alongside torch | ||
torchvision; platform_machine != "ppc64le" | ||
torchvision==0.20.1; platform_machine == "ppc64le" | ||
datasets # for benchmark scripts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ | |
"tpu", | ||
"xpu", | ||
"hpu", | ||
"metal", | ||
] | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import os | ||
from typing import TYPE_CHECKING, Optional | ||
|
||
import psutil | ||
import torch | ||
|
||
from vllm.logger import init_logger | ||
|
||
from .interface import Platform, PlatformEnum, _Backend | ||
|
||
logger = init_logger(__name__) | ||
|
||
if TYPE_CHECKING: | ||
from vllm.config import VllmConfig | ||
else: | ||
VllmConfig = None | ||
|
||
logger = init_logger(__name__) | ||
|
||
|
||
class MetalPlatform(Platform): | ||
_enum = PlatformEnum.METAL | ||
device_name: str = "metal" | ||
device_type: str = "metal" | ||
dispatch_key: str = "CPU" | ||
|
||
@classmethod | ||
def get_device_name(cls, device_id: int = 0) -> str: | ||
return "metal" | ||
|
||
@classmethod | ||
def get_attn_backend_cls(cls, selected_backend: _Backend, head_size: int, | ||
dtype: torch.dtype, kv_cache_dtype: Optional[str], | ||
block_size: int, use_v1: bool) -> str: | ||
if selected_backend != _Backend.TORCH_SDPA: | ||
logger.info("Cannot use %s backend on Metal.", selected_backend) | ||
logger.info("Using Torch SDPA backend.") | ||
return "vllm.attention.backends.torch_sdpa.TorchSDPABackend" | ||
|
||
@classmethod | ||
def get_device_total_memory(cls, device_id: int = 0) -> int: | ||
return psutil.virtual_memory().total | ||
|
||
@classmethod | ||
def is_async_output_supported(cls, enforce_eager: Optional[bool]) -> bool: | ||
return False | ||
|
||
@classmethod | ||
def inference_mode(cls): | ||
return torch.no_grad() | ||
|
||
@classmethod | ||
def check_and_update_config(cls, vllm_config: VllmConfig) -> None: | ||
import vllm.envs as envs | ||
from vllm.utils import GiB_bytes | ||
model_config = vllm_config.model_config | ||
cache_config = vllm_config.cache_config | ||
|
||
if cache_config and cache_config.block_size is None: | ||
cache_config.block_size = 16 | ||
|
||
kv_cache_space = envs.VLLM_CPU_KVCACHE_SPACE | ||
|
||
if kv_cache_space >= 0: | ||
if kv_cache_space == 0: | ||
cache_config.cpu_kvcache_space_bytes = 4 * GiB_bytes # type: ignore | ||
logger.warning( | ||
"Environment variable VLLM_CPU_KVCACHE_SPACE (GB) " | ||
"for CPU backend is not set, using 4 by default.") | ||
else: | ||
cache_config.cpu_kvcache_space_bytes = kv_cache_space * GiB_bytes # type: ignore # noqa | ||
else: | ||
raise RuntimeError( | ||
"Invalid environment variable VLLM_CPU_KVCACHE_SPACE" | ||
f" {kv_cache_space}, expect a positive integer value.") | ||
|
||
scheduler_config = vllm_config.scheduler_config | ||
if ((scheduler_config.chunked_prefill_enabled | ||
or cache_config.enable_prefix_caching) | ||
and model_config.dtype == torch.half): | ||
logger.warning("Chunked-prefill on the CPU backend only does not" | ||
" support fp16 for now, cast to bf16.") | ||
model_config.dtype = torch.bfloat16 # TODO supported? | ||
|
||
parallel_config = vllm_config.parallel_config | ||
if parallel_config.worker_cls == "auto": | ||
parallel_config.worker_cls = "vllm.worker.cpu_worker.CPUWorker" | ||
|
||
assert vllm_config.device_config.device_type == "metal" | ||
|
||
@classmethod | ||
def is_pin_memory_available(cls) -> bool: | ||
logger.warning("Pin memory is not supported on Metal.") | ||
return False | ||
|
||
@classmethod | ||
def get_punica_wrapper(cls) -> str: | ||
return "vllm.lora.punica_wrapper.punica_gpu.PunicaWrapperGPU" |
Oops, something went wrong.