def testTrain(self): batch_size = 20 sequence_length = 35 with tf.Graph().as_default(), tf.device(tf.test.gpu_device_name()): inputs_ph = tf.placeholder(tf.int64, [sequence_length, batch_size], "inputs") labels_ph = tf.placeholder(tf.int64, [sequence_length, batch_size], "labels") inputs = np.ones(inputs_ph.shape.as_list(), dtype=np.int64) labels = np.ones(labels_ph.shape.as_list(), dtype=np.int64) model = rnn_ptb.small_model(tf.test.is_gpu_available()) optimizer = tf.train.GradientDescentOptimizer(learning_rate=1.0) loss = rnn_ptb.loss_fn(model, inputs_ph, labels_ph, training=True) grads = rnn_ptb.clip_gradients(optimizer.compute_gradients(loss), 0.25) train_op = optimizer.apply_gradients(grads) with tf.Session() as sess: sess.run(tf.global_variables_initializer()) sess.run(train_op, feed_dict={ inputs_ph: inputs, labels_ph: labels }) sess.run([train_op, loss], feed_dict={ inputs_ph: inputs, labels_ph: labels })
def testTrain(self): model = rnn_ptb.small_model(tfe.num_gpus() > 0) sequence_length = 35 data = np.ones([4 * sequence_length, 20], dtype=np.int64) with tf.device(device()): optimizer = tf.train.GradientDescentOptimizer(1.0) # Train two epochs rnn_ptb.train(model, optimizer, data, sequence_length, 0.25) rnn_ptb.train(model, optimizer, data, sequence_length, 0.25)
def benchmark_cudnn_train_small(self): if not tf.test.is_gpu_available(): return self._benchmark_train("graph_cudnn_train_small", rnn_ptb.small_model(True))
def benchmark_train_small(self): self._benchmark_train("graph_train_small", rnn_ptb.small_model(False))
def benchmark_apply_small(self): self._benchmark_apply("graph_apply_small", rnn_ptb.small_model(False))
def benchmark_cudnn_train_small(self): if not tf.test.is_gpu_available(): return self._benchmark_train("graph_cudnn_train_small", rnn_ptb.small_model(True))
def benchmark_train_small(self): self._benchmark_train("graph_train_small", rnn_ptb.small_model(False))
def benchmark_apply_small(self): self._benchmark_apply("graph_apply_small", rnn_ptb.small_model(False))
def benchmark_cudnn_apply_small(self): if not tfe.num_gpus(): return self._benchmark_apply("eager_cudnn_apply_small", rnn_ptb.small_model(True))
def testApply(self): model = rnn_ptb.small_model(tfe.num_gpus() > 0) with tf.device(device()): model(tf.ones([35, 20], dtype=tf.int64), training=False)
def benchmark_cudnn_apply_small(self): if not tfe.num_gpus(): return self._benchmark_apply("eager_cudnn_apply_small", rnn_ptb.small_model(True))