From d002f60af9668f7b934f9e4616d96003a3e4f755 Mon Sep 17 00:00:00 2001 From: Yang Yang Date: Thu, 18 Jan 2018 00:23:46 +0000 Subject: [PATCH] merge develop --- paddle/framework/lod_tensor.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/paddle/framework/lod_tensor.cc b/paddle/framework/lod_tensor.cc index 3f2c2e64e..b29f528f3 100644 --- a/paddle/framework/lod_tensor.cc +++ b/paddle/framework/lod_tensor.cc @@ -289,14 +289,15 @@ void DeserializeFromStream(std::istream &is, LoDTensor *tensor, std::vector LoDTensor::SplitLoDTensor( const std::vector places) const { check_memory_size(); - PADDLE_ENFORCE(lod().empty(), "Disable parallel lod for now"); - size_t result_size = std::min(static_cast(dims()[0]), places.size()); - size_t remainder = dims()[0] % places.size(); + int batch_size = + lod().empty() ? dims()[0] : static_cast(lod()[0].size()) - 1; + size_t result_size = std::min(static_cast(batch_size), places.size()); + size_t remainder = batch_size % places.size(); std::vector results; results.reserve(result_size); - int step_width = static_cast(dims()[0] / result_size); + int step_width = static_cast(batch_size / result_size); for (size_t i = 0; i < result_size; ++i) { int begin = static_cast(i * step_width); int end = static_cast((i + 1) * step_width); @@ -307,14 +308,14 @@ std::vector LoDTensor::SplitLoDTensor( LoDTensor dst; if (lod().empty()) { auto src = Slice(begin, end); - auto &dst_place = places[place_idx]; + auto &dst_place = places[i]; framework::Copy(src, dst_place, &dst); } else { auto lod_and_offset = GetSubLoDAndAbsoluteOffset(lod(), begin, end, 0); auto &offset = lod_and_offset.second; auto src = Slice(offset.first, offset.second); - auto &dst_place = places[place_idx]; + auto &dst_place = places[i]; framework::Copy(src, dst_place, &dst); LoD my_lod; @@ -327,7 +328,7 @@ std::vector LoDTensor::SplitLoDTensor( } dst.set_lod(my_lod); } - lods.emplace_back(dst); + results.emplace_back(dst); } return results; -- GitLab