def get_full_actor_cls( self, trial: "Trial", actor_cls: ActorClass ) -> Optional[ActorClass]: """Get a fully configured actor class. Returns the actor handle if the placement group is ready. In this case, the placement group is moved to `self._in_use_pgs` and removed from `self._ready`. Args: trial: "Trial" object to start actor_cls: Ray actor class. Returns: Configured ActorClass or None """ pgf = trial.placement_group_factory if not self._ready[pgf]: return None pg = self._ready[pgf].pop() self._in_use_pgs[pg] = trial self._in_use_trials[trial] = pg logger.debug(f"For trial {trial} use pg {pg.id}") # We still have to pass resource specs if not pgf.head_bundle_is_empty: # Pass the full resource specs of the first bundle per default head_bundle = pg.bundle_specs[0].copy() num_cpus = head_bundle.pop("CPU", 0) num_gpus = head_bundle.pop("GPU", 0) memory = head_bundle.pop("memory", None) object_store_memory = head_bundle.pop("object_store_memory", None) # Only custom resources remain in `head_bundle` resources = head_bundle return actor_cls.options( placement_group=pg, placement_group_bundle_index=0, placement_group_capture_child_tasks=True, num_cpus=num_cpus, num_gpus=num_gpus, memory=memory, object_store_memory=object_store_memory, resources=resources, ) else: return actor_cls.options( placement_group=pg, placement_group_capture_child_tasks=True, num_cpus=0, num_gpus=0, resources={}, )
def get_full_actor_cls(self, trial: "Trial", actor_cls: ActorClass) -> Optional[ActorClass]: """Get a fully configured actor class. Returns the actor handle if the placement group is ready. In this case, the placement group is moved to `self._in_use_pgs` and removed from `self._ready`. Args: trial ("Trial"): "Trial" object to start actor_cls: Ray actor class. Returns: Configured ActorClass or None """ pgf = trial.placement_group_factory if not self._ready[pgf]: return None pg = self._ready[pgf].pop() self._in_use_pgs[pg] = trial self._in_use_trials[trial] = pg # We still have to pass resource specs # Pass the full resource specs of the first bundle per default first_bundle = pg.bundle_specs[0].copy() num_cpus = first_bundle.pop("CPU", None) num_gpus = first_bundle.pop("GPU", None) # Only custom resources remain in `first_bundle` resources = first_bundle or None if num_cpus is None: # If the placement group specifically set the number # of CPUs to 0, use this. num_cpus = pgf.head_cpus logger.debug(f"For trial {trial} use pg {pg.id}") return actor_cls.options( placement_group=pg, placement_group_bundle_index=0, placement_group_capture_child_tasks=True, num_cpus=num_cpus, num_gpus=num_gpus, resources=resources)
def get_full_actor_cls(self, trial: Trial, actor_cls: ActorClass) -> Optional[ActorClass]: """Get a fully configured actor class. Returns the actor handle if the placement group is ready. In this case, the placement group is moved to `self._in_use_pgs` and removed from `self._ready`. Args: trial (Trial): Trial object to start actor_cls: Ray actor class. Returns: Configured ActorClass or None """ pgf = trial.placement_group_factory if not self._ready[pgf]: return None pg = self._ready[pgf].pop() self._in_use_pgs[pg] = trial self._in_use_trials[trial] = pg # We still have to pass resource specs # Pass the full resource specs of the first bundle per default first_bundle = pg.bundle_specs[0].copy() num_cpus = first_bundle.pop("CPU", None) num_gpus = first_bundle.get("GPU", None) # Only custom resources remain in `first_bundle` resources = first_bundle or None return actor_cls.options(placement_group=pg, placement_group_bundle_index=0, num_cpus=num_cpus, num_gpus=num_gpus, resources=resources)