Get the Ray actor wrapper for the inference model. Creates Ray actors with appropriate GPU allocation and distributed communication setup based on the inferred launch mode. Args: actor_cls: The actor class to instantiate (e.g., vLLMRolloutModel, SGLangRolloutModel). con
(
actor_cls,
config: "InferenceModelConfig",
pg: PlacementGroup,
actor_bundle_list: List[Tuple[str, int]],
)
| 163 | |
| 164 | |
| 165 | async def get_model_wrapper( |
| 166 | actor_cls, |
| 167 | config: "InferenceModelConfig", |
| 168 | pg: PlacementGroup, |
| 169 | actor_bundle_list: List[Tuple[str, int]], |
| 170 | ) -> ModelWrapper: |
| 171 | """Get the Ray actor wrapper for the inference model. |
| 172 | |
| 173 | Creates Ray actors with appropriate GPU allocation and distributed communication |
| 174 | setup based on the inferred launch mode. |
| 175 | |
| 176 | Args: |
| 177 | actor_cls: The actor class to instantiate (e.g., vLLMRolloutModel, SGLangRolloutModel). |
| 178 | config (InferenceModelConfig): The model config. |
| 179 | pg (PlacementGroup): The placement group for the actors. |
| 180 | actor_bundle_list (List[Tuple[str, int]]): The list of (actor_name, bundle_id) tuples |
| 181 | for distributed setup. |
| 182 | Returns: |
| 183 | ModelWrapper: A wrapper for the model actors with distributed communication setup. |
| 184 | """ |
| 185 | handlers = [] |
| 186 | for i, (actor_name, bundle_id) in enumerate(actor_bundle_list): |
| 187 | engine_config = deepcopy(config) |
| 188 | engine_config.ray_actor_name = actor_name |
| 189 | engine_config.node_rank = i |
| 190 | handlers.append( |
| 191 | ray.remote(actor_cls) |
| 192 | .options( |
| 193 | name=actor_name, |
| 194 | num_gpus=engine_config.gpu_per_engine / engine_config.nnodes, |
| 195 | namespace=engine_config.ray_namespace, |
| 196 | scheduling_strategy=PlacementGroupSchedulingStrategy( |
| 197 | placement_group=pg, |
| 198 | placement_group_capture_child_tasks=True, |
| 199 | placement_group_bundle_index=bundle_id, |
| 200 | ), |
| 201 | ) |
| 202 | .remote(config=engine_config) |
| 203 | ) |
| 204 | if len(actor_bundle_list) > 1: |
| 205 | # get master address and port from the first handler and set it to all handlers for distributed communication |
| 206 | master_addr, master_port = await handlers[0].get_available_address.remote(random_port=True) |
| 207 | for handler in handlers: |
| 208 | await handler.set_master_addr_port.remote(master_addr, master_port) |
| 209 | await asyncio.gather(*[handler.prepare.remote() for handler in handlers]) |
| 210 | server_address = await handlers[0].get_api_server_url.remote() |
| 211 | wrapper = ModelWrapper(models=handlers, config=config, api_address=server_address) |
| 212 | await wrapper.prepare() |
| 213 | return wrapper |
| 214 | |
| 215 | |
| 216 | async def get_external_model_wrapper(config: InferenceModelConfig) -> ModelWrapper: |
no test coverage detected