Learn / DGX Spark Ray Cluster Setup

Ray cluster, part 2: set up, check, stop

Now set up Ray on two DGX Sparks. First, the safety warning. Anyone who can reach Ray's dashboard, jobs or client services can run code on your Sparks.

Chapters

  1. 0:00Introduction
  2. 0:06Read this first: Ray runs code
  3. 0:24On both Sparks: Install the same version
  4. 0:34First Spark only: One token for both
  5. 0:48First Spark: Start the head
  6. 0:57Second Spark: Join the worker
  7. 1:05First Spark: Check both joined
  8. 1:15First Spark: See where work ran
  9. 1:28Stop: Stop the worker first
  10. 1:38Wrap up
Read the transcript

Introduction

Now set up Ray on two DGX Sparks. First, the safety warning.

Read this first: Ray runs code

Anyone who can reach Ray's dashboard, jobs or client services can run code on your Sparks. Never expose them. Block Ray's ports from every network except the cluster link. Turn on token authentication. It adds to that protection, and doesn't replace it.

On both Sparks: Install the same version

Make a Python environment on both Sparks. Switch it on. Install the same Ray version on both, with matching Python versions.

python3 -m venv ~/ray-env
source ~/ray-env/bin/activate
pip install "ray[default]==VERSION"

First Spark only: One token for both

Make the token on the first Spark. This prints it, so keep your screen private. Make a private folder on the second Spark. Copy the token across, over the cluster link. Then make the copy readable only by you.

ray get-auth-token --generate
ssh USER@SECOND-SPARK-LINK-ADDRESS \
'mkdir -p ~/.ray && chmod 700 ~/.ray'
scp ~/.ray/auth_token \
USER@SECOND-SPARK-LINK-ADDRESS:.ray/auth_token
ssh USER@SECOND-SPARK-LINK-ADDRESS \
'chmod 600 .ray/auth_token'

First Spark: Start the head

On the first Spark, turn token mode on. Then start the head on its cluster link address, with the dashboard on localhost.

export RAY_AUTH_MODE=token
ray start --head --port=6379 \
--node-ip-address=FIRST-SPARK-LINK-ADDRESS \
--dashboard-host=localhost

Second Spark: Join the worker

On the second Spark, turn token mode on there too. Then join the head, using the second Spark's own link address.

export RAY_AUTH_MODE=token
ray start --address=FIRST-SPARK-LINK-ADDRESS:6379 \
--node-ip-address=SECOND-SPARK-LINK-ADDRESS

First Spark: Check both joined

Check the listening ports, so you know what your firewall must block. Then ask for the status. You want two active nodes, and two GPUs if you offered both.

sudo ss -ltnp
ray status

First Spark: See where work ran

Run the small example from the written page. It counts tasks by host name. Compare default with spread. The counts needn't be equal. Ray's task list can also show which node ran each task.

python where_ran.py
ray list tasks --detail

Stop: Stop the worker first

Finish your jobs first. Stopping ends all Ray processes on that machine. Run it on the worker. Then run it on the head.

ray stop    # on the second Spark
ray stop    # then on the first

Wrap up

The written page covers vLLM, undoing the setup, and problems.

Sources

More lessons