CLI¶
ray-vast {up,down,attach,dashboard} CLUSTER_YAML [options]
Every command takes the path of the cluster YAML. The YAML needs cluster_name and node_config.region of the head node type.
down, attach and dashboard take the region from the state file ~/.ray-vast/<cluster_name>.json when it exists. Only up rejects the removed and moved provider fields.
ray-vast --help and ray-vast <command> --help show the options.
Commands¶
| Command | What it does |
|---|---|
up |
Makes the IAM role, the SSH key pair, the 5 security groups, the instance profile and the EC2 head. Builds a derived image on the head. Starts Ray. |
down |
Removes everything of the cluster. Prints left: nothing when done. |
attach |
Opens an SSH shell on the head (user ubuntu). |
dashboard |
Copies the cluster token to the laptop, prints the export line, and opens an SSH tunnel to port 8265 of the head. |
Options¶
| Option | Commands | Meaning |
|---|---|---|
--profile NAME |
all | AWS profile. Default: AWS_PROFILE. Else, for down, attach and dashboard, the profile that up saved. Else the default credentials. |
--wheel FILE |
up |
For development. Install this ray-vast wheel on the head. |
Exit codes¶
| Code | Meaning |
|---|---|
| 0 | Success. |
| 1 | An error. For down: something is left. |
| 2 | A bad command line, for example an unknown option such as the removed --index-url, --key-name or --key-file. |
attach and dashboard return the exit code of ssh.
Errors¶
- A user error prints one line on stderr:
ray-vast <command>: <message>. The exit code is 1. - User errors include a missing YAML file, bad YAML syntax, a bad YAML field value, an unknown AWS profile and missing AWS credentials. The message names the file, the field or the profile.
- An AWS error adds more lines: a hint about missing permissions, and for
up, theray-vast downcommand. - An unexpected error (a bug) prints a Python traceback. The last line of the traceback has the message.
ray-vast up¶
ray-vast up cluster.yaml --profile my-aws-profile
up does these steps:
- It reads and checks the YAML. It shows the warnings. It stops at once if the cluster already exists: an EC2 head with the cluster tag, or
~/.ray-vast/<cluster_name>.json. - It makes the IAM role
ray-vast-<cluster_name>with the permissions boundaryray-vast-head-boundary. If the boundary policy does not exist,upstops here and makes nothing. Read Getting started. - It writes
~/.ray-vast/<cluster_name>.jsonwith the region and the AWS profile. - It makes the EC2 key pair
ray-vast-<cluster_name>and saves the private key in~/.ray-vast/<cluster_name>/ssh_key.pem(mode 600). - It makes the 5 security groups
ray-vast-<cluster_name>-0…-4, the role policy and the instance profile. Group 0 gets one SSH rule for the public IP of your laptop. - It starts the EC2 head: Ubuntu 24.04, the
instance_typeof the head node type, 60 GB gp3 disk, IMDSv2 required, no Elastic IP. User data installs Docker. - It builds a derived image on the head:
provider.imageplus ray-vast. Read Where the head gets ray-vast. It reads the Ray version of the image, and warns if it is not 2.59. - It measures the image size. The size sets the pull limit of the workers.
- It copies the vast key to the head. It makes the CA, the cluster token and the head certificate on the head. The CA key never leaves the head.
- It starts the head container
ray-vast-headand waits untilray statusanswers.
Output:
installing ray-vast==<version> from PyPI
head instance <instance id> starting
head IP <head ip>
cluster <cluster_name> is up. Head IP <head ip>.
dashboard: ray-vast dashboard cluster.yaml (then open http://127.0.0.1:8265)
shell: ray-vast attach cluster.yaml
up adds lines that start with warning: when they apply. They come in this order:
- After the
installingline: the warnings of the YAML checks (CPUabove 58,allow_non_datacenter). - After the
head IPline: an untested Ray version in the image. - Just before the
cluster ... is upline: a CA that expires within 14 days.
Rules:
upreads the vast key fromVAST_API_KEY, or from~/.config/vastai/vast_api_key. It sends the key to the head. The key is never in the YAML.upsaves the AWS profile (--profileorAWS_PROFILE) in the state file. The other commands use it by default.attachanddashboarduse the SSH key thatupmade. So run them on the machine that ranup.upmakes no vast rental. Workers start when a job needs them, or formin_workers.- After an AWS error,
upprintsRun ray-vast down CLUSTER_YAML to remove what was created.
Where the head gets ray-vast¶
up installs ray-vast in the derived image. The first line of the up output tells the source. up uses the first source that applies:
| Source | When | Output line |
|---|---|---|
| A wheel file | You pass --wheel FILE. |
installing ray-vast from the wheel FILE |
| The source tree | ray-vast runs from a git clone (an editable install). up builds the wheel with python -m build. This needs the build package (in the test extra). |
installing ray-vast from a wheel built from the source tree <path> |
| PyPI | All other cases: the normal pip install ray-vast. |
installing ray-vast==<version> from PyPI |
<version>is the version of theray-vastpackage on your laptop. So the head runs the same version as the CLI.- If the image build fails,
upstops withthe head image build failed while installing ray-vast==<version> from PyPI; see the build output below. The end of the build output follows. The head exists then. Runray-vast down.
To test a release on TestPyPI, download its wheel and pass it with --wheel:
pip download --no-deps --index-url https://test.pypi.org/simple/ ray-vast==<version> -d /tmp/rv
ray-vast up cluster.yaml --profile my-aws-profile --wheel /tmp/rv/ray_vast-<version>-py3-none-any.whl
ray-vast down¶
ray-vast down cluster.yaml
down does these steps:
- It terminates the EC2 head first. So the autoscaler cannot rent new workers.
- It destroys every vast instance with the label
ray-vast:<cluster_name>. It lists again until none is left. - It deletes the 5 security groups, the key pair, the instance profile and the role.
- It deletes the state files in
~/.ray-vast/, with the private SSH key. - It prints what is left.
Output:
terminating head <instance id>
destroyed 2 vast instance(s)
deleted security group <group id>
...
deleted key pair ray-vast-<cluster_name>
deleted instance profile ray-vast-<cluster_name>
deleted role ray-vast-<cluster_name>
left: nothing
Rules:
downneeds no SSH key.- Without
--profileandAWS_PROFILE,downuses the profile thatupsaved. downfinds everything by tag, name and label. It works after a failedup, when the head is gone, and when the state file is missing.- If something is left,
downlists it and exits with code 1. Rundownagain. - Without a vast key,
downcleans AWS, warns that the vast instances were not swept, and exits with code 0. Read Clean up after a failure.
ray-vast attach¶
ray-vast attach cluster.yaml
Opens an SSH shell on the EC2 host of the head, as the user ubuntu. Ray runs in the Docker container ray-vast-head. Run Ray commands in it:
sudo docker exec ray-vast-head ray status
ray-vast dashboard¶
ray-vast dashboard cluster.yaml
- It copies the cluster token to
~/.ray-vast/<cluster_name>/token(mode 600). - It prints the
exportline for the Ray CLI. - It opens an SSH tunnel from port 8265 on your laptop to port 8265 on the head. Ctrl-C closes it. Then the command prints
tunnel closedand exits with code 0.
Output:
for `ray job submit` set:
export RAY_AUTH_MODE=token RAY_AUTH_TOKEN_PATH=/home/you/.ray-vast/<cluster_name>/token
dashboard at http://127.0.0.1:8265 (Ctrl-C to close the tunnel); use --address http://127.0.0.1:8265
State files¶
ray-vast keeps these files on your laptop, in ~/.ray-vast/:
| File | Content |
|---|---|
<cluster_name>.json |
Region, AWS profile, head instance ID and IP, security groups, role and instance profile names. up writes it. |
<cluster_name>/ssh_key.pem |
The private SSH key of the head. up writes it. Mode 600. |
<cluster_name>.known_hosts |
SSH host keys of the head (StrictHostKeyChecking=accept-new). |
<cluster_name>/token |
The cluster token. dashboard writes it. Mode 600. |
down deletes all of them.
Cluster names¶
The cluster name must match [A-Za-z0-9][A-Za-z0-9_-]{0,39}: 1 to 40 letters, digits, _ and -, and it starts with a letter or digit.
Environment variables¶
| Variable | Use |
|---|---|
AWS_PROFILE |
The default of --profile. It wins over the profile that up saved. |
VAST_API_KEY |
The vast API key. If it is not set, ray-vast reads ~/.config/vastai/vast_api_key. |
Ray commands that do not work¶
Some ray cluster commands do not work with this provider. The list is in Limits.