[BLOCKING] fix the issue with infrequent feature (#4045)

* fix the issue with infrequent feature

* handle exception

* use only 2 workers

* address the comments
This commit is contained in:
Nan Zhu
2019-01-06 16:01:03 -08:00
committed by GitHub
parent e290ec9a80
commit 773ddbcfcb
3 changed files with 64 additions and 2 deletions

View File

@@ -9,6 +9,7 @@
#include <dmlc/base.h>
#include <dmlc/data.h>
#include <rabit/rabit.h>
#include <cstring>
#include <memory>
#include <numeric>
@@ -169,8 +170,16 @@ class SparsePage {
inline Inst operator[](size_t i) const {
const auto& data_vec = data.HostVector();
const auto& offset_vec = offset.HostVector();
size_t size;
// in distributed mode, some partitions may not get any instance for a feature. Therefore
// we should set the size as zero
if (rabit::IsDistributed() && i + 1 >= offset_vec.size()) {
size = 0;
} else {
size = offset_vec[i + 1] - offset_vec[i];
}
return {data_vec.data() + offset_vec[i],
static_cast<Inst::index_type>(offset_vec[i + 1] - offset_vec[i])};
static_cast<Inst::index_type>(size)};
}
/*! \brief constructor */
@@ -285,7 +294,6 @@ class SparsePage {
auto& data_vec = data.HostVector();
auto& offset_vec = offset.HostVector();
offset_vec.push_back(offset_vec.back() + inst.size());
size_t begin = data_vec.size();
data_vec.resize(begin + inst.size());
if (inst.size() != 0) {