- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用函数式 API 运行 keras 多输入模型时出现此警告。该模型在单个 GPU 上运行时运行良好且没有警告。当我使用 tf.distribute.MirroredStrategy
使用两个 GPU 模型的最终结果没问题,但我收到警告。我认为这会导致性能问题?
tf.__version__ : 2.2.0
tf.keras.__version__ : 2.3.0-tf
NVIDIA-SMI 410.72 Driver Version: 410.72 CUDA Version: 10.1
我生成的模型是:
def build_model_():
input_a_size = 200
input_b_size = 4
num_classes = 2
len_embedding = 100
mirrored_strategy = tf.distribute.MirroredStrategy(['/gpu:0', '/gpu:1'])
with mirrored_strategy.scope():
input_a = Input(shape=(input_a_size,), name='input_a', dtype=np.uint8)
input_b = Input(shape=(input_b_size,), name='input_b', dtype=np.float32)
x = Embedding(len_embedding, 100)(input_a)
x = Conv1D(32, 4, activation='relu')(x)
x = Flatten()(x)
branch_a = Dense(64, activation='relu')(x)
x = Dense(32, activation='relu')(input_b)
branch_b = Dense(32, activation='relu')(x)
concat = Concatenate()([
branch_a,
branch_b,
])
x = Dense(256, activation = 'relu')(concat)
output = Dense(num_classes, activation='softmax')(x)
model = Model(inputs=[
input_a,
input_b,
],
outputs=[output])
model.compile(loss = 'binary_crossentropy', optimizer = 'adam', metrics = ['accuracy'])
model.summary()
return model
型号概要:
INFO:tensorflow:Using MirroredStrategy with devices ('/job:localhost/replica:0/task:0/device:GPU:0', '/job:localhost/replica:0/task:0/device:GPU:1')
Model: "model"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_a (InputLayer) [(None, 200)] 0
__________________________________________________________________________________________________
embedding (Embedding) (None, 200, 100) 10000 input_a[0][0]
__________________________________________________________________________________________________
conv1d (Conv1D) (None, 197, 128) 51328 embedding[0][0]
__________________________________________________________________________________________________
max_pooling1d (MaxPooling1D) (None, 49, 128) 0 conv1d[0][0]
__________________________________________________________________________________________________
input_b (InputLayer) [(None, 4)] 0
__________________________________________________________________________________________________
flatten (Flatten) (None, 6272) 0 max_pooling1d[0][0]
__________________________________________________________________________________________________
dense_1 (Dense) (None, 32) 160 input_b[0][0]
__________________________________________________________________________________________________
dense (Dense) (None, 64) 401472 flatten[0][0]
__________________________________________________________________________________________________
dense_2 (Dense) (None, 32) 1056 dense_1[0][0]
__________________________________________________________________________________________________
concatenate (Concatenate) (None, 96) 0 dense[0][0]
dense_2[0][0]
__________________________________________________________________________________________________
dense_3 (Dense) (None, 256) 24832 concatenate[0][0]
__________________________________________________________________________________________________
dense_4 (Dense) (None, 2) 514 dense_3[0][0]
==================================================================================================
Total params: 489,362
Trainable params: 489,362
Non-trainable params: 0
__________________________________________________________________________________________________
我生成输入的方式:
input_a_train.shape: (35000, 200)
input_b_train.shape: (35000, 4)
y_train.shape: (35000, 2)
train_dataset = tf.data.Dataset.from_tensor_slices(({
"input_a": input_a_train,
"input_b": input_b_train,
}, y_train))
<TensorSliceDataset shapes: ({input_a: (200,), input_b: (4,)}, (2,)), types: ({input_a: tf.uint8, input_b: tf.float64}, tf.float32)>
val_dataset = tf.data.Dataset.from_tensor_slices(({
"input_a": input_a_val,
"input_b": input_b_val,
}, y_val))
<TensorSliceDataset shapes: ({input_a: (200,), input_b: (4,)}, (2,)), types: ({input_a: tf.uint8, input_b: tf.float64}, tf.float32)>
train_batches = train_dataset.padded_batch(128)
val_batches = val_dataset.padded_batch(128)
我在训练阶段收到警告,
history = my_model.fit(
x = train_batches,
epochs=3,
verbose = 1,
validation_data = val_batches,
)
这是输出:
Epoch 1/3
INFO:tensorflow:batch_all_reduce: 12 all-reduces with algorithm = nccl, num_packs = 1
WARNING:tensorflow:Efficient allreduce is not supported for 1 IndexedSlices
INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:GPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:GPU:0', '/job:localhost/replica:0/task:0/device:GPU:1').
INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
INFO:tensorflow:batch_all_reduce: 12 all-reduces with algorithm = nccl, num_packs = 1
WARNING:tensorflow:Efficient allreduce is not supported for 1 IndexedSlices
INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:GPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:GPU:0', '/job:localhost/replica:0/task:0/device:GPU:1').
INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
INFO:tensorflow:Reduce to /job:localhost/replica:0/task:0/device:CPU:0 then broadcast to ('/job:localhost/replica:0/task:0/device:CPU:0',).
274/274 [==============================] - ETA: 0s - loss: 0.1857 - accuracy: 0.9324
...
这里有一个类似的问题:
Efficient allreduce is not supported for 2 IndexedSlices但它没有答案。
最佳答案
我使用 tf.distribute.experimental.MultiWorkerMirroredStrategy()
解决了它.此策略对处理 IndexedSlices 有更好的支持,链接如下:https://github.com/tensorflow/tensorflow/issues/41898#issuecomment-668786507 .此外,根据使用的 GPU 数量增加批量大小。
这个问题涵盖了问题,
https://github.com/tensorflow/tensorflow/issues/41898
physical_devices = tf.config.list_physical_devices('GPU') # 8 GPUs in my setup
tf.config.set_visible_devices(physical_devices[0:8], 'GPU') # Using all GPUs (default behaviour)
strategy = tf.distribute.experimental.MultiWorkerMirroredStrategy()
BATCH_SIZE_PER_REPLICA = 1024
GLOBAL_BATCH_SIZE = BATCH_SIZE_PER_REPLICA * strategy.num_replicas_in_sync
train_batches = train_dataset.batch(GLOBAL_BATCH_SIZE)
with strategy.scope():
model = build_model_()
model.compile(loss = 'binary_crossentropy', optimizer = 'adam', metrics = ['accuracy'])
history = model.fit(
x = train_batches,
epochs=10,
verbose = 1,
)
关于python - 警告 :tensorflow:Efficient allreduce is not supported for 1 IndexedSlices,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63034145/
我在一个数据集中有一个来自不同来源的姓名列表:一组按 FirstName LastName 组织;另一个有全名。我想查看名字或姓氏是否在全名列中,并创建一个标志。两个问题: 首先,我 u sed th
我一直认为不存在是正确的方法,而不是使用不存在条件。但是,我对我一直使用的查询进行比较,我注意到“Not In”条件的执行实际上似乎更快。任何关于为什么会出现这种情况的见解,或者如果到目前为止我只是做
我需要开发一个 iPad 应用程序,它应该管理两种方向模式(横向和纵向)。 根据 official Apple iOS documentation , 有 2 种方法可以继续。 -第一个包括在收到旋转
我有一个类有 2 个变量成员: class A: fullname = "" email = "" 内存中存储了一个A的列表,现在我需要针对全名或电子邮件进行搜索,搜索需要支持模糊搜索
哪个更有效率?或者它们都同样有效?带星号的行中的底层架构发生了什么? (1) for(int i = m_size; i > index; --i) { int k = normalize(
要检查两个不同日期范围的重叠,{Start1, End1} 和 {Start2, End2} 我正在检查: if ((Start1 = Start2)) { //overlap exists }
这个问题在这里已经有了答案: 关闭 13 年前. Possible Duplicate: Is there a performance difference between i++ and ++i i
前言: 学习ComfyUI是一场持久战, efficiency-nodes-comfyui是提高工作流创造效率的工具,包含效率节点整合工作流中的基础功能,比如Efficient Loader节点相当
我正在编写一个 Java 小程序,并且正在尝试读取一个 220K 行 (9.2 MB) 的文本文件,该文件是用 .jar 归档的。我相信我对文本文件的唯一合理访问是InputStream。为了使用 I
我有一个 Java 应用程序,需要播放一些不同的“声音/连复段”来指示状态。我想知道是否最好将这些记录为音频文件(wav 或任何格式)并使用 Java 音频类播放它们,或者存储 MIDI 数据并使用
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
很抱歉这个问题太基本了。 目标:这是我的软件程序的输出: 1 590 SC 1.000 LEU2_YEAST 100% 1 590 EC 1.000 LEU2_ECOLI 10
重复使用 $(this) 是否有效,还是将其保存到变量中更好?我已经看到它在很多 jQuery 代码中重复使用,但由于它是对构造函数的调用,我认为它应该不必要地慢,我错了吗? 最佳答案 只是为了好玩
我正在考虑编写一个函数,该函数使用 calloc 创建一个数组来容纳文件中的数据(目前以字符形式)。据我了解,我的两个最明显的选择是读取所有字符以获得所需的总大小,使用 calloc 分配所需的空间,
好的,假设我有如下类: public class KPIObject // Data { get; set; } public string Caption { get; set; } } p
我想对表演者数组进行排序,以便他们按名字的第一个字符进行分组。例如,以下输出中的“A”代表名字以“A”开头的表演者的集合。 [ "A"[Performer,Performer,Performer,Pe
我正在使用此 MySQL 语句来查找社区的平均特性评估。问题是我必须为每个邻域添加一条 SELECT 语句——而且有很多邻域。有没有办法不必指定“RIVER FRONT”或“OLD TOWN”?有没有
我有许多表,大约有四个,我希望连接在一起。为了使我的代码更清晰和可读(对我而言),我希望一次加入所有代码,然后在最后过滤: SELECT f1, f2, ..., fn FROM t1 INNER J
我有以下代码: setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); # statement handle (prevents in
我有一个巨大的数据文件,我只需要这个文件中的特定数据,以后我会经常使用这些数据。那么这两种方法中哪一种更有效: 将此数据保存在全局变量(可能是 LinkedList)中,并在每次需要时使用它们 将它们
我是一名优秀的程序员,十分优秀!