neuron_executor.py 3.39 KB
Newer Older
1
from typing import Dict, List, Set, Tuple
2

3
from vllm.executor.executor_base import ExecutorAsyncBase, ExecutorBase
4
from vllm.logger import init_logger
5
from vllm.lora.request import LoRARequest
6
from vllm.sequence import SamplerOutput, SequenceGroupMetadata
7
from vllm.utils import make_async
8
9
10
11
12
13

logger = init_logger(__name__)


class NeuronExecutor(ExecutorBase):

14
15
16
17
    def _init_executor(self) -> None:
        assert (self.lora_config is
                None), "LoRA is not supported for Neuron backend."
        assert (not self.speculative_config
18
                ), "Speculative decoding not yet supported for Neuron backend."
19
20
21
22
23
24
25
26
27
28
29
30

        # Instantiate the worker and load the model to the device.
        self._init_worker()

    def _init_worker(self):
        from vllm.worker.neuron_worker import NeuronWorker

        self.driver_worker = NeuronWorker(
            self.model_config,
            self.parallel_config,
            self.scheduler_config,
            self.device_config,
31
            self.cache_config,
32
33
34
35
        )
        self.driver_worker.init_device()
        self.driver_worker.load_model()

36
    def determine_num_available_blocks(self) -> Tuple[int, int]:
37
38
39
40
41
42
43
44
45
46
47
        """Determine the number of available KV blocks by invoking the
        underlying worker.
        """
        return self.driver_worker.determine_num_available_blocks()

    def initialize_cache(self, num_gpu_blocks: int,
                         num_cpu_blocks: int) -> None:
        """Initialize the KV cache by invoking the underlying worker.
        """
        self.driver_worker.initialize_cache(num_gpu_blocks, num_cpu_blocks)

48
49
50
51
    def execute_model(self,
                      seq_group_metadata_list: List[SequenceGroupMetadata],
                      blocks_to_swap_in: Dict[int, int],
                      blocks_to_swap_out: Dict[int, int],
52
53
                      blocks_to_copy: Dict[int, List[int]],
                      num_lookahead_slots: int) -> List[SamplerOutput]:
54
55
56
        assert (blocks_to_swap_in == {} and blocks_to_swap_out == {}
                and blocks_to_copy == {}), (
                    "Cache operations are not supported for Neuron backend.")
57
58
        assert num_lookahead_slots == 0, (
            "lookahead not supported for Neuron backend.")
59
60
61
62
63
64

        output = self.driver_worker.execute_model(
            seq_group_metadata_list=seq_group_metadata_list)
        return output

    def add_lora(self, lora_request: LoRARequest) -> bool:
65
        return self.driver_worker.add_lora(lora_request)
66
67

    def remove_lora(self, lora_id: int) -> bool:
68
        return self.driver_worker.remove_lora(lora_id)
69

70
    def list_loras(self) -> Set[int]:
71
        return self.driver_worker.list_loras()
72
73
74
75
76

    def check_health(self) -> None:
        # NeuronExecutor will always be healthy as long as
        # it's running.
        return
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95


class NeuronExecutorAsync(NeuronExecutor, ExecutorAsyncBase):

    async def execute_model_async(
        self,
        seq_group_metadata_list: List[SequenceGroupMetadata],
        blocks_to_swap_in: Dict[int, int],
        blocks_to_swap_out: Dict[int, int],
        blocks_to_copy: Dict[int, List[int]],
    ) -> SamplerOutput:
        output = await make_async(self.driver_worker.execute_model)(
            seq_group_metadata_list=seq_group_metadata_list, )
        return output

    async def check_health_async(self) -> None:
        # NeuronExecutor will always be healthy as long as
        # it's running.
        return