AI Ants

迈向通用人工智能之路

0%

自动超参搜索之NNI工具使用

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

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

-p 指定运行端口;

nni
本地chrome浏览器打开http://172.22.22.203:8888/,结果如下:

nni-client

超参数搜索的结果:

nni-result

对应的accuracy:

nni-metric

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

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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

-------------本文结束感谢您的阅读-------------

本文标题:自动超参搜索之NNI工具使用

文章作者:杨苏辉

发布时间:2020年12月16日 - 17:45

最后更新:2020年12月17日 - 16:53

原始链接:https://yangsuhui.github.io/p/b5ee.html

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

如果您觉得内容不错,可以对我打赏哦!