Ray task

  • a ray task is a python function marked as runnable in parallel
  • It is stateless
  1. To get a task, you use the @ray.remote decorator on a function

  2. Ray executes this function in a separate process on any available CPU core

  3. To call the function, you call result_ref = function.remote(inpout) and you get back an ObjectRef i.e. futures. The call is async.

  4. To collect the futures, ray.get(result_refs) is a blocking call to wait for the futures.

Ray actors

  • a ray actor is a stateful worker

  • To get an actor, you use the @ray.remote decorator on a class definition

  • To instantiate an actor, you call actor_handle=class.remote() and you receive an actor handle

  • To call the functions of the actor (e.g. to update its state), you call actor_handle.func.remote(input). This call is async.

Ray data & datasets

  • It creates a plan, the head-node orchestrates the loading directly on the workers (it is streamed).

  • ray data will give python dicts to your tasks (this is how it handles rows)

  • then, when you want to apply to each row, you can call dataset.map(task_func)

    • if you want a task to process batches, you can call dataset.map_batches(batch_task_func)
    • this is still lazy btw
  • The computation only runs when we consume the results e.g. writing the data processed_ds.write_parquet