neuron.py 1.74 KB
Newer Older
1
from typing import TYPE_CHECKING, Optional
2

3
4
from vllm.logger import init_logger

5
6
from .interface import Platform, PlatformEnum

7
8
9
10
11
if TYPE_CHECKING:
    from vllm.config import VllmConfig
else:
    VllmConfig = None

12
13
logger = init_logger(__name__)

14
15
16

class NeuronPlatform(Platform):
    _enum = PlatformEnum.NEURON
17
    device_name: str = "neuron"
18
    device_type: str = "neuron"
19
    ray_device_key: str = "neuron_cores"
20
    supported_quantization: list[str] = ["neuron_quant"]
21
    device_control_env_var: str = "NEURON_RT_VISIBLE_CORES"
22
23
24
25

    @classmethod
    def get_device_name(cls, device_id: int = 0) -> str:
        return "neuron"
26

27
28
29
30
    @classmethod
    def is_async_output_supported(cls, enforce_eager: Optional[bool]) -> bool:
        return False

31
32
33
34
35
36
    @classmethod
    def check_and_update_config(cls, vllm_config: VllmConfig) -> None:
        parallel_config = vllm_config.parallel_config
        if parallel_config.worker_cls == "auto":
            parallel_config.worker_cls = \
                "vllm.worker.neuron_worker.NeuronWorker"
37

38
39
40
        if parallel_config.world_size > 1:
            parallel_config.distributed_executor_backend = "uni"

41
42
        assert (vllm_config.lora_config
                is None), "LoRA is not supported for Neuron backend."
43
44
45
        assert (not vllm_config.speculative_config
                ), "Speculative decoding not yet supported for Neuron backend."

46
47
48
49
50
51
        cache_config = vllm_config.cache_config
        if cache_config:
            # neuron needs block_size = max_model_len
            vllm_config.cache_config.block_size = \
                vllm_config.model_config.max_model_len

52
53
54
55
    @classmethod
    def is_pin_memory_available(cls) -> bool:
        logger.warning("Pin memory is not supported on Neuron.")
        return False