Create model using float 16 data type
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
# source: https://docs.nvidia.com/deeplearning/sdk/mixed-precision-training/index.html | |
import tensorflow as tf | |
def create_simple_model(nbatch, nin, nout, dtype): | |
"""A simple softmax model.""" | |
data = tf.placeholder(dtype, shape=(nbatch, nin)) | |
weights = tf.get_variable('weights', (nin, nout), dtype) | |
biases = tf.get_variable('biases', nout, dtype, initializer=tf.zeros_initializer()) | |
logits = tf.matmul(data, weights) + biases | |
target = tf.placeholder(tf.float32, shape=(nbatch, nout)) | |
# Note: The softmax should be computed in float32 precision | |
loss = tf.losses.softmax_cross_entropy(target, tf.cast(logits, tf.float32)) | |
return data, target, loss |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment