-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Google colab updates. Documentation updates, verifaction script updat…
…es (#2772) * Google colab updates. Documentation updates, verifaction script updates Signed-off-by: Joel Polizzi <quic_jpolizzi@quicinc.com> * Correct typos and provide further documentation comments Signed-off-by: Joel Polizzi <quic_jpolizzi@quicinc.com> --------- Signed-off-by: Joel Polizzi <quic_jpolizzi@quicinc.com>
- Loading branch information
1 parent
9894507
commit a969432
Showing
5 changed files
with
419 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,330 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "783-amyMv50Y" | ||
}, | ||
"source": [ | ||
"# Aimet Installation and test\n", | ||
"Welcome to aimet!\n", | ||
"This colab environment can be used to experiment with aimet.\n", | ||
"If you are testing a GPU variant of aimet you will need to select a T4 GPU runtime from the dropdown menu to the right.\n", | ||
"\n", | ||
"*Please note there are limitations in Google Colab and this is documented for short and quick aimet tests and not intended to be leveraged for any production purpose." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "xlxmatutwx2L" | ||
}, | ||
"source": [ | ||
"To get started we first will run this cell to install the proper conda environment." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 63, | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
}, | ||
"id": "8YVW5OljfovQ", | ||
"outputId": "752f91d6-c680-479e-c438-756bd8e97e83" | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"['Python 3.8.3']\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"python_ver = !python --version\n", | ||
"print(python_ver)\n", | ||
"if('Python 3.8' not in python_ver[0]):\n", | ||
" print(python_ver)\n", | ||
" !wget -O mini.sh https://repo.anaconda.com/miniconda/Miniconda3-py38_4.8.3-Linux-x86_64.sh\n", | ||
" !chmod +x mini.sh\n", | ||
" !bash ./mini.sh -b -f -p /usr/local\n", | ||
" !conda install -q -y jupyter\n", | ||
" !conda install -q -y google-colab -c conda-forge\n", | ||
" !python -m ipykernel install --user --name=\"py38\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "9I3_ZZ45xAIH" | ||
}, | ||
"source": [ | ||
"Here you can see that when calling python through bash we can access python 3.8, which is required for aimet." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"id": "5Ol64M4Lfue_" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"!which python\n", | ||
"!echo $PYTHONPATH\n", | ||
"import sys\n", | ||
"!python -c \"import sys; print(sys.version)\"\n", | ||
"print(sys.version)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "Gpvyh4SvxMwr" | ||
}, | ||
"source": [ | ||
"Next, we will set our PYTHONPATH environment variable" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"id": "6cuOtbfShwdX" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"%env PYTHONPATH=\"/env/python:/usr/local/lib/python3.8/site-packages\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "scCYapn-yH7X" | ||
}, | ||
"source": [ | ||
"Here we will set the aimet variant and release_tag we are using.\n", | ||
"Variants can be found in the Aimet documentation: https://quic.github.io/aimet-pages/releases/latest/install/index.html\n", | ||
"\n", | ||
"Release tags can be found here: https://github.com/quic/aimet/releases" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": { | ||
"id": "EBPO13XxiDQo" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"os.environ[\"AIMET_VARIANT\"] = \"torch_gpu\"\n", | ||
"os.environ[\"release_tag\"] = \"1.28.0\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "QpTw20v5kBS6" | ||
}, | ||
"source": [ | ||
"Now we will remove the existing nvidia-ml.list and nvidia-machine-learning.list and replace it in our install script\n", | ||
"* You may skip this step when using a cpu variant" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 64, | ||
"metadata": { | ||
"id": "1CLd8BMqoyyz" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"!rm -rf /etc/apt/sources.list.d/nvidia-ml.list /etc/apt/sources.list.d/nvidia-machine-learning.list" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"id": "nGpT1h7as9Xx" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"!apt-get update" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "BsKtA8N0kUYO" | ||
}, | ||
"source": [ | ||
"Lets wget o" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"id": "tp0aU80aUw6H" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"!git clone https://github.com/quic/aimet.git" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "a6b2OFtqkaR2" | ||
}, | ||
"source": [ | ||
"This script will run our installation based on th3e variables we provided in earlier steps" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "rNqBqhzey3hJ" | ||
}, | ||
"source": [ | ||
"Run the installation script" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"id": "tLZ3-M0ajkVn" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"\n", | ||
"!/bin/bash aimet/develop/packaging/verification/aimet-os-install.sh" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "QSNlJS8r0Ptj" | ||
}, | ||
"source": [ | ||
"In order to acces our environment inside colab we need to use the %%bash magic command to call python in the cell. Lets test some imports" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"id": "T9bHRI6Allmh" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"%%bash\n", | ||
"sh /usr/local/lib/python3.8/site-packages/aimet_common/bin/envsetup.sh\n", | ||
"python -c \"\n", | ||
"\n", | ||
"from aimet_common.defs import QuantScheme\n", | ||
"import aimet_common.defs as aimet_common_defs\n", | ||
"import aimet_common.libpymo as libpymo\n", | ||
"\n", | ||
"import torch\n", | ||
"from aimet_torch.quantsim import QuantizationSimModel\n", | ||
"from aimet_torch.compress import ModelCompressor\n", | ||
"\n", | ||
"from aimet_torch.adaround.adaround_weight import Adaround, AdaroundParameters\n", | ||
"from aimet_torch.batch_norm_fold import fold_all_batch_norms\n", | ||
"from aimet_torch.quantsim import QuantizationSimModel\n", | ||
"\n", | ||
"\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "7mA-M7y7UxlS" | ||
}, | ||
"source": [ | ||
"Now that we can import Aimet lets install pytest and run one of our tests" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"id": "iOPur82rbqwV" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"!pip install pytest" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "lOJO6i6hoQ5n" | ||
}, | ||
"source": [ | ||
"Lets run our tests from the test directory and create our data directory" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"id": "aflR_DJCek8u" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"if os.getcwd() != os.path.abspath(\"/content/aimet/TrainingExtensions/torch/test/python\"):\n", | ||
" os.chdir(\"aimet/TrainingExtensions/torch/test/python\")\n", | ||
"else:\n", | ||
" print(\"Already located at aimet/TrainingExtensions/torch/test/python\")\n", | ||
"\n", | ||
"if not os.path.exists(\"./data\"):\n", | ||
" os.mkdir(\"./data\")\n", | ||
"else:\n", | ||
" print(\"Path exists\")\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "R2NT7yA5pRRX" | ||
}, | ||
"source": [ | ||
"Lets run a quantizer test for torch gpu" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"id": "j95Nuz_DatK3" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"!pytest test_quantizer_GPU.py" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"accelerator": "GPU", | ||
"colab": { | ||
"gpuType": "T4", | ||
"provenance": [] | ||
}, | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
Oops, something went wrong.