| 96 | |
| 97 | |
| 98 | class RayResourcePool(ResourcePool): |
| 99 | def __init__( |
| 100 | self, |
| 101 | process_on_nodes: Optional[list[int]] = None, |
| 102 | use_gpu: bool = True, |
| 103 | name_prefix: str = None, |
| 104 | max_colocate_count: int = 10, |
| 105 | detached=False, |
| 106 | accelerator_type: Optional[str] = None, |
| 107 | ) -> None: |
| 108 | super().__init__(process_on_nodes, max_colocate_count) |
| 109 | self.use_gpu = use_gpu |
| 110 | # print(f"in RayProcessDispatchConfiguration: name_prefix = {name_prefix}") |
| 111 | self.name_prefix = get_random_string(length=6) if name_prefix is None else name_prefix |
| 112 | self.pgs = None |
| 113 | self.detached = detached |
| 114 | self.accelerator_type = accelerator_type |
| 115 | |
| 116 | def get_placement_groups(self, strategy="STRICT_PACK", name=None, device_name="cuda"): |
| 117 | if self.pgs is not None: |
| 118 | return self.pgs |
| 119 | |
| 120 | pg_name_prefix = ( |
| 121 | name if name else f"{self.name_prefix}verl_group_{'_'.join([str(count) for count in self._store])}:" |
| 122 | ) |
| 123 | # print(f"pg_name_prefix = {pg_name_prefix}") |
| 124 | if device_name == "npu": |
| 125 | device_name = "NPU" |
| 126 | elif device_name == "cuda": |
| 127 | device_name = "GPU" |
| 128 | |
| 129 | bundle = {"CPU": self.max_colocate_count} |
| 130 | if self.use_gpu: |
| 131 | bundle[device_name] = 1 |
| 132 | if self.accelerator_type is not None: |
| 133 | bundle[self.accelerator_type] = 1e-4 |
| 134 | pg_scheme = [[bundle.copy() for _ in range(process_count)] for process_count in self._store] |
| 135 | |
| 136 | lifetime = "detached" if self.detached else None |
| 137 | |
| 138 | pgs = [ |
| 139 | placement_group(bundles=bundles, strategy=strategy, name=pg_name_prefix + str(idx), lifetime=lifetime) |
| 140 | for idx, bundles in enumerate(pg_scheme) |
| 141 | ] |
| 142 | |
| 143 | ray.get([pg.ready() for pg in pgs]) |
| 144 | |
| 145 | self.pgs = sort_placement_group_by_node_ip(pgs) |
| 146 | return pgs |
| 147 | |
| 148 | |
| 149 | class SubRayResourcePool(RayResourcePool): |
no outgoing calls