NNI (Neural Network Intelligence)

repository·master·Indexed 12 days ago

https://github.com/microsoft/nni

An automated toolkit for deep learning providing tools for hyperparameter tuning, neural architecture search, and model compression. It includes features such as the Network Morphism tuner for PyTorch and Keras, custom Assessors for early stopping via report_intermediate_result, and the nnictl command-line tool for experiment management.

Tokens
158.5K
Snippets
416
Records
632
Agent score
92%

What's inside NNI

  1. Overview of Quantizers in NNI

    master
    NNI provides several quantization algorithms implemented as quantizer objects. These algorithms are designed to facilitate efficient integer-arithmetic-only inference or low-bitwidth training. The available quantizers include implementations of established research papers such as DoReFa-Net, Binarized Neural Networks, and Learned Step Size Quantization (LSQ), as well as Post-Training Quantization (PTQ).
  2. Overview of NNI capabilities

    master

    NNI (Neural Network Intelligence) automates several key stages of the deep learning lifecycle:

    • Hyperparameter Tuning (HPO): Uses various algorithms including Exhaustive search (Grid Search, Random), Heuristic search (Anneal, Evolution, Hyperband, PBT), and Bayesian optimization (BOHB, DNGO, GP, Metis, SMAC, TPE).
    • Neural Architecture Search (NAS): Supports Multi-trial strategies (Grid Search, Policy Based RL, Random, Regularized Evolution, TPE) and One-shot strategies (DARTS, ENAS, FBNet, ProxylessNAS, SPOS).
    • Model Compression: Includes Pruning (Level, L1 Norm, Taylor FO Weight, Movement, AGP, Auto Compress) and Quantization (Naive, QAT, LSQ, Observer, DoReFa, BNN).

    NNI supports major frameworks like PyTorch, TensorFlow, Scikit-learn, XGBoost, LightGBM, MXNet, and Caffe2.

  3. Overview of NNI Model Compression in version 3.0

    master

    Starting from version 3.0, NNI features a redesigned model compression framework that integrates pruning, quantization, and distillation. The framework allows for granular control over the compression process through several configuration types:

    • Compression granularity configuration: Control how compression is applied at different levels of the model.
    • Input/output compression configuration: Define compression parameters for model inputs and outputs.
    • Custom module compression: Apply specific compression logic to individual modules.

    For pruning, NNI uses a graph analysis scheme based on torch.fx. This enables support for various op types of sparsity propagation, custom special op sparsity propagation methods, and replacement logic, which improves the robustness of model acceleration.

  4. Hyperparameter Optimization (HPO) Overview

    master

    Hyperparameter Optimization (HPO) is a core capability of NNI. Instead of using a naive approach like Grid Search—which evaluates every possible combination of hyperparameters and consumes massive computational resources—NNI uses intelligent algorithms to find optimal hyperparameter combinations more efficiently.

    NNI addresses three main needs in HPO:

    1. Finding optimal combinations with fewer trials using advanced Tuners.
    2. Scaling training across distributed platforms using Training Services.
    3. Monitoring experiments via a Web Portal.

    To get started, you can follow specific tutorials for your preferred framework:

  5. Supported AI Frameworks and Libraries

    master

    NNI supports hyperparameter tuning and neural network search for any AI framework or library that supports Python models (version >= 3.6) via its built-in Python API.

    Supported AI Frameworks:

    • PyTorch
    • TensorFlow
    • Keras
    • MXNet
    • Caffe2
    • CNTK (Python)
    • Spark MLlib
    • Chainer
    • Theano

    Supported Libraries: NNI supports all Python-based libraries, including common machine learning libraries and GBDT (Gradient Boosting Decision Tree) algorithms:

    • Scikit-learn
    • XGBoost
    • CatBoost
    • LightGBM
  6. Hyperparameter Optimization (HPO) in NNI

    master

    NNI provides an automated Hyperparameter Optimization (HPO) framework to find the optimal set of hyperparameters for machine learning algorithms. Instead of using naive brute-force methods like grid search, NNI uses tuners to intelligently decide the order of hyperparameter evaluations based on historical results, significantly reducing the number of iterations required to find optimal values.

    Key components of the NNI HPO workflow include:

    • Tuners: Algorithms (e.g., Random Search, TPE, SMAC, PPO) that predict where the best hyperparameters are likely to be located.
    • Training Platforms: Support for running experiments locally or on distributed platforms like SSH servers, Kubernetes, and AzureML.
    • Web Portal: A UI to monitor training progress, visualize performance, and manage experiments.
    # Example of a naive (brute-force) HPO process that NNI automates more efficiently
    best_hyperparameters = None
    best_accuracy = 0
    
    for learning_rate in [0.1, 0.01, 0.001, 0.0001]:
        for momentum in [i / 10 for i in range(10)]:
            for activation_type in ['relu', 'tanh', 'sigmoid']:
                model = build_model(activation_type)
                train_model(model, learning_rate, momentum)
                accuracy = evaluate_model(model)
    
                if accuracy > best_accuracy:
                    best_accuracy = accuracy
                    best_hyperparameters = (learning_rate, momentum, activation_type)
    
    print('Best hyperparameters:', best_hyperparameters)
  7. Key Features of NNI NAS (Retiarii)

    master

    The NNI NAS framework, powered by Retiarii, provides three primary capabilities:

    • Search Space Construction: Simple APIs to build complex search spaces easily.
    • Exploration Strategies: Implementation of State-of-the-Art (SOTA) NAS algorithms with a unified interface.
    • Scalable Experiment Backends: Support for experiment backends to scale NAS trials on large-scale AI platforms.
  8. Supported Training Services in NNI

    master

    NNI supports a variety of training services to dispatch trials across different environments, from local machines to cloud platforms. Users can configure NNI to run experiments on:

    • Local: The entire experiment runs on a single local machine.
    • Remote: Trials are dispatched to configured SSH servers.
    • OpenPAI: Running trials on the OpenPAI DNN model training platform (Kubernetes-based).
    • Kubeflow: Running trials with the Kubeflow DNN model training framework (Kubernetes-based).
    • AdaptDL: Running trials on the AdaptDL elastic DNN model training platform.
    • FrameworkController: Running trials with the FrameworkController on Kubernetes.
    • AML: Running trials on the Azure Machine Learning (AML) cloud service.
    • PAI-DLC: Running trials on PAI-DLC (deep learning containers based on Alibaba ACK).
    • Hybrid: Jointly using multiple training services simultaneously.

    NNI is designed to be extensible, allowing users to customize new training services for specific resources or platforms.

  9. Compare HPO algorithms in NNI

    master

    NNI supports various Hyperparameter Optimization (HPO) algorithms including:

    • Random Search
    • Grid Search
    • Evolution
    • Anneal
    • Metis (Note: High time complexity $O(n^3)$ in Gaussian Process)
    • TPE
    • SMAC
    • BOHB
    • HyperBand
    • GP (Gaussian Process)

    When comparing algorithms, performance is typically measured by the 'Best loss' or 'Best IOPS' achieved within a specified number of trials or time limit. For example, in an AutoGBDT task, SMAC achieved a best loss of 0.408386, while in a RocksDB 'fillrandom' benchmark, SMAC achieved a best IOPS of 491136.

  10. Explore NNI's core capabilities

    master

    NNI is designed for several automated machine learning (AutoML) tasks:

    • Hyperparameter Tuning (HPO): Uses built-in Tuners (algorithms to pick parameters) and Assessors (algorithms for early stopping) to optimize model performance.
    • Neural Architecture Search (NAS):
      • General NAS Framework: Allows specifying candidate operations (e.g., separable conv, dilated conv) and skip connections.
      • One-shot NAS: Supports algorithms like ENAS and DARTS via the NNI Trial SDK. These can be run directly in your code without starting a full NNI experiment.
      • Classic Mode: Each architecture is treated as an independent trial job within a standard NNI experiment.
    • Model Compression: Provides pruning and quantization algorithms via the NNI Trial SDK. These can be used directly in trial code without a formal NNI experiment.
    • Automatic Feature Engineering: Provides algorithms to find optimal features. Like NAS and Compression, these are available via the NNI Trial SDK for direct use in trial code.
  11. Automatic System Tuning with NNI

    master

    NNI can automate the tuning of system configurations (e.g., databases, tensor operator implementations) to adapt to specific hardware or workloads. This replaces manual tuning, which requires deep hardware expertise.

    Typical use cases include:

    • SPTAG (Space Partition Tree And Graph): Automatic tuning of SPTAG configurations.
    • RocksDB: Tuning the performance of the RocksDB storage engine.
    • Tensor Operators: Automatically tuning the performance of tensor operators.
  12. Explore related Microsoft Research projects

    master

    NNI is part of a broader ecosystem of open-source AI and machine learning tools from Microsoft Research (MSR). Related projects include:

    • OpenPAI: An open-source platform for AI model training and resource management (supports on-premise, cloud, and hybrid environments).
    • FrameworkController: A general-purpose Kubernetes Pod Controller for orchestrating applications on Kubernetes.
    • MMdnn: A cross-framework solution to convert, visualize, and diagnose deep neural network models.
    • SPTAG: A library for large-scale vector approximate nearest neighbor search.
    • nn-Meter: An inference latency predictor for DNN models on diverse edge devices.