NNI 文档

NNI (Neural Network Intelligence) 是一个轻量而强大的工具,可以帮助用户 自动化

开始使用

安装最新的版本,可执行以下命令:

$ pip install nni

如果在安装上遇到问题,可参考 安装指南

开始你的第一个 NNI 实验

$ nnictl hello

备注

你需要预先安装 PyTorch (以及 torchvision )才能运行这个实验。

请阅读 NNI 快速入门 以开启你的 NNI 旅程!

为什么选择 NNI?

NNI 使得自动机器学习技术即插即用

_images/hpo-small.svg

超参调优

params = nni.get_next_parameter()

class Net(nn.Module):
    ...

model = Net()
optimizer = optim.SGD(model.parameters(),
                      params['lr'],
                      params['momentum'])

for epoch in range(10):
    train(...)

accuracy = test(model)
nni.report_final_result(accuracy)

_images/pruning-small.svg

模型剪枝

# define a config_list
config = [{
    'sparsity': 0.8,
    'op_types': ['Conv2d']
}]

# generate masks for simulated pruning
wrapped_model, masks = \
    L1NormPruner(model, config). \
    compress()

# apply the masks for real speedup
ModelSpeedup(unwrapped_model, input, masks). \
    speedup_model()

_images/quantization-small.svg

模型量化

# define a config_list
config = [{
    'quant_types': ['input', 'weight'],
    'quant_bits': {'input': 8, 'weight': 8},
    'op_types': ['Conv2d']
}]

# in case quantizer needs a extra training
quantizer = QAT_Quantizer(model, config)
quantizer.compress()
# Training...

# export calibration config and
# generate TensorRT engine for real speedup
calibration_config = quantizer.export_model(
    model_path, calibration_path)
engine = ModelSpeedupTensorRT(
    model, input_shape, config=calib_config)
engine.compress()

_images/multi-trial-nas-small.svg

神经网络架构搜索

# define model space
-   self.conv2 = nn.Conv2d(32, 64, 3, 1)
+   self.conv2 = nn.LayerChoice([
+       nn.Conv2d(32, 64, 3, 1),
+       DepthwiseSeparableConv(32, 64)
+   ])
# search strategy + evaluator
strategy = RegularizedEvolution()
evaluator = FunctionalEvaluator(
    train_eval_fn)

# run experiment
RetiariiExperiment(model_space,
    evaluator, strategy).run()

_images/one-shot-nas-small.svg

单尝试 (One-shot) NAS

# define model space
space = AnySearchSpace()

# get a darts trainer
trainer = DartsTrainer(space, loss, metrics)
trainer.fit()

# get final searched architecture
arch = trainer.export()

_images/feature-engineering-small.svg

特征工程

selector = GBDTSelector()
selector.fit(
    X_train, y_train,
    lgb_params=lgb_params,
    eval_ratio=eval_ratio,
    early_stopping_rounds=10,
    importance_type='gain',
    num_boost_round=1000)

# get selected features
features = selector.get_selected_features()

NNI 可降低自动机器学习实验管理的成本

_images/training-service-small.svg

训练平台

一个自动机器学习实验通常需要很多次尝试,来找到合适且具有潜力的模型。 训练平台 的目标便是让整个调优过程可以轻松的扩展到分布式平台上,为不同的计算资源(例如本地机器、远端服务器、集群等)提供的统一的用户体验。 目前,NNI 已经支持 超过九种 训练平台。

_images/web-portal-small.svg

网页控制台

网页控制台提供了可视化调优过程的能力,让你可以轻松检查、跟踪、控制实验流程。

_images/webui.gif

_images/experiment-management-small.svg

多实验管理

深度学习模型往往需要多个实验不断迭代,例如用户可能想尝试不同的调优算法,优化他们的搜索空间,或者切换到其他的计算资源。 多实验管理 提供了对多个实验的结果进行聚合和比较的强大能力,极大程度上简化了开发者的开发流程。

获取帮助或参与贡献

NNI 使用 NNI GitHub 仓库 进行维护。我们在 GitHub 上收集反馈,以及新需求和想法。你可以:

  • 新建一个 GitHub issue 反馈一个 bug 或者需求。

  • 新建一个 pull request 以贡献代码(在此之前,请务必确保你已经阅读过 贡献指南)。

  • 如果你有任何问题,都可以加入 NNI 讨论

  • 加入即时聊天群组:

Gitter

微信

https://user-images.githubusercontent.com/39592018/80665738-e0574a80-8acc-11ea-91bc-0836dc4cbf89.png https://github.com/scarlett2018/nniutil/raw/master/wechat.png

引用 NNI

如果你在你的文献中用到了 NNI,请考虑引用我们:

Microsoft. Neural Network Intelligence (version v3.0pt1). https://github.com/microsoft/nni

Bibtex 格式如下(请将版本号替换成你在使用的特定版本):

@software{nni2021,
   author = {{Microsoft}},
   month = {1},
   title = {{Neural Network Intelligence}},
   url = {https://github.com/microsoft/nni},
   version = {2.0},
   year = {2021}
}