To parameterize a step, you need parameters. They can be float
, integer
, string
or boolean
type.
With valohai-utils
, you define the parameters in the call to the prepare method. Feed the default_parameters
argument with a key/value dictionary of the parameters.
-
key is the name of the parameter. Used in the code, the YAML and the Valohai UI.
-
value defines the default value of the parameter and also its type.
Empty values are not supported as they have no type.
Defining parameters with valohai-utils
solves two problems:
-
Parsing the command-line overrides
-
Managing the duplicate definitions between Python & YAML
train.py
Here we define a step train
, with a parameter learning-rate
.
import valohai
params = {
"learning-rate": 0.001,
}
valohai.prepare(
step="train",
default_parameters=params,
)
This key/value pair…
params = {
"learning-rate": 0.001
}
…will be transpiled into the following YAML
- name: learning-rate
default: 0.001
optional: false
type: float
Accessing values
Once you have defined a parameter using the prepare method, you can access it in your code by referring to the parameter name.
lr = valohai.parameters("learning-rate").value
Overriding values
All parameters defined by the prepare method always have a default value.
There are two ways to override the default value:
- Command-line parameter (local)
- Valohai UI or CLI (remote)
Example (local):
python train.py --learning-rate=.002
vh yaml step train.py
vh exec run -a train --learning-rate=.002
Comments
0 comments
Please sign in to leave a comment.