neuron.py 2.15 KB
Newer Older
1
2
# SPDX-License-Identifier: Apache-2.0

3
from typing import TYPE_CHECKING, Optional
4

5
from vllm import envs
6
7
from vllm.logger import init_logger

8
9
from .interface import Platform, PlatformEnum

10
11
12
13
14
if TYPE_CHECKING:
    from vllm.config import VllmConfig
else:
    VllmConfig = None

15
16
logger = init_logger(__name__)

17
18
19

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

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

30
31
32
33
    @classmethod
    def is_async_output_supported(cls, enforce_eager: Optional[bool]) -> bool:
        return False

34
35
36
37
38
39
    @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"
40

41
42
43
        if parallel_config.world_size > 1:
            parallel_config.distributed_executor_backend = "uni"

44
45
        assert (vllm_config.lora_config
                is None), "LoRA is not supported for Neuron backend."
46
47
48
        assert (not vllm_config.speculative_config
                ), "Speculative decoding not yet supported for Neuron backend."

49
50
51
52
        cache_config = vllm_config.cache_config
        if cache_config:
            # neuron needs block_size = max_model_len
            vllm_config.cache_config.block_size = \
53
                vllm_config.model_config.max_model_len  # type: ignore
54

55
56
57
58
    @classmethod
    def is_pin_memory_available(cls) -> bool:
        logger.warning("Pin memory is not supported on Neuron.")
        return False
59

60
61
62
63
64
65
66
    @classmethod
    def get_device_communicator_cls(cls) -> str:
        if envs.VLLM_USE_V1:
            return "vllm.distributed.device_communicators.neuron_communicator.NeuronCommunicator"  # noqa
        else:
            return Platform.get_device_communicator_cls()

67
68
69
    @classmethod
    def use_all_gather(cls) -> bool:
        return True