Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Simple Example for TensorFlow

Interactive mode

Get node for interactive use:

Code Block
srun --partition=debug --pty --nodes=1 --ntasks-per-node=8 --gres=gpu:v100:1 -t 01:30:00 --wait=0 --export=ALL /bin/bash

Once on the compute node, load PowerAI module using one of these:

Code Block
module load ibm/powerai/1.6.0.py2 # for python2 environment
module load ibm/powerai/1.6.0.py3 # for python3 environment
module load ibm/powerai           # python3 environment by default

Copy the following code into file "mnist-demo.py":

Code Block
import tensorflow as tf
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 = tf.keras.models.Sequential([
  tf.keras.layers.Flatten(input_shape=(28, 28)),
  tf.keras.layers.Dense(512, activation=tf.nn.relu),
  tf.keras.layers.Dropout(0.2),
  tf.keras.layers.Dense(10, activation=tf.nn.softmax)
])
model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])

model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test, y_test)

Train on MNIST with keras API:

Code Block
python3 ./mnist-demo.py

Batch mode

The same can be accomplished in batch mode using the following tf_sample.sb script:

Code Block
sbatch tf_sample.sb
squeue

Simple Example for Pytorch

...