Run the following commands in your local development machine.
pipx install valohai-cli
# Login with your credentials
vh login
# Creat a directory in your local machine
mkdir hello-valohai
cd hello-valohai
# Create a project
vh project create --name hello-valohai
Then add a new Python file hello.py
and place inside it:
import valohai
import json
my_data = {
'myinput': 'https://valohaidemo.blob.core.windows.net/mnist/preprocessed_mnist.npz'
}
# Define parameters in a dictionary
my_parameters = {
'iterations': 5,
}
# Prepare a Valohai step called "train"
# that'll use a public PyTorch image
valohai.prepare(
step="train",
image="tensorflow/tensorflow:2.6.1-gpu",
default_inputs=my_data,
default_parameters=my_parameters
)
# Get the path to the downloaded file
downloaded_file_path = valohai.inputs('myinput').path()
print(f"Downloaded file available at: {downloaded_file_path}")
# Access the parameter defined at runtime
num_iterations = valohai.parameters('iterations').value
for i in range(num_iterations):
# Print random metrics
with valohai.metadata.logger() as logger:
logger.log("iteration", num_iterations)
logger.log("accuracy", random.uniform(60.0, 95.0))
Finally launch your job in Valohai — but let’s change the default parameter value
vh execution run train --iterations=10 --adhoc --open
That’s it! :tada: