在tensorflow 2.8.0中,使用镜像策略:
strategy = tf.distribute.MirroredStrategy()
with strategy.scope():
self.model()产生以下警告:
W tensorflow/core/grappler/optimizers/data/auto_shard.cc:776] AUTO sharding policy will apply DATA sharding policy as it failed to apply FILE sharding policy because of the following reason: Did not find a shardable source, walked to a node which is not a dataset: name: "FlatMapDataset/_2"
Consider either turning off auto-sharding or switching the auto_shard_policy to DATA to shard this dataset. You can do this by creating a new `tf.data.Options()` object then setting `options.experimental_distribute.auto_shard_policy = AutoShardPolicy.DATA` before applying the options object to the dataset via `dataset.with_options(options)`.但是我想使用文件共享策略,因为我已经设置了多个GPU。我有什么办法做到这一点吗?
发布于 2022-06-24 22:54:43
如果对数据集使用tf.data,则需要在dataset中使用tf.data.Options()设置碎片策略。
import tensorflow as tf
dataset = # some dataset
options = tf.data.Options()
options.experimental_distribute.auto_shard_policy = tf.data.experimental.AutoShardPolicy.FILE
dataset = dataset.with_options(options) # use this as input for your modelFILE和DATA与使用多GPU无关,它们都使用多GPU.更多的是关于如何将数据加载到它们上。默认情况下,如果您拥有比员工更多的数据(这是您应该使用的),则使用FILE。看起来您的输入数据可能无法正确创建。
如果您不使用tf.data,而是使用类似于numpy数组的东西,则可以忽略警告或阻止它们显示,因为它们默认为FILE (如果它正常工作的话)。不要故意使警告失效。)
import os
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" # this MUST come before any tf call.编辑:也许有一种方法可以使用numpy数组来设置碎片策略,我只是还没有找到它。我使用numpy数组并隐藏警告,因为我知道它们运行良好。对我的警告只是说它默认为FILE,但对您来说,数据集本身存在问题。
https://stackoverflow.com/questions/72740907
复制相似问题