| 126 | |
| 127 | |
| 128 | class RayClassWithInitArgs(ClassWithInitArgs): |
| 129 | |
| 130 | def __init__(self, cls, *args, **kwargs) -> None: |
| 131 | # self._options = kwargs.pop('options', dict()) |
| 132 | super().__init__(cls, *args, **kwargs) |
| 133 | self._options = {} |
| 134 | self._additional_resource = {} |
| 135 | |
| 136 | def set_additional_resource(self, additional_resource): |
| 137 | self._additional_resource = additional_resource |
| 138 | |
| 139 | def update_options(self, options: Dict): |
| 140 | self._options.update(options) |
| 141 | |
| 142 | def __call__(self, |
| 143 | placement_group, |
| 144 | placement_group_bundle_idx, |
| 145 | use_gpu: bool = True, |
| 146 | num_gpus=1, |
| 147 | sharing_with=None) -> Any: |
| 148 | if sharing_with is not None: |
| 149 | target_node_id = ray.get(sharing_with.get_node_id.remote()) |
| 150 | cuda_visible_devices = ray.get(sharing_with.get_cuda_visible_devices.remote()) |
| 151 | options = {"scheduling_strategy": NodeAffinitySchedulingStrategy(node_id=target_node_id, soft=False)} |
| 152 | return self.cls.options(**options).remote(*self.args, |
| 153 | cuda_visible_devices=cuda_visible_devices, |
| 154 | **self.kwargs) |
| 155 | |
| 156 | options = { |
| 157 | "scheduling_strategy": |
| 158 | PlacementGroupSchedulingStrategy(placement_group=placement_group, |
| 159 | placement_group_bundle_index=placement_group_bundle_idx) |
| 160 | } |
| 161 | options.update(self._options) |
| 162 | |
| 163 | if use_gpu: |
| 164 | options["num_gpus"] = num_gpus |
| 165 | |
| 166 | if len(self._additional_resource) > 1: |
| 167 | for k, v in self._additional_resource.items(): |
| 168 | options[k] = v |
| 169 | |
| 170 | # print("cls:", self.cls) |
| 171 | # print("args: ", self.args) |
| 172 | # print("kwargs: ", self.kwargs) |
| 173 | return self.cls.options(**options).remote(*self.args, **self.kwargs) |
| 174 | |
| 175 | |
| 176 | class RayWorkerGroup(WorkerGroup): |
no outgoing calls
no test coverage detected