Using Ray on Slurm-on-Kubernetes (SUNK) provides Ray’s Python native parallelism with Slurm’s enterprise-level scheduler. By using Ray on SUNK, you let Slurm manage when and where jobs run, while Ray manages how distributed tasks are executed. This document covers integrating Ray’s distributed computing framework with SUNK’s Slurm-based job scheduler and covers container preparation, cluster management, and interactive debugging. Consider running Ray on SUNK if one of the following apply:Documentation Index
Fetch the complete documentation index at: https://docs.coreweave.com/llms.txt
Use this file to discover all available pages before exploring further.
- Most of your compute usage is through Slurm, and you need Ray to orchestrate workloads.
- You want to support Ray and Slurm users from a single environment, using the Slurm scheduler for efficient resource allocation.
Prerequisites
Before completing the steps in the guide, be sure you have the following:- Access to a SUNK cluster with permissions to submit jobs.
- Familiarity with Slurm commands, such
srun,sbatch, andsqueue.
Create a Ray cluster on Slurm
When working with containers on Slurm, you typically pull them as squash files to a shared directory in the Slurm login nodes. Within the shared directory, you can then execute the containers using multiple nodes without making simultaneous repository pulls. There are two methods for pulling containers:-
Pulling a Ray container and saving it as a squash file using
enroot. This is useful if you need to debug container errors. -
Pulling a container as a
sqshfile usingsrun. This is useful when your containers are well-tested and you only want to run jobs.
Pull a Ray container
To pull a Ray container, complete the following steps.-
From the login node, create an interactive session on a GPU by running the following command:
(Note that you can also create a VS Code tunnel to the GPU.)
- NODE_TYPE: Change this option based on your available resources.
You should now be in a session on a GPU node. Verify you are in a shared directory, such as your home directory orExample with h100 node/mnt/data. -
Import and start the container. Note that this can be any container, but here we’ll use a
rayprojectnightly container:You should see output similar to the following:
--rw flag to start the container, changes you make will be saved when you exit.
If you are using a container from ghcr.io, prefix it with docker://, for example, docker://ghcr.io/. If your container requires permissions, you will need to configure your enroot credentials. For more information about enroot, see the SUNK Training guide.
Conda environment
Instead of using containers, you can create a conda environment that includes your dependencies. However, this is not recommended. Ray expects the versions of Ray and Python used in the head and worker nodes to be identical to those used in the Ray script being run. Conda environments with many users can be difficult to manage, but conda may be easier for testing and debugging when running Ray on Slurm. If using conda, you need to initialize your conda environment (only once).-
To initialize a conda environment, determine its PATH and initialize it:
Use the conda PATH in the next command. For example, if the PATH is the following:Enter the PATH below:
-
Create an environment with the version of Ray that you want to use and any additional packages. Here the environment is called
rayenv:
Scripts for generating sbatch files
You can write a script to generate sbatch files for creating Ray clusters of the size and specifications you want. This lets you generate the right sbatch commands programmatically. For examples of these kinds of scripts, refer to the NERSC GitHub repository.
The following example script starts up a Ray cluster and also runs a job. If you want to start a Ray cluster and use it interactively, make sure the sbatchscript does not exit by putting a sleep inf command in the script. This keeps the script running for a specified time as an interactive development cluster. You can exit it earlier if you don’t need it.
Note that the instructions use the variable SLURM_GPUS_PER_TASK. This is not a default Slurm variable. You need to set it. In the following examples, it’s hardcoded to 8. Adjust the number of GPUs per task as you need.
To see available capacity, use the sinfo command. The partitions of different skus will typically be separated by name, for example, h100, h200.
sbatch script:
srun command for the sbatch script above:
- USER_NAME: Replace with your username.
- rayproject+ray+nightly-py39-gpu.sqsh: This is the Ray container squash file we downloaded in the Pull a Ray container section.
- tune_basic_example.py: Create this file under your username with the contents found in the NERSC repository here.
Pull a container as a sqsh file using srun
To pull a container as a sqsh file using srun, complete the following steps.
-
On a login node, execute a simple command—such as “echo hello”—on the development container. As an example, we use a
nccltest to pull and save the container.${HOME}/nccl-test.sqsh. Update${HOME}andnccl-test.sqshbased on where you want to save the file and what name to give it.
-
To pull the latest Ray container, run the following command:
${HOME}/ray-nightly-py39-gpu. Update${HOME}andray-nightly-py39-gpubased on where you want to save the file and what name to give it.
Interactively modify a container using srun
You can interactively modify a container using srun by mounting the home directory explicitly and saving the container. You can then install Ray inside the container:
${HOME}/nccl-test.sqsh. Update${HOME}andnccl-test.sqshbased on where you saved the container image from the previous steps.
nccl-test-new.sqsh is saved.
Work with Ray on Slurm
Once your Ray environment is running, you can either connect interactively to the running Ray cluster for development or attach to a containerized Ray job to debug or inspect it. See instructions for each option below.Interactively log in to a Ray environment
You can run the script by submitting thesbatch script. Note that the script includes the command to sleep an environment.
-
Use the example script above and save it as
ray.devcluster.batch, and then run the following command: -
Your Ray environment will be a job. You can find out what job it is by running the following command:
You should see similar output like the following:
-
Above we can see that the
JOBIDis1335. This is a mini Ray environment with two h100 nodes. To connect to it and begin running things interactively, you would run the following command:jobid: Be sure to replace thejobidflag with the job you want to run.--overlap: The overlap flag specifies that you should attach to the head node of the specified job, herejobid=1335.
Attach to a Ray job using a container
If you launch a job using a container, you can connect to that container by providing the container name, as opposed to sleeping in the Ray environment for a job recently launched. To attach to a Ray job using a container, complete the following steps.-
Run the
squeuecommand to figure out what job it is: -
Find the specific step that is running the container using
sacct.sacctis a Slurm command that gives more information about the “steps” of the job. Steps are tasks launched within the allocation that use some or all of the resources.- JOB_ID: Replace with your
jobid.
- JOB_ID: Replace with your
-
This will start the container in the same allocation, so you can debug the run interactively. You want to be able to connect with the same container to a specific step.
--container-image: Replace with the location of your container image.--jobid: Replace with yourjobid.
-Jflag in thesruncommand. This makes it easier to find. Note this will take a minute because first it is launching all the Ray daemons. There will be multiple nodes in the cluster but you can onlysshinto one. The node that it will pick by default will be the head node of the allocation, which will be where you can runray status. -
To connect to a specific node in your Ray environment, provide it on the command line with the
--nodelistflag.--nodelist: Replace with your node.--container-image: Replace with the location of your container image.--jobid: Replace with yourjobid.
Stop a Ray environment
To delete a job, find the job id usingsqueue and cancel it using the following command:
JOB_ID: Replace with the job you want to delete.