Base class containing common engine functionality
| 84 | |
| 85 | |
| 86 | class EngineService: |
| 87 | """ |
| 88 | Base class containing common engine functionality |
| 89 | """ |
| 90 | |
| 91 | def __init__(self, cfg: FDConfig, start_queue=True, use_async_llm=False): |
| 92 | """ |
| 93 | Initializes the LLMEngine with the provided configuration. |
| 94 | |
| 95 | Args: |
| 96 | cfg (Config): Config object containing all the configuration parameters. |
| 97 | """ |
| 98 | self.cfg = cfg |
| 99 | self.use_async_llm = use_async_llm |
| 100 | |
| 101 | if self.cfg.parallel_config.data_parallel_size > 1: |
| 102 | self.llm_logger = get_logger( |
| 103 | "fastdeploy", f"fastdeploy_dprank{self.cfg.parallel_config.local_data_parallel_id}.log" |
| 104 | ) |
| 105 | else: |
| 106 | self.llm_logger = llm_logger |
| 107 | |
| 108 | self.is_paused = False # pause request generation |
| 109 | self._pause_cond = threading.Condition() |
| 110 | |
| 111 | self._ctrl_output_queues = {} |
| 112 | self._ctrl_response_mailboxes = collections.defaultdict(collections.OrderedDict) |
| 113 | tp_size = cfg.parallel_config.tensor_parallel_size |
| 114 | dp_index = cfg.parallel_config.local_data_parallel_id |
| 115 | for tp_rank in range(tp_size): |
| 116 | # create worker control response queue |
| 117 | engine_worker_queue_port = self.cfg.parallel_config.local_engine_worker_queue_port |
| 118 | name = f"ctrl_w2e_rank{tp_rank+tp_size*dp_index}_{engine_worker_queue_port}" |
| 119 | self.llm_logger.info(f"Init Worker Control Output Queue: {name} (consumer)") |
| 120 | self._ctrl_output_queues[name] = FMQ().queue(name, "consumer") |
| 121 | |
| 122 | # create cache control response queue |
| 123 | if self.cfg.cache_config.num_cpu_blocks > 0 or self.cfg.cache_config.kvcache_storage_backend: |
| 124 | engine_cache_queue_port = self.cfg.cache_config.local_cache_queue_port |
| 125 | name = f"ctrl_c2e_rank{tp_rank+tp_size*dp_index}_{engine_cache_queue_port}" |
| 126 | self.llm_logger.info(f"Init Cache Control Output Queue: {name} (consumer)") |
| 127 | self._ctrl_output_queues[name] = FMQ().queue(name, "consumer") |
| 128 | |
| 129 | self.scheduler = cfg.scheduler_config.scheduler() |
| 130 | self.enable_decode_cache_task = envs.FD_ENABLE_CACHE_TASK == "1" |
| 131 | |
| 132 | if envs.ENABLE_V1_KVCACHE_SCHEDULER: |
| 133 | self.llm_logger.info("Use V1 KVCache Scheduler") |
| 134 | self.resource_manager = ResourceManagerV1( |
| 135 | cfg.scheduler_config.max_num_seqs, |
| 136 | cfg, |
| 137 | cfg.parallel_config.tensor_parallel_size, |
| 138 | cfg.scheduler_config.splitwise_role, |
| 139 | cfg.parallel_config.local_data_parallel_id, |
| 140 | ) |
| 141 | else: |
| 142 | self.llm_logger.info("Use V0 KVCache Scheduler") |
| 143 | self.resource_manager = ResourceManager( |
no outgoing calls