Skip to main content
 首页 » 编程设计

python之tf.estimator.Estimator.evaluate() 是否总是在一个 GPU 上运行

2025年05月04日13mfryf

我的印象是在 tf.estimator.Estimator 实例上调用 evaluate() 不会在多个 GPU 上运行模型,即使分配策略是 MirroredStrategy,配置为至少使用 2 个 GPU。

这是一个建议这种行为的示例脚本:https://gist.github.com/patzm/b69fcdf33fc9062683d749d0ea936b5e

这是显示此行为的 nvidia-smi 的屏幕截图:

如果 evaluate() 应该运行,如果像上面那样在多个 GPU 上使用,请在您的回答中突出显示我的错误。

请您参考如下方法:

在您的RunConfig 中,将策略也设置为eval_distribute,详情请参阅this

run_config = tf.estimator.RunConfig( 
    model_dir=tf.test.get_temp_dir(), 
    session_config=tf.ConfigProto(allow_soft_placement=True), 
    train_distribute=distribution_strategy, 
    eval_distribute=distribution_strategy 
)