The Wikipedia definition of a hyperparameter is: “a parameter whose value is set before the learning process begins.” This definition exists to differentiate these values that control how the machine learning is conducted from parameters such as neural network weights that are actively changed during training. Thus, hyperparameters are a subset of parameters.
In the context of Valohai, all parameters to be recorded are defined before launching an execution. If you wish to record something that is defined or changes during runtime, use Valohai metadata.
This is the reason why we don’t always use the training-centric hyperparameter term.
Why define parameters?
- Defining parameters allows you to easily rerun, sort, and keep track of executions based on the parameter values used to run them.
- You can easily create (or copy) an execution and change the parameters in the UI, without changing your code.
- Defining parameters allows you to start creating Tasks where you run multiple parallel executions with different parameter combinations.
- Each step has its own parameter configuration in
valohai.yaml
. - A parameter can be a type of a
string
,integer
,float
, andflag
(=boolean).
Defining parameters
To keep track of parameters in Valohai, you add them as part of your YAML step.parameters.
Example of a valohai.yaml
with a step defining 3 parameters:
- step:
name: train
image: python:3.6
command:
- python train.py {parameters}
parameters:
- name: max_steps
pass-as: --max_steps={v}
type: float
default: 300
- name: learning_rate
pass-as: --learning_rate={v}
type: float
default: 0.001
- name: dropout
pass-as: --dropout={v}
type: float
default: 0.9
The above would generate the following command by default:
python train.py --max_steps=300 --learning_rate=0.001 --dropout=0.9
You can then parse the command-line arguments in your script.
import argparse
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('--max_steps', type=int, default=300)
parser.add_argument('--learning_rate', type=float, default=0.001)
parser.add_argument('--dropout', type=float, default=0.9)
return parser.parse_args()
args = parse_args()
print("Max steps: %s" % args.max_steps)
Parsing values with valohai-utils
Python users can use the valohai-utils helper library to define and parse parameters.
import valohai
my_parameters = {
'max_steps': 300,
'learning_rate': 0.001,
'dropout': 0.9,
}
valohai.prepare(step="helloworld", default_parameters=my_parameters)
print("Max steps: %s" % valohai.parameters('max_steps').value)
and generate valohai.yaml
configuration file with the parameter definitions:
vh yaml step helloworld.py
vh exec run helloworld --adhoc
Selecting values
When you are creating a new Valohai execution using the web user interface, look for the Parameters
subsection at the bottom.
Default values of the parameters are defined by the valohai.yaml
, but they can be tweaked in the web user interface, command-line client, or the API. All changes are version-controlled as part of a Valohai execution.
Comments
0 comments
Please sign in to leave a comment.