Unverified Commit a911b856 authored by Yuge Zhang's avatar Yuge Zhang Committed by GitHub
Browse files

Resolve conflicts for #4760 (#4762)

parent 14d2966b
References
==================
.. toctree::
:maxdepth: 2
nnictl Commands <reference/nnictl>
Experiment Configuration <reference/experiment_config>
Experiment Configuration (legacy) <Tutorial/ExperimentConfig>
Search Space <Tutorial/SearchSpaceSpec>
NNI Annotation <Tutorial/AnnotationSpec>
SDK API References <sdk_reference>
Supported Framework Library <SupportedFramework_Library>
Launch from Python <Tutorial/HowToLaunchFromPython>
Shared Storage <Tutorial/HowToUseSharedStorage>
Tensorboard <Tutorial/Tensorboard>
Framework Related
=================
Pruner
------
.. autoclass:: nni.algorithms.compression.v2.pytorch.base.Pruner
:members:
PrunerModuleWrapper
-------------------
.. autoclass:: nni.algorithms.compression.v2.pytorch.base.PrunerModuleWrapper
BasicPruner
-----------
.. autoclass:: nni.algorithms.compression.v2.pytorch.pruning.basic_pruner.BasicPruner
:members:
DataCollector
-------------
.. autoclass:: nni.algorithms.compression.v2.pytorch.pruning.tools.DataCollector
:members:
MetricsCalculator
-----------------
.. autoclass:: nni.algorithms.compression.v2.pytorch.pruning.tools.MetricsCalculator
:members:
SparsityAllocator
-----------------
.. autoclass:: nni.algorithms.compression.v2.pytorch.pruning.tools.SparsityAllocator
:members:
BasePruningScheduler
--------------------
.. autoclass:: nni.algorithms.compression.v2.pytorch.base.BasePruningScheduler
:members:
TaskGenerator
-------------
.. autoclass:: nni.algorithms.compression.v2.pytorch.pruning.tools.TaskGenerator
:members:
Quantizer
---------
.. autoclass:: nni.compression.pytorch.compressor.Quantizer
:members:
QuantizerModuleWrapper
----------------------
.. autoclass:: nni.compression.pytorch.compressor.QuantizerModuleWrapper
:members:
QuantGrad
---------
.. autoclass:: nni.compression.pytorch.compressor.QuantGrad
:members:
Pruner
======
Basic Pruner
------------
.. _level-pruner:
Level Pruner
^^^^^^^^^^^^
.. autoclass:: nni.compression.pytorch.pruning.LevelPruner
.. _l1-norm-pruner:
L1 Norm Pruner
^^^^^^^^^^^^^^
.. autoclass:: nni.compression.pytorch.pruning.L1NormPruner
.. _l2-norm-pruner:
L2 Norm Pruner
^^^^^^^^^^^^^^
.. autoclass:: nni.compression.pytorch.pruning.L2NormPruner
.. _fpgm-pruner:
FPGM Pruner
^^^^^^^^^^^
.. autoclass:: nni.compression.pytorch.pruning.FPGMPruner
.. _slim-pruner:
Slim Pruner
^^^^^^^^^^^
.. autoclass:: nni.compression.pytorch.pruning.SlimPruner
.. _activation-apoz-rank-pruner:
Activation APoZ Rank Pruner
^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autoclass:: nni.compression.pytorch.pruning.ActivationAPoZRankPruner
.. _activation-mean-rank-pruner:
Activation Mean Rank Pruner
^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autoclass:: nni.compression.pytorch.pruning.ActivationMeanRankPruner
.. _taylor-fo-weight-pruner:
Taylor FO Weight Pruner
^^^^^^^^^^^^^^^^^^^^^^^
.. autoclass:: nni.compression.pytorch.pruning.TaylorFOWeightPruner
.. _admm-pruner:
ADMM Pruner
^^^^^^^^^^^
.. autoclass:: nni.compression.pytorch.pruning.ADMMPruner
Scheduled Pruners
-----------------
.. _linear-pruner:
Linear Pruner
^^^^^^^^^^^^^
.. autoclass:: nni.compression.pytorch.pruning.LinearPruner
.. _agp-pruner:
AGP Pruner
^^^^^^^^^^
.. autoclass:: nni.compression.pytorch.pruning.AGPPruner
.. _lottery-ticket-pruner:
Lottery Ticket Pruner
^^^^^^^^^^^^^^^^^^^^^
.. autoclass:: nni.compression.pytorch.pruning.LotteryTicketPruner
.. _simulated-annealing-pruner:
Simulated Annealing Pruner
^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autoclass:: nni.compression.pytorch.pruning.SimulatedAnnealingPruner
.. _auto-compress-pruner:
Auto Compress Pruner
^^^^^^^^^^^^^^^^^^^^
.. autoclass:: nni.compression.pytorch.pruning.AutoCompressPruner
.. _amc-pruner:
AMC Pruner
^^^^^^^^^^
.. autoclass:: nni.compression.pytorch.pruning.AMCPruner
Other Pruner
------------
.. _movement-pruner:
Movement Pruner
^^^^^^^^^^^^^^^
.. autoclass:: nni.compression.pytorch.pruning.MovementPruner
\ No newline at end of file
Pruning Speedup
===============
.. autoclass:: nni.compression.pytorch.speedup.ModelSpeedup
:members:
Quantization Speedup
====================
.. autoclass:: nni.compression.pytorch.quantization_speedup.ModelSpeedupTensorRT
:members:
Quantizer
=========
.. _naive-quantizer:
Naive Quantizer
^^^^^^^^^^^^^^^
.. autoclass:: nni.algorithms.compression.pytorch.quantization.NaiveQuantizer
.. _qat-quantizer:
QAT Quantizer
^^^^^^^^^^^^^
.. autoclass:: nni.algorithms.compression.pytorch.quantization.QAT_Quantizer
.. _dorefa-quantizer:
DoReFa Quantizer
^^^^^^^^^^^^^^^^
.. autoclass:: nni.algorithms.compression.pytorch.quantization.DoReFaQuantizer
.. _bnn-quantizer:
BNN Quantizer
^^^^^^^^^^^^^
.. autoclass:: nni.algorithms.compression.pytorch.quantization.BNNQuantizer
.. _lsq-quantizer:
LSQ Quantizer
^^^^^^^^^^^^^
.. autoclass:: nni.algorithms.compression.pytorch.quantization.LsqQuantizer
.. _observer-quantizer:
Observer Quantizer
^^^^^^^^^^^^^^^^^^
.. autoclass:: nni.algorithms.compression.pytorch.quantization.ObserverQuantizer
Compression API Reference
=========================
.. toctree::
:maxdepth: 1
Pruner <pruner>
Quantizer <quantizer>
Pruning Speedup <pruning_speedup>
Quantization Speedup <quantization_speedup>
Compression Utilities <utils>
Framework Related <framework>
Compression Utilities
=====================
SensitivityAnalysis
-------------------
.. autoclass:: nni.compression.pytorch.utils.SensitivityAnalysis
:members:
ChannelDependency
-----------------
.. autoclass:: nni.compression.pytorch.utils.ChannelDependency
:members:
GroupDependency
---------------
.. autoclass:: nni.compression.pytorch.utils.GroupDependency
:members:
ChannelMaskConflict
-------------------
.. autoclass:: nni.compression.pytorch.utils.ChannelMaskConflict
:members:
GroupMaskConflict
-----------------
.. autoclass:: nni.compression.pytorch.utils.GroupMaskConflict
:members:
count_flops_params
------------------
.. autofunction:: nni.compression.pytorch.utils.count_flops_params
compute_sparsity
----------------
.. autofunction:: nni.algorithms.compression.v2.pytorch.utils.pruning.compute_sparsity
Experiment API Reference
========================
.. autoclass:: nni.experiment.Experiment
:members:
......@@ -20,11 +20,6 @@ A config file is needed when creating an experiment. This document describes the
4. Setting a field to ``None`` or ``null`` is equivalent to not setting the field.
.. contents:: Contents
:local:
:depth: 3
Examples
========
......@@ -120,13 +115,13 @@ ExperimentConfig
* - searchSpaceFile
- ``str``, optional
- Path_ to the JSON file containing the search space.
Search space format is determined by tuner. The common format for built-in tuners is documented `here <../Tutorial/SearchSpaceSpec.rst>`__.
Search space format is determined by tuner. The common format for built-in tuners is documented :doc:`here </hpo/search_space>`.
Mutually exclusive to ``searchSpace``.
* - searchSpace
- ``JSON``, optional
- Search space object.
The format is determined by tuner. Common format for built-in tuners is documented `here <../Tutorial/SearchSpaceSpec.rst>`__.
The format is determined by tuner. Common format for built-in tuners is documented :doc:`here </hpo/search_space>`.
Note that ``None`` means "no such field" so empty search space should be written as ``{}``.
Mutually exclusive to ``searchSpaceFile``.
......@@ -151,7 +146,7 @@ ExperimentConfig
- ``int`` or ``None``, optional
- Default: None. This field might have slightly different meanings for various training services,
especially when set to ``0`` or ``None``.
See `training service's document <../training_services.rst>`__ for details.
See :doc:`training service's document </experiment/training_service/overview>` for details.
In local mode, setting the field to ``0`` will prevent trials from accessing GPU (by empty ``CUDA_VISIBLE_DEVICES``).
And when set to ``None``, trials will be created and scheduled as if they did not use GPU,
......@@ -183,7 +178,7 @@ ExperimentConfig
* - useAnnotation
- ``bool``, optional
- Default: ``False``. Enable `annotation <../Tutorial/AnnotationSpec.rst>`__.
- Default: ``False``. Enable :doc:`annotation </hpo/nni_annotation>`.
When using annotation, ``searchSpace`` and ``searchSpaceFile`` should not be specified manually.
* - debug
......@@ -215,25 +210,25 @@ ExperimentConfig
* - tuner
- ``AlgorithmConfig``, optional
- Specify the tuner.
The built-in tuners can be found `here <../builtin_tuner.rst>`__ and you can follow `this tutorial <../Tuner/CustomizeTuner.rst>`__ to customize a new tuner.
The built-in tuners can be found :doc:`here </hpo/tuners>` and you can follow :doc:`this tutorial </hpo/custom_algorithm>` to customize a new tuner.
* - assessor
- ``AlgorithmConfig``, optional
- Specify the assessor.
The built-in assessors can be found `here <../builtin_assessor.rst>`__ and you can follow `this tutorial <../Assessor/CustomizeAssessor.rst>`__ to customize a new assessor.
The built-in assessors can be found :doc:`here </hpo/assessors>` and you can follow :doc:`this tutorial </hpo/custom_algorithm>` to customize a new assessor.
* - advisor
- ``AlgorithmConfig``, optional
- Specify the advisor.
NNI provides two built-in advisors: `BOHB <../Tuner/BohbAdvisor.rst>`__ and `Hyperband <../Tuner/HyperbandAdvisor.rst>`__, and you can follow `this tutorial <../Tuner/CustomizeAdvisor.rst>`__ to customize a new advisor.
NNI provides two built-in advisors: :class:`BOHB <nni.algorithms.hpo.bohb_advisor.BOHB>` and :class:`Hyperband <nni.algorithms.hpo.hyperband_advisor.Hyperband>`.
* - trainingService
- ``TrainingServiceConfig``
- Specify the `training service <../TrainingService/Overview.rst>`__.
- Specify the :doc:`training service </experiment/training_service/overview>`.
* - sharedStorage
- ``SharedStorageConfig``, optional
- Configure the shared storage, detailed usage can be found `here <../Tutorial/HowToUseSharedStorage.rst>`__.
- Configure the shared storage, detailed usage can be found :doc:`here </experiment/training_service/shared_storage>`.
AlgorithmConfig
^^^^^^^^^^^^^^^
......@@ -242,9 +237,9 @@ AlgorithmConfig
For customized algorithms, there are two ways to describe them:
1. `Register the algorithm <../Tutorial/InstallCustomizedAlgos.rst>`__ to use it like built-in. (preferred)
1. :doc:`Register the algorithm </hpo/custom_algorithm_installation>` to use it like built-in. (preferred)
2. Specify code directory and class name directly.
2. Specify code directory and class name directly.
.. list-table::
:widths: 10 10 80
......@@ -286,13 +281,15 @@ One of the following:
- `AmlConfig`_
- `DlcConfig`_
- `HybridConfig`_
- :doc:`FrameworkControllerConfig </experiment/training_service/frameworkcontroller>`
- :doc:`KubeflowConfig </experiment/training_service/kubeflow>`
For `Kubeflow <../TrainingService/KubeflowMode.rst>`_, `FrameworkController <../TrainingService/FrameworkControllerMode.rst>`_, and `AdaptDL <../TrainingService/AdaptDLMode.rst>`_ training platforms, it is suggested to use `v1 config schema <../Tutorial/ExperimentConfig.rst>`_ for now.
.. _reference-local-config-label:
LocalConfig
-----------
Detailed usage can be found `here <../TrainingService/LocalMode.rst>`__.
Introduction of the corresponding local training service can be found :doc:`/experiment/training_service/local`.
.. list-table::
:widths: 10 10 80
......@@ -330,10 +327,12 @@ Detailed usage can be found `here <../TrainingService/LocalMode.rst>`__.
If ``trialGpuNumber`` is less than the length of this value, only a subset will be visible to each trial.
This will be used as ``CUDA_VISIBLE_DEVICES`` environment variable.
.. _reference-remote-config-label:
RemoteConfig
------------
Detailed usage can be found `here <../TrainingService/RemoteMachineMode.rst>`__.
Detailed usage can be found :doc:`/experiment/training_service/remote`.
.. list-table::
:widths: 10 10 80
......@@ -353,7 +352,7 @@ Detailed usage can be found `here <../TrainingService/RemoteMachineMode.rst>`__.
* - reuseMode
- ``bool``, optional
- Default: ``True``. Enable `reuse mode <../TrainingService/Overview.rst#training-service-under-reuse-mode>`__.
- Default: ``True``. Enable :ref:`reuse mode <training-service-reuse>`.
RemoteMachineConfig
"""""""""""""""""""
......@@ -433,7 +432,7 @@ RemoteMachineConfig
OpenpaiConfig
-------------
Detailed usage can be found `here <../TrainingService/PaiMode.rst>`__.
Detailed usage can be found :doc:`here </experiment/training_service/openpai>`.
.. list-table::
:widths: 10 10 80
......@@ -491,7 +490,7 @@ Detailed usage can be found `here <../TrainingService/PaiMode.rst>`__.
* - reuseMode
- ``bool``, optional
- Default: ``True``. Enable `reuse mode <../TrainingService/Overview.rst#training-service-under-reuse-mode>`__.
- Default: ``True``. Enable :ref:`reuse mode <training-service-reuse>`.
* - openpaiConfig
- ``JSON``, optional
......@@ -505,7 +504,7 @@ Detailed usage can be found `here <../TrainingService/PaiMode.rst>`__.
AmlConfig
---------
Detailed usage can be found `here <../TrainingService/AMLMode.rst>`__.
Detailed usage can be found :doc:`here </experiment/training_service/aml>`.
.. list-table::
:widths: 10 10 80
......@@ -542,7 +541,7 @@ Detailed usage can be found `here <../TrainingService/AMLMode.rst>`__.
DlcConfig
---------
Detailed usage can be found `here <../TrainingService/DlcMode.rst>`__.
Detailed usage can be found :doc:`here </experiment/training_service/paidlc>`.
.. list-table::
:widths: 10 10 80
......@@ -607,14 +606,16 @@ Detailed usage can be found `here <../TrainingService/DlcMode.rst>`__.
HybridConfig
------------
Currently only support `LocalConfig`_, `RemoteConfig`_, `OpenpaiConfig`_ and `AmlConfig`_ . Detailed usage can be found `here <../TrainingService/HybridMode.rst>`__.
Currently only support `LocalConfig`_, `RemoteConfig`_, `OpenpaiConfig`_ and `AmlConfig`_ . Detailed usage can be found :doc:`here </experiment/training_service/hybrid>`.
.. _reference-sharedstorage-config-label:
SharedStorageConfig
^^^^^^^^^^^^^^^^^^^
Detailed usage can be found `here <../Tutorial/HowToUseSharedStorage.rst>`__.
Detailed usage can be found :doc:`here </experiment/training_service/shared_storage>`.
nfsConfig
NfsConfig
---------
.. list-table::
......@@ -653,7 +654,7 @@ nfsConfig
- ``str``
- Exported directory of NFS server, detailed `here <https://www.ibm.com/docs/en/aix/7.2?topic=system-nfs-exporting-mounting>`_.
azureBlobConfig
AzureBlobConfig
---------------
.. list-table::
......
HPO API Reference
=================
Trial APIs
----------
.. autofunction:: nni.get_experiment_id
.. autofunction:: nni.get_next_parameter
.. autofunction:: nni.get_sequence_id
.. autofunction:: nni.get_trial_id
.. autofunction:: nni.report_final_result
.. autofunction:: nni.report_intermediate_result
Tuners
------
Batch Tuner
^^^^^^^^^^^
.. autoclass:: nni.algorithms.hpo.batch_tuner.BatchTuner
BOHB Tuner
^^^^^^^^^^
.. autoclass:: nni.algorithms.hpo.bohb_advisor.BOHB
DNGO Tuner
^^^^^^^^^^
.. autoclass:: nni.algorithms.hpo.dngo_tuner.DNGOTuner
Evolution Tuner
^^^^^^^^^^^^^^^
.. autoclass:: nni.algorithms.hpo.evolution_tuner.EvolutionTuner
GP Tuner
^^^^^^^^
.. autoclass:: nni.algorithms.hpo.gp_tuner.GPTuner
Grid Search Tuner
^^^^^^^^^^^^^^^^^
.. autoclass:: nni.algorithms.hpo.gridsearch_tuner.GridSearchTuner
Hyperband Tuner
^^^^^^^^^^^^^^^
.. autoclass:: nni.algorithms.hpo.hyperband_advisor.Hyperband
Hyperopt Tuner
^^^^^^^^^^^^^^
.. autoclass:: nni.algorithms.hpo.hyperopt_tuner.HyperoptTuner
Metis Tuner
^^^^^^^^^^^
.. autoclass:: nni.algorithms.hpo.metis_tuner.MetisTuner
PBT Tuner
^^^^^^^^^
.. autoclass:: nni.algorithms.hpo.pbt_tuner.PBTTuner
PPO Tuner
^^^^^^^^^
.. autoclass:: nni.algorithms.hpo.ppo_tuner.PPOTuner
Random Tuner
^^^^^^^^^^^^
.. autoclass:: nni.algorithms.hpo.random_tuner.RandomTuner
SMAC Tuner
^^^^^^^^^^
.. autoclass:: nni.algorithms.hpo.smac_tuner.SMACTuner
TPE Tuner
^^^^^^^^^
.. autoclass:: nni.algorithms.hpo.tpe_tuner.TpeTuner
.. autoclass:: nni.algorithms.hpo.tpe_tuner.TpeArguments
Assessors
---------
Curve Fitting Assessor
^^^^^^^^^^^^^^^^^^^^^^
.. autoclass:: nni.algorithms.hpo.curvefitting_assessor.CurvefittingAssessor
Median Stop Assessor
^^^^^^^^^^^^^^^^^^^^
.. autoclass:: nni.algorithms.hpo.medianstop_assessor.MedianstopAssessor
Customization
-------------
.. autoclass:: nni.assessor.AssessResult
:members:
.. autoclass:: nni.assessor.Assessor
:members:
.. autoclass:: nni.tuner.Tuner
:members:
Evaluator
=========
FunctionalEvaluator
-------------------
.. autoclass:: nni.retiarii.evaluator.FunctionalEvaluator
:members:
Classification
--------------
.. autoclass:: nni.retiarii.evaluator.pytorch.Classification
:members:
Regression
----------
.. autoclass:: nni.retiarii.evaluator.pytorch.Regression
:members:
Utilities
---------
.. autoclass:: nni.retiarii.evaluator.pytorch.Trainer
.. autoclass:: nni.retiarii.evaluator.pytorch.DataLoader
Customization
-------------
.. autoclass:: nni.retiarii.evaluator.pytorch.Lightning
.. autoclass:: nni.retiarii.evaluator.pytorch.LightningModule
Cross-graph Optimization (experimental)
---------------------------------------
.. autoclass:: nni.retiarii.evaluator.pytorch.cgo.evaluator.MultiModelSupervisedLearningModule
:members:
.. autoclass:: nni.retiarii.evaluator.pytorch.cgo.evaluator.Classification
:members:
.. autoclass:: nni.retiarii.evaluator.pytorch.cgo.evaluator.Regression
:members:
Uncategorized Modules
=====================
Experiment
----------
.. autoclass:: nni.retiarii.experiment.pytorch.RetiariiExeConfig
:members:
.. autoclass:: nni.retiarii.experiment.pytorch.RetiariiExperiment
:members:
NAS Benchmarks
--------------
.. _nas-bench-101-reference:
NAS-Bench-101
^^^^^^^^^^^^^
.. automodule:: nni.nas.benchmarks.nasbench101
:members:
:imported-members:
.. _nas-bench-201-reference:
NAS-Bench-201
^^^^^^^^^^^^^
.. automodule:: nni.nas.benchmarks.nasbench201
:members:
:imported-members:
.. _nds-reference:
NDS
^^^
.. automodule:: nni.nas.benchmarks.nds
:members:
:imported-members:
Retrain (Architecture Evaluation)
---------------------------------
.. autofunction:: nni.retiarii.fixed_arch
Utilities
---------
.. autofunction:: nni.retiarii.basic_unit
.. autofunction:: nni.retiarii.model_wrapper
.. automodule:: nni.retiarii.nn.pytorch.mutation_utils
:imported-members:
:members:
.. automodule:: nni.retiarii.utils
:members:
Search Space
============
.. _mutation-primitives:
Mutation Pritimives
-------------------
LayerChoice
^^^^^^^^^^^
.. autoclass:: nni.retiarii.nn.pytorch.LayerChoice
:members:
InputChoice
^^^^^^^^^^^
.. autoclass:: nni.retiarii.nn.pytorch.InputChoice
:members:
.. autoclass:: nni.retiarii.nn.pytorch.ChosenInputs
:members:
ValueChoice
^^^^^^^^^^^
.. autoclass:: nni.retiarii.nn.pytorch.ValueChoice
:members:
:inherited-members: Module
ModelParameterChoice
^^^^^^^^^^^^^^^^^^^^
.. autoclass:: nni.retiarii.nn.pytorch.ModelParameterChoice
:members:
:inherited-members: Module
Repeat
^^^^^^
.. autoclass:: nni.retiarii.nn.pytorch.Repeat
:members:
Cell
^^^^
.. autoclass:: nni.retiarii.nn.pytorch.Cell
:members:
NasBench101Cell
^^^^^^^^^^^^^^^
.. autoclass:: nni.retiarii.nn.pytorch.NasBench101Cell
:members:
NasBench201Cell
^^^^^^^^^^^^^^^
.. autoclass:: nni.retiarii.nn.pytorch.NasBench201Cell
:members:
.. _hyper-modules:
Hyper-module Library (experimental)
-----------------------------------
AutoActivation
^^^^^^^^^^^^^^
.. autoclass:: nni.retiarii.nn.pytorch.AutoActivation
:members:
Mutators (advanced)
-------------------
Mutator
^^^^^^^
.. autoclass:: nni.retiarii.Mutator
:members:
.. autoclass:: nni.retiarii.Sampler
:members:
.. autoclass:: nni.retiarii.InvalidMutation
:members:
Placeholder
^^^^^^^^^^^
.. autoclass:: nni.retiarii.nn.pytorch.Placeholder
:members:
Graph
^^^^^
.. autoclass:: nni.retiarii.Model
:members:
.. autoclass:: nni.retiarii.Graph
:members:
.. autoclass:: nni.retiarii.Node
:members:
.. autoclass:: nni.retiarii.Edge
:members:
.. autoclass:: nni.retiarii.Operation
:members:
Strategy
========
.. _multi-trial-nas-reference:
Multi-trial Strategy
--------------------
Random
^^^^^^
.. autoclass:: nni.retiarii.strategy.Random
:members:
GridSearch
^^^^^^^^^^
.. autoclass:: nni.retiarii.strategy.GridSearch
:members:
RegularizedEvolution
^^^^^^^^^^^^^^^^^^^^
.. autoclass:: nni.retiarii.strategy.RegularizedEvolution
:members:
TPE
^^^
.. autoclass:: nni.retiarii.strategy.TPE
:members:
PolicyBasedRL
^^^^^^^^^^^^^
.. autoclass:: nni.retiarii.strategy.PolicyBasedRL
:members:
.. _one-shot-strategy-reference:
One-shot Strategy
-----------------
.. _darts-strategy:
DARTS
^^^^^
The paper `DARTS: Differentiable Architecture Search <https://arxiv.org/abs/1806.09055>`__ addresses the scalability challenge of architecture search by formulating the task in a differentiable manner. Their method is based on the continuous relaxation of the architecture representation, allowing efficient search of the architecture using gradient descent.
Authors' code optimizes the network weights and architecture weights alternatively in mini-batches. They further explore the possibility that uses second order optimization (unroll) instead of first order, to improve the performance.
Implementation on NNI is based on the `official implementation <https://github.com/quark0/darts>`__ and a `popular 3rd-party repo <https://github.com/khanrc/pt.darts>`__. DARTS on NNI is designed to be general for arbitrary search space. A CNN search space tailored for CIFAR10, same as the original paper, is implemented as a use case of DARTS.
.. autoclass:: nni.retiarii.oneshot.pytorch.DartsTrainer
Reproduction Results
""""""""""""""""""""
The above-mentioned example is meant to reproduce the results in the paper, we do experiments with first and second order optimization. Due to the time limit, we retrain *only the best architecture* derived from the search phase and we repeat the experiment *only once*. Our results is currently on par with the results reported in paper. We will add more results later when ready.
.. list-table::
:header-rows: 1
:widths: auto
* -
- In paper
- Reproduction
* - First order (CIFAR10)
- 3.00 +/- 0.14
- 2.78
* - Second order (CIFAR10)
- 2.76 +/- 0.09
- 2.80
Examples
""""""""
:githublink:`Example code <examples/nas/oneshot/darts>`
.. code-block:: bash
# In case NNI code is not cloned. If the code is cloned already, ignore this line and enter code folder.
git clone https://github.com/Microsoft/nni.git
# search the best architecture
cd examples/nas/oneshot/darts
python3 search.py
# train the best architecture
python3 retrain.py --arc-checkpoint ./checkpoints/epoch_49.json
Limitations
"""""""""""
* DARTS doesn't support DataParallel and needs to be customized in order to support DistributedDataParallel.
.. _enas-strategy:
ENAS
^^^^
The paper `Efficient Neural Architecture Search via Parameter Sharing <https://arxiv.org/abs/1802.03268>`__ uses parameter sharing between child models to accelerate the NAS process. In ENAS, a controller learns to discover neural network architectures by searching for an optimal subgraph within a large computational graph. The controller is trained with policy gradient to select a subgraph that maximizes the expected reward on the validation set. Meanwhile the model corresponding to the selected subgraph is trained to minimize a canonical cross entropy loss.
Implementation on NNI is based on the `official implementation in Tensorflow <https://github.com/melodyguan/enas>`__, including a general-purpose Reinforcement-learning controller and a trainer that trains target network and this controller alternatively. Following paper, we have also implemented macro and micro search space on CIFAR10 to demonstrate how to use these trainers. Since code to train from scratch on NNI is not ready yet, reproduction results are currently unavailable.
.. autoclass:: nni.retiarii.oneshot.pytorch.EnasTrainer
Examples
""""""""
:githublink:`Example code <examples/nas/oneshot/enas>`
.. code-block:: bash
# In case NNI code is not cloned. If the code is cloned already, ignore this line and enter code folder.
git clone https://github.com/Microsoft/nni.git
# search the best architecture
cd examples/nas/oneshot/enas
# search in macro search space
python3 search.py --search-for macro
# search in micro search space
python3 search.py --search-for micro
# view more options for search
python3 search.py -h
.. _fbnet-strategy:
FBNet
^^^^^
.. note:: This one-shot NAS is still implemented under NNI NAS 1.0, and will `be migrated to Retiarii framework in near future <https://github.com/microsoft/nni/issues/3814>`__.
For the mobile application of facial landmark, based on the basic architecture of PFLD model, we have applied the FBNet (Block-wise DNAS) to design an concise model with the trade-off between latency and accuracy. References are listed as below:
* `FBNet: Hardware-Aware Efficient ConvNet Design via Differentiable Neural Architecture Search <https://arxiv.org/abs/1812.03443>`__
* `PFLD: A Practical Facial Landmark Detector <https://arxiv.org/abs/1902.10859>`__
FBNet is a block-wise differentiable NAS method (Block-wise DNAS), where the best candidate building blocks can be chosen by using Gumbel Softmax random sampling and differentiable training. At each layer (or stage) to be searched, the diverse candidate blocks are side by side planned (just like the effectiveness of structural re-parameterization), leading to sufficient pre-training of the supernet. The pre-trained supernet is further sampled for finetuning of the subnet, to achieve better performance.
.. image:: ../../../img/fbnet.png
:width: 800
:align: center
PFLD is a lightweight facial landmark model for realtime application. The architecture of PLFD is firstly simplified for acceleration, by using the stem block of PeleeNet, average pooling with depthwise convolution and eSE module.
To achieve better trade-off between latency and accuracy, the FBNet is further applied on the simplified PFLD for searching the best block at each specific layer. The search space is based on the FBNet space, and optimized for mobile deployment by using the average pooling with depthwise convolution and eSE module etc.
Experiments
"""""""""""
To verify the effectiveness of FBNet applied on PFLD, we choose the open source dataset with 106 landmark points as the benchmark:
* `Grand Challenge of 106-Point Facial Landmark Localization <https://arxiv.org/abs/1905.03469>`__
The baseline model is denoted as MobileNet-V3 PFLD (`Reference baseline <https://github.com/Hsintao/pfld_106_face_landmarks>`__), and the searched model is denoted as Subnet. The experimental results are listed as below, where the latency is tested on Qualcomm 625 CPU (ARMv8):
.. list-table::
:header-rows: 1
:widths: auto
* - Model
- Size
- Latency
- Validation NME
* - MobileNet-V3 PFLD
- 1.01MB
- 10ms
- 6.22%
* - Subnet
- 693KB
- 1.60ms
- 5.58%
Example
"""""""
`Example code <https://github.com/microsoft/nni/tree/master/examples/nas/oneshot/pfld>`__
Please run the following scripts at the example directory.
The Python dependencies used here are listed as below:
.. code-block:: bash
numpy==1.18.5
opencv-python==4.5.1.48
torch==1.6.0
torchvision==0.7.0
onnx==1.8.1
onnx-simplifier==0.3.5
onnxruntime==1.7.0
To run the tutorial, follow the steps below:
1. **Data Preparation**: Firstly, you should download the dataset `106points dataset <https://drive.google.com/file/d/1I7QdnLxAlyG2Tq3L66QYzGhiBEoVfzKo/view?usp=sharing>`__ to the path ``./data/106points`` . The dataset includes the train-set and test-set:
.. code-block:: bash
./data/106points/train_data/imgs
./data/106points/train_data/list.txt
./data/106points/test_data/imgs
./data/106points/test_data/list.txt
2. **Search**: Based on the architecture of simplified PFLD, the setting of multi-stage search space and hyper-parameters for searching should be firstly configured to construct the supernet. For example,
.. code-block::
from lib.builder import search_space
from lib.ops import PRIMITIVES
from lib.supernet import PFLDInference, AuxiliaryNet
from nni.algorithms.nas.pytorch.fbnet import LookUpTable, NASConfig,
# configuration of hyper-parameters
# search_space defines the multi-stage search space
nas_config = NASConfig(
model_dir="./ckpt_save",
nas_lr=0.01,
mode="mul",
alpha=0.25,
beta=0.6,
search_space=search_space,
)
# lookup table to manage the information
lookup_table = LookUpTable(config=nas_config, primitives=PRIMITIVES)
# created supernet
pfld_backbone = PFLDInference(lookup_table)
After creation of the supernet with the specification of search space and hyper-parameters, we can run below command to start searching and training of the supernet:
.. code-block:: bash
python train.py --dev_id "0,1" --snapshot "./ckpt_save" --data_root "./data/106points"
The validation accuracy will be shown during training, and the model with best accuracy will be saved as ``./ckpt_save/supernet/checkpoint_best.pth``.
3. **Finetune**: After pre-training of the supernet, we can run below command to sample the subnet and conduct the finetuning:
.. code-block:: bash
python retrain.py --dev_id "0,1" --snapshot "./ckpt_save" --data_root "./data/106points" \
--supernet "./ckpt_save/supernet/checkpoint_best.pth"
The validation accuracy will be shown during training, and the model with best accuracy will be saved as ``./ckpt_save/subnet/checkpoint_best.pth``.
4. **Export**: After the finetuning of subnet, we can run below command to export the ONNX model:
.. code-block:: bash
python export.py --supernet "./ckpt_save/supernet/checkpoint_best.pth" \
--resume "./ckpt_save/subnet/checkpoint_best.pth"
ONNX model is saved as ``./output/subnet.onnx``, which can be further converted to the mobile inference engine by using `MNN <https://github.com/alibaba/MNN>`__ .
The checkpoints of pre-trained supernet and subnet are offered as below:
* `Supernet <https://drive.google.com/file/d/1TCuWKq8u4_BQ84BWbHSCZ45N3JGB9kFJ/view?usp=sharing>`__
* `Subnet <https://drive.google.com/file/d/160rkuwB7y7qlBZNM3W_T53cb6MQIYHIE/view?usp=sharing>`__
* `ONNX model <https://drive.google.com/file/d/1s-v-aOiMv0cqBspPVF3vSGujTbn_T_Uo/view?usp=sharing>`__
.. _spos-strategy:
SPOS
^^^^
Proposed in `Single Path One-Shot Neural Architecture Search with Uniform Sampling <https://arxiv.org/abs/1904.00420>`__ is a one-shot NAS method that addresses the difficulties in training One-Shot NAS models by constructing a simplified supernet trained with an uniform path sampling method, so that all underlying architectures (and their weights) get trained fully and equally. An evolutionary algorithm is then applied to efficiently search for the best-performing architectures without any fine tuning.
Implementation on NNI is based on `official repo <https://github.com/megvii-model/SinglePathOneShot>`__. We implement a trainer that trains the supernet and a evolution tuner that leverages the power of NNI framework that speeds up the evolutionary search phase.
.. autoclass:: nni.retiarii.oneshot.pytorch.SinglePathTrainer
Examples
""""""""
Here is a use case, which is the search space in paper. However, we applied latency limit instead of flops limit to perform the architecture search phase.
:githublink:`Example code <examples/nas/oneshot/spos>`
**Requirements:** Prepare ImageNet in the standard format (follow the script `here <https://gist.github.com/BIGBALLON/8a71d225eff18d88e469e6ea9b39cef4>`__). Linking it to ``data/imagenet`` will be more convenient. Download the checkpoint file from `here <https://1drv.ms/u/s!Am_mmG2-KsrnajesvSdfsq_cN48?e=aHVppN>`__ (maintained by `Megvii <https://github.com/megvii-model>`__) if you don't want to retrain the supernet. Put ``checkpoint-150000.pth.tar`` under ``data`` directory. After preparation, it's expected to have the following code structure:
.. code-block:: bash
spos
├── architecture_final.json
├── blocks.py
├── data
│ ├── imagenet
│ │ ├── train
│ │ └── val
│ └── checkpoint-150000.pth.tar
├── network.py
├── readme.md
├── supernet.py
├── evaluation.py
├── search.py
└── utils.py
Then follow the 3 steps:
1. **Train Supernet**:
.. code-block:: bash
python supernet.py
This will export the checkpoint to ``checkpoints`` directory, for the next step.
.. note:: The data loading used in the official repo is `slightly different from usual <https://github.com/megvii-model/SinglePathOneShot/issues/5>`__, as they use BGR tensor and keep the values between 0 and 255 intentionally to align with their own DL framework. The option ``--spos-preprocessing`` will simulate the behavior used originally and enable you to use the checkpoints pretrained.
2. **Evolution Search**: Single Path One-Shot leverages evolution algorithm to search for the best architecture. In the paper, the search module, which is responsible for testing the sampled architecture, recalculates all the batch norm for a subset of training images, and evaluates the architecture on the full validation set.
In this example, it will inherit the ``state_dict`` of supernet from `./data/checkpoint-150000.pth.tar`, and search the best architecture with the regularized evolution strategy. Search in the supernet with the following command
.. code-block:: bash
python search.py
NNI support a latency filter to filter unsatisfied model from search phase. Latency is predicted by Microsoft nn-Meter (https://github.com/microsoft/nn-Meter). To apply the latency filter, users could run search.py with additional arguments ``--latency-filter``. Here is an example:
.. code-block:: bash
python search.py --latency-filter cortexA76cpu_tflite21
Note that the latency filter is only supported for base execution engine.
The final architecture exported from every epoch of evolution can be found in ``trials`` under the working directory of your tuner, which, by default, is ``$HOME/nni-experiments/your_experiment_id/trials``.
3. **Train for Evaluation**:
.. code-block:: bash
python evaluation.py
By default, it will use ``architecture_final.json``. This architecture is provided by the official repo (converted into NNI format). You can use any architecture (e.g., the architecture found in step 2) with ``--fixed-arc`` option.
Known Limitations
"""""""""""""""""
* Block search only. Channel search is not supported yet.
Current Reproduction Results
""""""""""""""""""""""""""""
Reproduction is still undergoing. Due to the gap between official release and original paper, we compare our current results with official repo (our run) and paper.
* Evolution phase is almost aligned with official repo. Our evolution algorithm shows a converging trend and reaches ~65% accuracy at the end of search. Nevertheless, this result is not on par with paper. For details, please refer to `this issue <https://github.com/megvii-model/SinglePathOneShot/issues/6>`__.
* Retrain phase is not aligned. Our retraining code, which uses the architecture released by the authors, reaches 72.14% accuracy, still having a gap towards 73.61% by official release and 74.3% reported in original paper.
.. _proxylessnas-strategy:
ProxylessNAS
^^^^^^^^^^^^
The paper `ProxylessNAS: Direct Neural Architecture Search on Target Task and Hardware <https://arxiv.org/abs/1812.00332>`__ removes proxy, it directly learns the architectures for large-scale target tasks and target hardware platforms. They address high memory consumption issue of differentiable NAS and reduce the computational cost to the same level of regular training while still allowing a large candidate set. Please refer to the paper for the details.
.. autoclass:: nni.retiarii.oneshot.pytorch.ProxylessTrainer
To use ProxylessNAS training/searching approach, users need to specify search space in their model using :doc:`NNI NAS interface </nas/construct_space>`, e.g., ``LayerChoice``, ``InputChoice``. After defining and instantiating the model, the following work can be leaved to ProxylessNasTrainer by instantiating the trainer and passing the model to it.
.. code-block:: python
trainer = ProxylessTrainer(model,
loss=LabelSmoothingLoss(),
dataset=None,
optimizer=optimizer,
metrics=lambda output, target: accuracy(output, target, topk=(1, 5,)),
num_epochs=120,
log_frequency=10,
grad_reg_loss_type=args.grad_reg_loss_type,
grad_reg_loss_params=grad_reg_loss_params,
applied_hardware=args.applied_hardware, dummy_input=(1, 3, 224, 224),
ref_latency=args.reference_latency)
trainer.train()
trainer.export(args.arch_path)
The complete example code can be found :githublink:`here <examples/nas/oneshot/proxylessnas>`.
Implementation
""""""""""""""
The implementation on NNI is based on the `offical implementation <https://github.com/mit-han-lab/ProxylessNAS>`__. The official implementation supports two training approaches: gradient descent and RL based. In our current implementation on NNI, gradient descent training approach is supported. The complete support of ProxylessNAS is ongoing.
The official implementation supports different targeted hardware, including 'mobile', 'cpu', 'gpu8', 'flops'. In NNI repo, the hardware latency prediction is supported by `Microsoft nn-Meter <https://github.com/microsoft/nn-Meter>`__. nn-Meter is an accurate inference latency predictor for DNN models on diverse edge devices. nn-Meter support four hardwares up to now, including ``cortexA76cpu_tflite21``, ``adreno640gpu_tflite21``, ``adreno630gpu_tflite21``, and ``myriadvpu_openvino2019r2``. Users can find more information about nn-Meter on its website. More hardware will be supported in the future. Users could find more details about applying ``nn-Meter`` :doc:`here </nas/hardware_aware_nas>`.
Below we will describe implementation details. Like other one-shot NAS algorithms on NNI, ProxylessNAS is composed of two parts: *search space* and *training approach*. For users to flexibly define their own search space and use built-in ProxylessNAS training approach, please refer to :githublink:`example code <examples/nas/oneshot/proxylessnas>` for a reference.
.. image:: ../../../img/proxylessnas.png
:width: 450
:align: center
ProxylessNAS training approach is composed of ProxylessLayerChoice and ProxylessNasTrainer. ProxylessLayerChoice instantiates MixedOp for each mutable (i.e., LayerChoice), and manage architecture weights in MixedOp. **For DataParallel**, architecture weights should be included in user model. Specifically, in ProxylessNAS implementation, we add MixedOp to the corresponding mutable (i.e., LayerChoice) as a member variable. The ProxylessLayerChoice class also exposes two member functions, i.e., ``resample``, ``finalize_grad``, for the trainer to control the training of architecture weights.
Reproduction Results
""""""""""""""""""""
To reproduce the result, we first run the search, we found that though it runs many epochs the chosen architecture converges at the first several epochs. This is probably induced by hyper-parameters or the implementation, we are working on it.
Customization
-------------
Multi-trial
^^^^^^^^^^^
.. autoclass:: nni.retiarii.Sampler
:noindex:
:members:
.. autoclass:: nni.retiarii.strategy.BaseStrategy
:members:
.. automodule:: nni.retiarii.execution
:members:
:imported-members:
:undoc-members:
One-shot
^^^^^^^^
.. autoclass:: nni.retiarii.oneshot.BaseOneShotTrainer
:members:
.. autofunction:: nni.retiarii.oneshot.pytorch.utils.replace_layer_choice
.. autofunction:: nni.retiarii.oneshot.pytorch.utils.replace_input_choice
NAS API Reference
=================
.. toctree::
:maxdepth: 2
search_space
strategy
evaluator
Others <others>
nnictl
======
nnictl Commands
===============
.. argparse::
:module: nni.tools.nnictl.nnictl
......
Uncategorized Modules
=====================
nni.common.serializer
---------------------
.. automodule:: nni.common.serializer
:members:
nni.typehint
------------
.. automodule:: nni.typehint
:members:
Python API Reference
====================
.. toctree::
:maxdepth: 1
Hyperparameter Optimization <hpo>
Neural Architecture Search <nas/toctree>
Model Compression <compression/toctree>
Experiment <experiment>
Others <others>
.. 19ce4f2ee1d3c4f1be277ab09ba40092
参考
==================
.. toctree::
:maxdepth: 2
nnictl 命令 <reference/nnictl>
Experiment 配置 <reference/experiment_config>
Experiment 配置(遗产) <Tutorial/ExperimentConfig>
搜索空间<Tutorial/SearchSpaceSpec>
NNI Annotation<Tutorial/AnnotationSpec>
SDK API 参考 <sdk_reference>
支持的框架和库 <SupportedFramework_Library>
从 Python 发起实验 <Tutorial/HowToLaunchFromPython>
共享存储 <Tutorial/HowToUseSharedStorage>
Tensorboard <Tutorial/Tensorboard>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment