gpt4 book ai didi

tensorflow - gpflow 2 : Why set autograph=False? 中的优化

转载 作者:行者123 更新时间:2023-12-04 10:34:17 25 4
gpt4 key购买 nike

在当前笔记本教程 (gpflow 2.0) 中,所有 @tf.function 标签都包含选项
签名=假,例如( https://gpflow.readthedocs.io/en/2.0.0-rc1/notebooks/advanced/gps_for_big_data.html ):

@tf.function(autograph=False)
def optimization_step(optimizer, model: gpflow.models.SVGP, batch):
with tf.GradientTape(watch_accessed_variables=False) as tape:
tape.watch(model.trainable_variables)
objective = - model.elbo(*batch)
grads = tape.gradient(objective, model.trainable_variables)
optimizer.apply_gradients(zip(grads, model.trainable_variables))
return objective

有谁知道为什么会这样,或者这背后的原因是什么?
据我了解, autograph=True只是允许将 python 控制流转换为图形结构。即使不需要该功能,将其设置/保留为 true 是否有任何缺点?

我的猜测是它在图形的编译时只是一个很小的开销,但应该可以忽略不计。错了吗?

谢谢

最佳答案

我们设置的原因autographFalse在大多数tf.function包装目标是因为 GPflow 使用了一个内部使用生成器的多调度 Dispatcher。但是,TensorFlow 无法在签名模式下处理生成器对象(请参阅 Capabilities and Limitations of AutoGraph ),这会导致以下警告:

WARNING:tensorflow:Entity <bound method Dispatcher.dispatch_iter of <dispatched sample_conditional>> appears to be a generator function. It will not be converted by AutoGraph.
WARNING: Entity <bound method Dispatcher.dispatch_iter of <dispatched sample_conditional>> appears to be a generator function. It will not be converted by AutoGraph.
WARNING:tensorflow:Entity <bound method Dispatcher.dispatch_iter of <dispatched conditional>> appears to be a generator function. It will not be converted by AutoGraph.
WARNING: Entity <bound method Dispatcher.dispatch_iter of <dispatched conditional>> appears to be a generator function. It will not be converted by AutoGraph.

我们已经知道这个问题有一段时间了,但还没有真正解决它 - 感谢您让我们重新关注这个问题。我刚刚创建了一个 PR这解决了这个问题,并且不再需要您将签名设置为 False。我希望这个 PR 很快就会合并。

关于tensorflow - gpflow 2 : Why set autograph=False? 中的优化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60263252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com