Begin by creating an account at app.valohai.com.
Is your team already on Valohai?
While most Valohai users log in from app.valohai.com, some teams use a self-hosted Valohai installation. Check with your team to confirm the correct domain.
Install the tools
Install the valohai-cli
tool on your local machine (or wherever you write your scripts) by running:
pipx install valohai-cli
# Then use your credentials to log in
vh login
pipx not found?
pipx
is a utility for installing and running Python applications in isolated environments.
See the pipx Installation Guide.
If pipx
is not available, you can also install Valohai using pip
or pip3
, depending on your environment.
Create a project
First, create a directory on your local machine:
mkdir hello-valohai
Navigate to the newly created folder. Then, create a new Valohai project and link local commands to it. This setup informs Valohai which project to use when running a job from your machine:
vh project create --name hello-valohai
Create a hello.py
About this example
This quickstart does not involve complex examples. Its purpose is to demonstrate how to launch jobs on remote cloud or on-premises machines using Valohai, while ensuring proper versioning and tracking.
This example is based on the YOLOv8 quickstart.
Create a file named train.py
and insert a simple yolov8
training example:
import shutil
from ultralytics import YOLO
import json
# Load a pretrained model (recommended for training)
model = YOLO("yolov8n.pt")
# Train the model
model.train(data="coco128.yaml", epochs=1, verbose=False)
# Export the model to ONNX format
path = model.export(format="onnx")
Next, modify the code to copy the generated model to the Valohai outputs directory, and create an alias so that you can easily reference the file later using the alias “latest-model”:
import shutil
from ultralytics import YOLO
import json
# Load a pretrained model (recommended for training)
model = YOLO("yolov8n.pt")
# Train the model
model.train(data="coco128.yaml", epochs=1, verbose=False)
path = model.export(format="onnx")
# Copy the exported model to the Valohai outputs directory
shutil.copy(path, '/valohai/outputs/')
file_metadata = {
"valohai.alias": "latest-model"
}
# Attach the metadata to the file, enabling easy retrieval by the alias
with open("/valohai/outputs/best.onnx.metadata.json", "w") as outfile:
f.write(json.dumps(file_metadata))
Create a valohai.yaml
Finally, create a valohai.yaml
configuration file to describe the job for Valohai. This configuration includes a step name, the command to run the script, the environment configuration, and a base environment image that contains Python and YOLOv8 libraries, sourced from a Docker image on hub.docker.com.
Update the environment field with the GPU machine you want to run the job on. You can see a list of available GPU machines by running vh environments --gpu
. Use the slug name provided in the output.
- step:
name: yolo
image: docker.io/ultralytics/ultralytics:8.0.180-python
command: python train.py
environment: aws-eu-west-1-p3-2xlarge
Run from the command line
When you’re ready, run your training on a remote cloud or on-premises machine by sending the job to the Valohai scheduler:
vh execution run yolo --adhoc --open-browser
A new browser tab will open, showing:
- Detailed execution information, including a snapcode of the code used for the job.
- All standard logs.
- Once the job completes, the trained model will be available in the outputs tab. It will be versioned and stored in the configured data store.
Stream logs to your command-line
To stream logs directly to your command line, include the --watch
flag:
bash
vh execution run yolo --adhoc --watch