MCPcopy Create free account
hub / github.com/PRIME-RL/PRIME / RayClassWithInitArgs

Class RayClassWithInitArgs

training/verl/single_controller/ray/base.py:128–173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

126
127
128class 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
176class RayWorkerGroup(WorkerGroup):

Callers 5

__init__Method · 0.90
mainFunction · 0.90
init_workersMethod · 0.90
init_workersMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected