def _numpy_to_tf(self, batch_size, max_seq_len, input_size, hidden_size): with tf.Graph().as_default(): with tf.Session() as sess: tensors = dynamic_rnn_minimal.random_inputs_tf( batch_size, max_seq_len, input_size, hidden_size) inputs, seq_len, w, b, init_state = tensors tf_from_np = conversion.convert( dynamic_rnn_minimal.numpy, numpy_to_tf, [variables, functions, control_flow]) ops = tf_from_np(inputs, seq_len, w, b, init_state) def target(): sess.run(ops) self.time_execution( ('NumPy_TF', batch_size, max_seq_len, input_size, hidden_size), target, extras={ 'max_seq_len': max_seq_len, 'batch_size': batch_size, 'input_size': input_size, 'hidden_size': hidden_size, })
def _autograph_baseline(self, batch_size, max_seq_len, input_size, hidden_size): with tf.Graph().as_default(): with tf.Session() as sess: inputs, seq_len, w, b, init_state = dynamic_rnn_minimal.random_inputs_tf( batch_size, max_seq_len, input_size, hidden_size) converted_fn = tf.autograph.to_graph( dynamic_rnn_minimal.eager, experimental_optional_features=None) ops = converted_fn(inputs, seq_len, w, b, init_state) def target(): sess.run(ops) self.time_execution( ('AutoGraph', batch_size, max_seq_len, input_size, hidden_size), target, extras={ 'max_seq_len': max_seq_len, 'batch_size': batch_size, 'input_size': input_size, 'hidden_size': hidden_size, })
def _eager_baseline(self, batch_size, max_seq_len, input_size, hidden_size): inputs, seq_len, w, b, init_state = dynamic_rnn_minimal.random_inputs_tf( batch_size, max_seq_len, input_size, hidden_size) def target(): dynamic_rnn_minimal.eager(inputs, seq_len, w, b, init_state).numpy() self.time_execution( ('Eager', batch_size, max_seq_len, input_size, hidden_size), target, extras={ 'max_seq_len': max_seq_len, 'batch_size': batch_size, 'input_size': input_size, 'hidden_size': hidden_size, })
def _numpy_to_eager(self, batch_size, max_seq_len, input_size, hidden_size): inputs, seq_len, w, b, init_state = dynamic_rnn_minimal.random_inputs_tf( batch_size, max_seq_len, input_size, hidden_size) eager_from_np = conversion.convert( dynamic_rnn_minimal.numpy, numpy_to_tf, [variables, functions, control_flow]) def target(): eager_from_np(inputs, seq_len, w, b, init_state).numpy() self.time_execution( ('NumPy_Eager', batch_size, max_seq_len, input_size, hidden_size), target, extras={ 'max_seq_len': max_seq_len, 'batch_size': batch_size, 'input_size': input_size, 'hidden_size': hidden_size, })
def _tf_baseline(self, batch_size, max_seq_len, input_size, hidden_size): with tf.Graph().as_default(): with tf.Session() as sess: tensors = dynamic_rnn_minimal.random_inputs_tf( batch_size, max_seq_len, input_size, hidden_size) inputs, seq_len, w, b, init_state = tensors ops = dynamic_rnn_minimal.tf_(inputs, seq_len, w, b, init_state) def target(): sess.run(ops) self.time_execution( ('TF', batch_size, max_seq_len, input_size, hidden_size), target, extras={ 'max_seq_len': max_seq_len, 'batch_size': batch_size, 'input_size': input_size, 'hidden_size': hidden_size, })