importrayfromray.util.actor_poolimportActorPoolfromray.util.acceleratorsimportNVIDIA_TESLA_V100ray.init(ignore_reinit_error=True,include_dashboard=False)DEVICE="cuda"iftorch.cuda.is_available()else"cpu"DTYPE=torch.float16ifDEVICE=="cuda"elsetorch.float32NUM_GPU=4@ray.remote(num_cpus=1,num_gpus=1,accelerator_type=NVIDIA_TESLA_V100)classMyWorker:defhello(self,payload):"""use GPU here, for example, load a model into GPU
"""return'predicted'MODEL_POOL=ActorPool([WayspotEmbedding.remote()for_inrange(NUM_GPU)])forpayloadinpayloads:MODEL_POOL.submit(lambdaa,v:a.predict.remote(v),row)results=[]foridxinrange(len(payloads)):try:results.append(MODEL_POOL.get_next())exceptExceptionase:passprint(results)