Parameters: Make Your Jobs Configurable

Turn your hardcoded values into parameters that you can change without touching code. This guide shows how to expose configuration values, hyperparameters, and other settings to Valohai.

💡 Already using argparse? You're 90% done. Just list your parameters in valohai.yaml.

Why Use Parameters?

  • Change values without code changes, Adjust hyperparameters from the UI

  • Track experiments automatically, Sort and filter by parameter values

  • Run parallel experiments, Test multiple configurations at once

  • Reproduce results, Every execution saves its exact parameters

Quick Example

Turn hardcoded values into command-line arguments:

Before

# Hardcoded values
iterations = 10
learning_rate = 0.01

After

# Parse from command line
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--iterations", type=int, default=10)
parser.add_argument("--learning_rate", type=float, default=0.01)
args = parser.parse_args()

iterations = args.iterations
learning_rate = args.learning_rate

Then declare them in valohai.yaml:

How Parameters Work

  1. Define in valohai.yaml, List parameters with types and defaults

  2. Parse in your code, Use argparse (or read from config files)

  3. Override at runtime, Change values via UI, CLI, or API

Valohai passes parameters as command-line arguments:

Common Patterns

Multiple Parameter Types

💡 Flags are not exactly booleans. When a flag gets the value false, nothing is passed to the execution. If you want the flags to behave more like actual booleans, i.e. to pass true or false to the execution, you can use the pass-true-as / pass-false-as in your valohai.yaml:

Parse in Python

Override When Running

Alternative: Read from Config Files

Don't use command-line arguments? Valohai creates config files you can read:

These files are read-only and created automatically by Valohai so you can't change the parameter values in them while the job is running.

Optional: Use the valohai-utils Python helper tool

The valohai-utils helper library offers a simpler syntax:

Parameter Types Reference

Type
YAML
Python (argparse)
Example

Integer

type: integer

type=int

--epochs=100

Float

type: float

type=float

--lr=0.001

String

type: string

type=str

--model=resnet

Flag

type: flag

action='store_true'

--augment

What's Next?

With parameters defined, you can:

  • Compare experiments, Filter executions by parameter values

  • Run hyperparameter sweeps, Test multiple values in parallel

  • Create reproducible pipelines, Lock in successful parameter sets


Last updated

Was this helpful?