首页 > 其他 > 详细

tf.control_dependencies()

时间:2019-12-25 15:48:29      阅读:90      评论:0      收藏:0      [点我收藏+]

1.tf.control_dependencies

此函数指定某些操作执行的依赖关系 返回一个控制依赖的上下文管理器,使用 with 关键字可以让在这个上下文环境中的操作都在 control_inputs 执行  

举例:

with tf.control_dependencies([a, b]):
     c = ....
     d = ...

# 在执行完 a,b 操作之后,才能执行 c,d 操作。意思就是 c,d 操作依赖 a,b 操作

bert源码:

# Position embedding信息
if use_position_embeddings:
# 确保seq_length小于等于max_position_embeddings
assert_op = tf.assert_less_equal(seq_length, max_position_embeddings)
with tf.control_dependencies([assert_op]):
  full_position_embeddings = tf.get_variable(
      name=position_embedding_name,
      shape=[max_position_embeddings, width],
      initializer=create_initializer(initializer_range))

tf.control_dependencies()

原文:https://www.cnblogs.com/nxf-rabbit75/p/12096613.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!