Skip to content

Commit b14fe8a

Browse files
authored
New AI Sample for Enabling Auto-Mixed Precision for Transfer Learning with TensorFlow (#1146)
* TF AMX TL sample * update README.md for TF AMX TL * Update sample.json * Update ci_test.py
1 parent 420f11a commit b14fe8a

File tree

11 files changed

+1360
-0
lines changed

11 files changed

+1360
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Enabling Auto-Mixed Precision for Transfer Learning with TensorFlow
2+
This tutorial guides you through the process of enabling auto-mixed precision to use low-precision datatypes, like bfloat16, for transfer learning with TensorFlow* (TF).
3+
4+
This sample demonstrates the end-to-end pipeline tasks typically performed in a deep learning use-case: training (and retraining), inference optimization, and serving the model with TensorFlow Serving.
5+
6+
| Area | Description
7+
|:--- |:---
8+
| What you will learn | Enable Auto-Mixed Precision for Transfer Learning with TensorFlow
9+
| Time to complete | 30 minutes
10+
11+
## Purpose
12+
13+
Through the implementation of end-to-end deep learning example, this sample demonstrates three important concepts:
14+
1. The benefits of using auto-mixed precision to accelerate tasks like transfer learning, with minimal changes to existing scripts.
15+
2. The importance of inference optimization on performance.
16+
3. The ease of using Intel® optimizations in TensorFlow, which are enabled by default in 2.9.0 and newer.
17+
18+
## Prerequisites
19+
20+
| Optimized for | Description
21+
|:--- |:---
22+
| OS | Ubuntu* 18.04 or newer
23+
| Hardware | Intel® Xeon® Scalable processor family or newer
24+
| Software | Intel® AI Analytics Toolkit (AI Kit)
25+
26+
### For Local Development Environments
27+
28+
You will need to download and install the following toolkits, tools, and components to use the sample.
29+
30+
- **Intel® AI Analytics Toolkit (AI Kit)**
31+
32+
You can get the AI Kit from [Intel® oneAPI Toolkits](https://www.intel.com/content/www/us/en/developer/tools/oneapi/toolkits.html#analytics-kit). <br> See [*Get Started with the Intel® AI Analytics Toolkit for Linux**](https://www.intel.com/content/www/us/en/develop/documentation/get-started-with-ai-linux) for AI Kit installation information and post-installation steps and scripts.
33+
34+
- **Jupyter Notebook**
35+
36+
Install using PIP: `$pip install notebook`. <br> Alternatively, see [*Installing Jupyter*](https://jupyter.org/install) for detailed installation instructions.
37+
38+
- **TensorFlow Serving**
39+
40+
See *TensorFlow Serving* [*Installation*](https://www.tensorflow.org/tfx/serving/setup) for detailed installation options.
41+
42+
- **Other dependencies**
43+
44+
Install using PIP and the `requirements.txt` file supplied with the sample: `$pip install -r requirements.txt`. <br> The `requirements.txt` file contains the necessary dependencies to run the Notebook.
45+
46+
### For Intel® DevCloud
47+
48+
The necessary tools and components are already installed in the environment. You do not need to install additional components. See [Intel® DevCloud for oneAPI](https://devcloud.intel.com/oneapi/get_started/) for information.
49+
50+
## Key Implementation Details
51+
52+
The sample tutorial contains one Jupyter Notebook and two Python scripts.
53+
54+
### Jupyter Notebook
55+
56+
| Notebook | Description
57+
|:--- |:---
58+
|`enabling_automixed_precision_transfer_learning_tensorflow.ipynb` | Enabling Auto-Mixed Precision for Transfer Learning with TensorFlow
59+
60+
### Python Scripts
61+
62+
| Script | Description
63+
|:--- |:---
64+
|`freeze_optimize_v2.py` |The script optimizes a pre-trained TensorFlow model PB file.
65+
|`tf_benchmark.py` |The script measures inference performance of a model using dummy data.
66+
67+
## Run the Sample on Linux*
68+
1. Launch Jupyter Notebook.
69+
```
70+
jupyter notebook --ip=0.0.0.0
71+
```
72+
2. Follow the instructions to open the URL with the token in your browser.
73+
3. Locate and select the Notebook.
74+
```
75+
enabling_automixed_precision_transfer_learning_tensorflow.ipynb
76+
````
77+
4. Change your Jupyter Notebook kernel to **tensorflow** or **intel-tensorflow**.
78+
5. Run every cell in the Notebook in sequence.
79+
80+
81+
### Run the Sample on Intel® DevCloud
82+
83+
1. If you do not already have an account, request an Intel® DevCloud account at [*Create an Intel® DevCloud Account*](https://intelsoftwaresites.secure.force.com/DevCloud/oneapi).
84+
2. On a Linux* system, open a terminal.
85+
3. SSH into Intel® DevCloud.
86+
```
87+
ssh DevCloud
88+
```
89+
> **Note**: You can find information about configuring your Linux system and connecting to Intel DevCloud at Intel® DevCloud for oneAPI [Get Started](https://devcloud.intel.com/oneapi/get_started).
90+
4. Follow the instructions to open the URL with the token in your browser.
91+
5. Locate and select the Notebook.
92+
```
93+
enabling_automixed_precision_transfer_learning_tensorflow.ipynb
94+
````
95+
6. Change the kernel to **tensorflow** or **intel-tensorflow**.
96+
7. Run every cell in the Notebook in sequence.
97+
98+
99+
#### Troubleshooting
100+
101+
If you receive an error message, troubleshoot the problem using the **Diagnostics Utility for Intel® oneAPI Toolkits**. The diagnostic utility provides configuration and system checks to help find missing dependencies, permissions errors, and other issues. See the [Diagnostics Utility for Intel® oneAPI Toolkits User Guide](https://www.intel.com/content/www/us/en/develop/documentation/diagnostic-utility-user-guide/top.html) for more information on using the utility.
102+
103+
104+
## Example Output
105+
You will see diagrams that compare performance and analysis.
106+
107+
The following image illustrates performance comparison for training speedup obtained by enabling auto-mixed precision.
108+
109+
![Training Speedup](images/training-perf-comp.png)
110+
111+
For performance analysis, you will see histograms showing different Tensorflow* operations in the analyzed pre-trained model pb file. The following image illustrates performance comparison for inference speedup obtained by optimizing the saved model for inference.
112+
113+
![Inference Speedup](images/inference-perf-comp.png)
114+
115+
116+
## License
117+
118+
Code samples are licensed under the MIT license. See
119+
[License.txt](https://github.com/oneapi-src/oneAPI-samples/blob/master/License.txt) for details.
120+
121+
Third party program Licenses can be found here: [third-party-programs.txt](https://github.com/oneapi-src/oneAPI-samples/blob/master/third-party-programs.txt).

0 commit comments

Comments
 (0)