NNI(自动超参数搜索)工具环境配置及使用

本文主要介绍如何搭建Microsoft的NNI工具环境以及使用NNI进行Mnist分类任务的超参数搜索。

NNI简介

NNI (Neural Network Intelligence) 是一个轻量但强大的工具包,帮助用户自动的进行特征工程,神经网络架构搜索,超参调优以及模型压缩。
NNI 管理自动机器学习 (AutoML) 的 Experiment,调度运行由调优算法生成的 Trial 任务来找到最好的神经网络架构和/或超参,支持各种训练环境,如本机,远程服务器,OpenPAI,Kubeflow,基于 K8S 的 FrameworkController(如,AKS 等), DLWorkspace (又称 DLTS), AML (Azure Machine Learning) 以及其它环境。

NNI环境安装

根据官网安装教程进行安装即可,也可以直接下载已经安装好NNI环境的docker镜像(docker pull 857470845/hvd_trt_apex_torch:v1)进行测试。
说明:NNI工程download下来后,deployment文件夹下有pypi和docker两种安装方式;docs文件夹下是一些使用说明保护config配置文件中的一些参数含义;examples下是
一些具体示例。

测试MNIST-pytorch

nnictl create --config nni/examples/trials/mnist-tfv1/config.yml -p 8888

-p 指定运行端口;

NNI(自动超参数搜索)工具环境配置及使用_第1张图片
本地chrome浏览器打开http://172.22.22.203:8888/,结果如下:

NNI(自动超参数搜索)工具环境配置及使用_第2张图片

超参数搜索的结果:

NNI(自动超参数搜索)工具环境配置及使用_第3张图片

对应的accuracy:

NNI(自动超参数搜索)工具环境配置及使用_第4张图片

同样的方式运行pytorch版本的MNIST:

nnictl create --config nni/examples/trials/mnist-pytorch/config.yml -p 8888

不过直接从官网下载的mnist-pytorch下的config.yml有一些参数需要修改一下才能使用GPU训练;
这是我修改后的config.yml配置文件,仅供参考。

authorName: default
experimentName: example_mnist_pytorch
trialConcurrency: 2
maxExecDuration: 1h
maxTrialNum: 10
#choice: local, remote, pai
trainingServicePlatform: local
searchSpacePath: search_space.json
#choice: true, false
useAnnotation: false
tuner:
  #choice: TPE, Random, Anneal, Evolution, BatchTuner, MetisTuner, GPTuner
  #SMAC (SMAC should be installed through nnictl)
  builtinTunerName: TPE
  classArgs:
    #choice: maximize, minimize
    optimize_mode: maximize
trial:
  command: python3 mnist.py
  codeDir: .
  gpuNum: 2
localConfig:
  maxTrialNumPerGpu:  2
  useActiveGpu: true
  gpuIndices: 1,3

特别说明:NNI可以本地运行,也可以和其他框架进行插件结合配置,比如和Microsoft的OpenPAI平台结合,就可以将训练任务上传到PAI平台上进行NNI训练,
不同的配置方式使用不同的config文件;

References

NNI项目地址: https://github.com/microsoft/nni/blob/master/README_zh_CN.md
使用说明: https://nni.readthedocs.io/en/latest/Tutorial/QuickStart.html
config参数: https://github.com/microsoft/nni/blob/master/docs/zh_CN/Tutorial/ExperimentConfig.md
推荐参考: https://blog.csdn.net/weixin_43653494/article/details/101039198

你可能感兴趣的:(AutoML,NNI,pytorch,神经网络,AutoML,NNI)