Skip to content

Instantly share code, notes, and snippets.

@xiaohan2012
Created February 1, 2023 20:07
Show Gist options
  • Save xiaohan2012/dc78d280ca73dd0b3b4248b814feb245 to your computer and use it in GitHub Desktop.
Save xiaohan2012/dc78d280ca73dd0b3b4248b814feb245 to your computer and use it in GitHub Desktop.
Progress bar in Ray
import ray
from tqdm import tqdm
class RayProgressBar:
@staticmethod
def num_jobs_done_iter(obj_ids):
while obj_ids:
done, obj_ids = ray.wait(obj_ids)
yield ray.get(done[0])
@staticmethod
def show(obj_ids):
seq = RayProgressBar.num_jobs_done_iter(obj_ids)
for x in tqdm(seq, total=len(obj_ids)):
pass
@staticmethod
def check():
assert ray.is_initialized()
# usage:
# obj_ids = [func.remote() for _ in range(10)]
# RayProgressBar.show(obj_ids)
# res = ray.get(obj_ids)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment