From fd1da60251f9daf6096dc59e62789b227d4a5889 Mon Sep 17 00:00:00 2001 From: Yang Wang Date: Mon, 9 May 2022 17:12:44 +0800 Subject: [PATCH] Add Nano doc structure and Nano overview (#4504) * Add Nano doc structrue and nano overview * add sections * add unset environment variable instructions * restructure * address comments --- .../source/doc/Nano/Overview/nano.md | 92 +++++++++++++++++++ .../source/doc/Nano/QuickStart/pytorch.md | 27 ++++++ .../source/doc/Nano/QuickStart/tensorflow.md | 18 ++++ 3 files changed, 137 insertions(+) create mode 100644 docs/readthedocs/source/doc/Nano/Overview/nano.md create mode 100644 docs/readthedocs/source/doc/Nano/QuickStart/pytorch.md create mode 100644 docs/readthedocs/source/doc/Nano/QuickStart/tensorflow.md diff --git a/docs/readthedocs/source/doc/Nano/Overview/nano.md b/docs/readthedocs/source/doc/Nano/Overview/nano.md new file mode 100644 index 00000000..9b6a1b6e --- /dev/null +++ b/docs/readthedocs/source/doc/Nano/Overview/nano.md @@ -0,0 +1,92 @@ +# Nano User Guide + +## **1. Overview** + +BigDL Nano is a python package to transparently accelerate PyTorch and TensorFlow applications on Intel hardware. It provides a unified and easy-to-use API for several optimization techniques and tools, so that users can only apply a few lines of code changes to make their PyTorch or TensorFlow code run faster. + +--- +## **2. Install** + +BigDL-Nano can be installed using pip and we recommend installing BigDL-Nano in a conda environment. + +For PyTorch Users, you can install bigdl-nano along with some dependencies specific to PyTorch using the following command. + +```bash +conda create -n env +conda activate env +pip install bigdl-nano[pytorch] +``` + +For TensorFlow users, you can install bigdl-nano along with some dependencies specific to TensorFlow using the following command. + +```bash +conda create -n env +conda activate env +pip install bigdl-nano[tensorflow] +``` + +After installing bigdl-nano, you can run the following command to setup a few environment variables. + +```bash +source bigdl-nano-init +``` + +The `bigdl-nano-init` scripts will export a few environment variable according to your hardware to maximize performance. + +In a conda environment, this will also add this script to `$CONDA_PREFIX/etc/conda/activate.d/`, which will automaticly run when you activate your current environment. + +In a pure pip environment, you need to run `source bigdl-nano-init` every time you open a new shell to get optimal performance and run `source bigdl-nano-unset-env` if you want to unset these environment variables. + +--- + +## **3. Get Started** + +#### **3.1 PyTorch** + +BigDL-Nano supports both PyTorch and PyTorch Lightning models and most optimizations requires only changing a few "import" lines in your code and adding a few flags. + +BigDL-Nano uses a extended version of PyTorch Lightning trainer for integrating our optimizations. + +For example, if you are using a LightingModule, you can use the following code enable intel-extension-for-pytorch and multi-instance training. + +```python +from bigdl.nano.pytorch import Trainer +net = create_lightning_model() +train_loader = create_training_loader() +trainer = Trainer(max_epochs=1, use_ipex=True, num_processes=4) +trainer.fit(net, train_loader) +``` + +For more details on the BigDL-Nano's PyTorch usage, please refer to the [PyTorch](../QuickStart/pytorch.md) page. + +### **3.2 TensorFlow** + +BigDL-Nano supports `tensorflow.keras` API and most optimizations requires only changing a few "import" lines in your code and adding a few flags. + +BigDL-Nano uses a extended version of `tf.keras.Model` or `tf.keras.Sequential` for integrating our optimizations. + +For example, you can conduct a multi-instance training using the following code: + +```python +import tensorflow as tf +from bigdl.nano.tf.keras import Sequential +mnist = tf.keras.datasets.mnist + +(x_train, y_train),(x_test, y_test) = mnist.load_data() +x_train, x_test = x_train / 255.0, x_test / 255.0 + +model = Sequential([ + tf.keras.layers.Flatten(input_shape=(28, 28)), + tf.keras.layers.Dense(128, activation='relu'), + tf.keras.layers.Dropout(0.2), + tf.keras.layers.Dense(10, activation='softmax') +]) + +model.compile(optimizer='adam', + loss='sparse_categorical_crossentropy', + metrics=['accuracy']) + +model.fit(x_train, y_train, epochs=5, num_processes=4) +``` + +For more details on the BigDL-Nano's PyTorch usage, please refer to the [TensorFlow](../QuickStart//tensorflow.md) page. diff --git a/docs/readthedocs/source/doc/Nano/QuickStart/pytorch.md b/docs/readthedocs/source/doc/Nano/QuickStart/pytorch.md new file mode 100644 index 00000000..76965009 --- /dev/null +++ b/docs/readthedocs/source/doc/Nano/QuickStart/pytorch.md @@ -0,0 +1,27 @@ +# BigDL-Nano PyTorch Overview + +BigDL-Nano can be used to accelerate PyTorch or PyTorch-Lightning applications on both training and inference workloads. The optimizations in BigDL-Nano are delivered through a extended version of PyTorch-Lightning `Trainer`. These optimizations are either enabled by default, or can be easily turned on by setting a parameter or calling a method. + +## PyTorch Training + +### Best Known Configurations + +### BigDL-Nano PyTorch Trainer + +#### IntelĀ® Extension for PyTorch + +#### Multi-instance Training + +### Optimized Data pipeline + +### Optimizers + +### Notebooks + +## PyTorch Inference + +### Runtime Acceleration + +### Quantization + +### Notebooks \ No newline at end of file diff --git a/docs/readthedocs/source/doc/Nano/QuickStart/tensorflow.md b/docs/readthedocs/source/doc/Nano/QuickStart/tensorflow.md new file mode 100644 index 00000000..a662bf51 --- /dev/null +++ b/docs/readthedocs/source/doc/Nano/QuickStart/tensorflow.md @@ -0,0 +1,18 @@ +# Nano TensorFlow Overview + +## TensorFlow Training + +### Runtime Acceleration +intel-tensorflow, intel-openmp + +### Optimized Layers +embedding + +### Optimizers +SparseAdam + +### Multi-Instance Training + +## TensorFlow Inference + +### Quantization \ No newline at end of file