定义搜索空间,即可能的超参数值。在NNI中,你可以使用一个名为search_space.json的JSON文件定义它。例如,对于学习率和隐藏层大小,可能的搜索空间如下:
{
"batch_size": {"_type":"choice", "_value": [16, 32, 64, 128]},
"hidden_size":{"_type":"choice","_value":[128, 256, 512, 1024]},
"lr":{"_type":"choice","_value":[0.0001, 0.001, 0.01, 0.1]},
"momentum":{"_type":"uniform","_value":[0, 1]}
}
在NNI的搜索空间定义中,“_type"字段用于指定超参数的分布或类型。对于”_type"字段,有两个选项“choice”和“uniform”,它们的含义如下:
config.yml是一个关键的配置文件,它包含了一次自动化机器学习试验的所有必要信息和配置
# This is the minimal config file for an NNI experiment.
# Use "nnictl create --config config.yml" to launch this experiment.
# Afterwards, you can check "config_detailed.yml" for more explanation.
searchSpaceFile: search_space.json
trialCommand: python3 mnist.py # NOTE: change "python3" to "python" if you are using Windows
trialGpuNumber: 0
trialConcurrency: 1
tuner:
name: TPE
classArgs:
optimize_mode: maximize
trainingService:
platform: local