March 16, 2019
Introduction to Running AI
Workloads on PowerAI
• IBM PowerAI Overview
• AI Workload Demos using TensorFlow
• PyTorch Hands-On Lab
•Download it from here: http://ibm.biz/download-powerai
•Connect to the PowerAI Conda repository
•Get the Docker container from here: https://hub.docker.com/r/ibmcom/powerai/
An enterprise software distribution that combines popular open source deep
learning frameworks, efficient AI development tools, and accelerated IBM®
Power Systems™ servers to take your deep learning projects to the next level
Visit website: http://bit.ly/powericpp
Using PowerAI for your workloads
Activate the virtual environment for your framework to get started!
Deep learning overview
Deep Learning consists of algorithms that permit software to train itself— by
exposing multilayered neural networks to vast amounts of data.
• Map x → y
• Neural net is a graph
• Data flow: left to right
• Input(s) of the current cell are the
output(s) from previous cells
• Tweak all weights until output matches
Training = tweak weights to minimize error (loss)
Repeat over and over and over ...
• Continuously feed in input data to model, comparing output predictions and actual labels in order to
• An optimization algorithm is used to minimize this loss by tweaking the weights and biases of the model.
• The model is progressively improved and predictions become more accurate as more data is fed.
(Run input through
(Compare output to
- Gradient Descent Algorithm
- Adam Optimization Algorithm
- Cross Entropy
- Mean Squared Error
The MNIST (Modified National Institute of Standards and Technology)
dataset consists of 60,000 images of handwritten digits like:
Each image has an associated label denoting which digit it is.
The above images would have labels 5, 0, 4, and 1.
Problem Description: Image Classification
We want to be able to train a deep learning model using the MNIST dataset that
will be able to look at images and predict what digits they are.
1. Download workload
=> git clone https://github.com/pvaneck/tf_mnist
=> cd tf_mnist
=> python ./train_basic_model.py
The training result will be saved in ~/tf_mnist/saved-model
Running the MNIST workload
Running the MNIST workload (continued)
Predict the class of an image using the models saved in the ~/tf_mnist/saved-model directory with a
sample image from ~/tf_mnist/sample-images directory.
=> python ./classify_mnist.py sample-images/img_1.jpg
# Sample image (img_1.jpg):
# This is the program output:
2 (confidence = 0.99987)
3 (confidence = 0.00010)
0 (confidence = 0.00003)
8 (confidence = 0.00000)
5 (confidence = 0.00000)
The result shows that the answer with the most confidence is “2”.
• Placeholders are input
• x is a 2D array for the images:
• Each row is one flattened 28x28 image
• First dimension is “None”, to be used to pull in a batch of images at a time
• y_ is 2D array for the labels:
• Second dimension 10 for the one-hot representation
# Placeholder that will be fed image data.
x = tf.placeholder(tf.float32, [None, 784])
# Placeholder that will be fed the correct labels.
y_ = tf.placeholder(tf.float32, [None, 10])
Implement Weight and Bias
• Weight and Bias are variables: to be tweaked during training
• Weight is a 2D array: 784 x 10
• Bias is a vector: 10
• Initialized with certain values: important for optimization algorithm
"""Generates a weight variable of a given shape."""
initial = tf.truncated_normal(shape, stddev=0.1)
"""Generates a bias variable of a given shape."""
initial = tf.constant(0.1, shape=shape)
# Define weight and bias.
W = weight_variable([784, 10])
b = bias_variable()
Implement Regression and Loss Optimizer
• Neural network: Regression + SoftMax
• Loss function: how far off is the prediction from the label
• Optimizer algorithm: how to tweak the variables
# Here we define our model which utilizes the softmax regression.
y = tf.nn.softmax(tf.matmul(x, W) + b)
# Define our loss.
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=))
# Define our optimizer.
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
Convolutional Neural Net
● Neural network with series of convolutional, downsampling, and non-linear layers
● Are deployed in many practical applications
○ Image and speech recognition, video analysis, drug discovery
● Most commonly used for image classification
PyTorch is a relatively new deep learning framework. Yet, it has begun to gain
adoption especially among researchers and data scientists.
▪ Goal is to build a flexible deep learning research platform that supports
▪ Dynamic computation graphs
▪ Native Python packages
▪ Auto-differentiation (gradient computations)
▪ Open sourced January, 2017
▪ Rapid adoption one year in …
▪ 3,983 github repo mentioned PyTorch in their name or description
▪ Taught in universities classes (Stanford, Carnegie Mellon University, ....)
▪ Fast growing community
▪ 5,400 users wrote 21k posts discussing 5,200 topics on PyTorch forums
▪ Merged with Caffe2 March 30, 2018
▪ Currently at version 0.4.0
○ Multi-dimensional arrays
○ Similar to NumPy (np) ndarrays, but can also be used on a GPU
○ Can easily convert from np arrays to torch tensor and vise versa
○ Support automatic differentiation for all operations on tensors.
○ Members includes .data (tensor), .grad (gradient w.r.t corresponding
○ Package: “import torch”
○ Tensor tutorial
○ Autograd tutorial
○ Base class to build neural network.
○ Inputs & output for training are Tensors.
○ Store learnable weights & biases as parameters
○ May store states
○ Package: “import torch.nn.Module”
○ Module tutorial
● And many more ….
● Consult handouts for credentials and access information.
Open Jupyter notebooks