Skip to content

Commit

Permalink
Added mechanism to invoke nbsphinx to render html versions of example…
Browse files Browse the repository at this point in the history
… notebooks. Added links to the same from the user guide.

Signed-off-by: Abhi Khobare <[email protected]>
  • Loading branch information
quic-akhobare committed Oct 28, 2022
1 parent 5a8d30f commit 57554d6
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 81 deletions.
5 changes: 4 additions & 1 deletion Docs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ add_custom_target(doc
"${AIMET_LD_LIBRARY_PATH}"
"${AIMET_PYTHONPATH}"
"SW_VERSION=${SW_VERSION}"
sphinx-build -v -T -b html ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
sphinx-build -v -T -b html ${CMAKE_BINARY_DIR}/Docs_SOURCE ${CMAKE_CURRENT_BINARY_DIR})

add_dependencies(doc
copy_doc_source copy_examples)

add_custom_target(copy_doc_source
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_BINARY_DIR}/Docs_SOURCE)
6 changes: 5 additions & 1 deletion Docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ def setup(app):
'sphinx.ext.autodoc',
'sphinx_autodoc_typehints',
'sphinx.ext.autosectionlabel',
'sphinx.ext.ifconfig'
'sphinx.ext.ifconfig',
'nbsphinx'
# 'rinoh.frontend.sphinx'
]

Expand Down Expand Up @@ -216,3 +217,6 @@ def setup(app):

# -- Extension configuration -------------------------------------------------
autoclass_content = 'both'

nbsphinx_allow_errors = True
nbsphinx_execute = 'never'
4 changes: 4 additions & 0 deletions Docs/toplevelhidden.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

.. toctree::
:hidden:

104 changes: 54 additions & 50 deletions Docs/user_guide/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
AIMET Examples
==============

AIMET Examples provide reference code (in the form of *scripts* and *Jupyter Notebooks*) to learn how to load models,
apply AIMET quantization and compression features, fine tune and save your models. It is also a quick way to become
AIMET Examples provide reference code (in the form of *Jupyter Notebooks*) to learn how to
apply AIMET quantization and compression features. It is also a quick way to become
familiar with AIMET usage and APIs.

For more details on each of the features and APIs please refer:
Expand All @@ -17,44 +17,60 @@ Installation Instructions
=========================

- The dataloader, evaluator, and trainer utilized in the examples is for the ImageNet dataset.
To run the example, please download it from here: https://www.image-net.org/download.php
To run the example, please download the ImageNet dataset from here: https://www.image-net.org/download.php
- Install AIMET and its dependencies using the instructions in the Installation section'
- Clone the AIMET repo as follows to any location:
- Installing AIMET will also install these AIMET Examples

Examples for PyTorch Models
===========================

The following table has links to browsable versions of the notebooks for different features.


.. list-table:: Quantization Examples
:widths: 40 12 12
:header-rows: 1

* - Features
- PyTorch
- TensorFlow
* - Quantization-Aware Training (QAT)
- `Link <../Examples/torch/quantization/qat.ipynb>`_
- `Link <../Examples/tensorflow/quantization/qat.ipynb>`_
* - QAT with Range Learning
- `Link <../Examples/torch/quantization/qat_range_learning.ipynb>`_
- `Link <../Examples/tensorflow/quantization/qat_range_learning.ipynb>`_
* - Cross-Layer Equalization (CLE)
- `Link <../Examples/torch/quantization/cle_bc.ipynb>`_
- `Link <../Examples/tensorflow/quantization/cle_bc.ipynb>`_
* - Adaptive Rounding (AdaRound)
- `Link <../Examples/torch/quantization/adaround.ipynb>`_
- `Link <../Examples/tensorflow/quantization/adaround.ipynb>`_
* - AutoQuant
- `Link <../Examples/torch/quantization/autoquant.ipynb>`_
- `Link <../Examples/tensorflow/quantization/autoquant.ipynb>`_
* - BN Re-estimation
- `Link <../Examples/torch/quantization/bn_reestimation.ipynb>`_
- `Link <../Examples/tensorflow/quantization/bn_reestimation.ipynb>`_


.. list-table:: Compression Examples
:widths: 40 12 12
:header-rows: 1

* - Features
- PyTorch
- TensorFlow
* - Channel Pruning
- `Link <../Examples/torch/compression/channel_pruning.ipynb>`_
- `Link <../Examples/tensorflow/compression/channel_pruning.ipynb>`_
* - Spatial SVD
- `Link <../Examples/torch/compression/spatial_svd.ipynb>`_
- `Link <../Examples/tensorflow/compression/spatial_svd.ipynb>`_
* - Spatial SVD + Channel Pruning
- `Link <../Examples/torch/compression/spatial_svd_channel_pruning.ipynb>`_
- `Link <../Examples/tensorflow/compression/spatial_svd_channel_pruning.ipynb>`_

* WORKSPACE="<absolute_path_to_workspace>"

* mkdir $WORKSPACE && cd $WORKSPACE

* Go to https://github.com/quic/aimet/releases and identify the release tag (`<release_tag>`) of the AIMET package that you're working with.

* git clone https://github.com/quic/aimet.git --branch <release_tag>

* Update the environment variable as follows: `export PYTHONPATH=$PYTHONPATH:${WORKSPACE}/aimet`

Code Layout
===========

The code for AIMET Examples shares a common structure:

Examples/

common/

torch/

utils/

quantization/

compression/

tensorflow/

utils/

quantization/

compression/

|
Running Examples via Jupyter Notebook
Expand All @@ -75,15 +91,3 @@ Running Examples via Jupyter Notebook
- `Examples/tensorflow/compression/`
- Follow the instructions therein to execute the code.

Running Examples via Command Line
=================================

To run an AIMET example:

python example_name.py --dataset_dir path/to/dataset/ --use_cuda

For example, to run the channel pruning example run the following:

python channel_pruning.py --dataset_dir path/to/dataset/ --use_cuda --epochs 15 --learning_rate 1e-2 --learning_rate_schedule [5, 10]

Setting the hyperparameters epochs, learning rate, and learning rate scheduler is optional. If the values are not given, the default values will be used.
32 changes: 3 additions & 29 deletions Examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,11 @@

set(AIMET_EXAMPLES_DEST ${AIMET_INSTALL_DIR}/Examples)

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/common
DESTINATION ${AIMET_EXAMPLES_DEST}
PATTERN "__pycache*" EXCLUDE
PATTERN "CMakeLists.txt" EXCLUDE
)

# Copy over the Examples documentation
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/README.md
DESTINATION ${AIMET_EXAMPLES_DEST}
)

if (ENABLE_TORCH)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/torch
DESTINATION ${AIMET_EXAMPLES_DEST}
PATTERN "__pycache*" EXCLUDE
PATTERN "CMakeLists.txt" EXCLUDE
)

endif(ENABLE_TORCH)

if (ENABLE_TENSORFLOW)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tensorflow
DESTINATION ${AIMET_EXAMPLES_DEST}
PATTERN "__pycache*" EXCLUDE
PATTERN "CMakeLists.txt" EXCLUDE
)

endif(ENABLE_TENSORFLOW)
add_custom_target(copy_examples
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_BINARY_DIR}/Docs_SOURCE/Examples)

# Create a tarball archive of the Examples code
install(CODE "execute_process(COMMAND
${CMAKE_COMMAND} -E chdir ${AIMET_INSTALL_DIR}
${CMAKE_COMMAND} -E tar cvzf ${AIMET_EXAMPLES_DEST}.tar.gz Examples)"
${CMAKE_COMMAND} -E tar cvzf ${AIMET_EXAMPLES_DEST}.tar.gz ${CMAKE_CURRENT_SOURCE_DIR}/Examples)"
)
File renamed without changes.
File renamed without changes.

0 comments on commit 57554d6

Please sign in to comment.