创建LoD tensor耗时太久问题
要创建一个形状为 [30, 2048]的lod tensor, lod level为 [[ 10, 9, 11]],也就是前10行向量组成第一个元素,依次类推。尝试用以下两种创建方式,测试发现耗时都在38ms左右(V100,fluid1.4),导致reader很慢,影响GPU使用率,有没有更快速的方式?
方式1: def to_level1_lod_slow(data, dtype, place): """ convert ot LODtensor """ seq_lens = [len(seq) for seq in data] cur_len = 0 lod = [cur_len] for l in seq_lens: cur_len += l lod.append(cur_len) flattened_data = np.concatenate(data, axis=0).astype(dtype) flattened_data = flattened_data.reshape([len(flattened_data), flattened_data.shape[1]]) res = fluid.LoDTensor() res.set(flattened_data, place) res.set_lod([lod]) return res
方式2: def to_level1_lod(data, dtype, place): """ convert ot LODtensor """ time1 = time.time() seq_lens = [len(seq) for seq in data] flattened_data = np.concatenate(data, axis=0).astype(dtype) res = fluid.create_lod_tensor(flattened_data, [seq_lens], place) time2 = time.time() print "create lod time, ", time2-time1 return res
耗时是在np.concatenate(data, axis=0).astype(dtype)还是在fluid.create_lod_tensor(flattened_data, [seq_lens], place)呢
Since you haven't replied for more than a year, we have closed this issue/pr. If the problem is not solved or there is a follow-up one, please reopen it at any time and we will continue to follow up. 由于您超过一年未回复,我们将关闭这个issue/pr。 若问题未解决或有后续问题,请随时重新打开,我们会继续跟进。