in lm_human_preferences/train_policy.py [0:0]
def tf_times():
"""Returns (time since start, time since last) as a tensorflow op."""
# Keep track of start and last times
with tf.init_scope():
init = tf.timestamp()
def make(name):
return tf.Variable(init, name=name, trainable=False, use_resource=True)
start = make('start_time')
last = make('last_time')
# Get new time and update last
now = tf.timestamp()
prev = last.read_value()
with tf.control_dependencies([prev]):
with tf.control_dependencies([last.assign(now)]):
return tf.cast(now - start.read_value(), tf.float32), tf.cast(now - prev, tf.float32)