|
|
|
@ -21,40 +21,40 @@ namespace framework {
|
|
|
|
|
|
|
|
|
|
void DownpourWorker::Initialize(const TrainerDesc& desc) {
|
|
|
|
|
param_ = desc.downpour_param();
|
|
|
|
|
for (size_t i = 0; i < param_.sparse_table_size(); ++i) {
|
|
|
|
|
for (int i = 0; i < param_.sparse_table_size(); ++i) {
|
|
|
|
|
uint64_t table_id =
|
|
|
|
|
static_cast<uint64_t>(param_.sparse_table(i).table_id());
|
|
|
|
|
TableParameter table = param_.sparse_table(i);
|
|
|
|
|
sparse_key_names_[table_id].resize(table.sparse_key_name_size());
|
|
|
|
|
for (size_t j = 0; j < table.sparse_key_name_size(); ++j) {
|
|
|
|
|
for (int j = 0; j < table.sparse_key_name_size(); ++j) {
|
|
|
|
|
sparse_key_names_[table_id][j] = table.sparse_key_name(j);
|
|
|
|
|
}
|
|
|
|
|
sparse_value_names_[table_id].resize(table.sparse_value_name_size());
|
|
|
|
|
for (size_t j = 0; j < table.sparse_value_name_size(); ++j) {
|
|
|
|
|
for (int j = 0; j < table.sparse_value_name_size(); ++j) {
|
|
|
|
|
sparse_value_names_[table_id][j] = table.sparse_value_name(j);
|
|
|
|
|
}
|
|
|
|
|
sparse_grad_names_[table_id].resize(table.sparse_grad_name_size());
|
|
|
|
|
for (size_t j = 0; j < table.sparse_grad_name_size(); ++j) {
|
|
|
|
|
for (int j = 0; j < table.sparse_grad_name_size(); ++j) {
|
|
|
|
|
sparse_grad_names_[table_id][j] = table.sparse_grad_name(j);
|
|
|
|
|
}
|
|
|
|
|
label_var_name_[table_id] = table.label_var_name();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < param_.dense_table_size(); ++i) {
|
|
|
|
|
for (int i = 0; i < param_.dense_table_size(); ++i) {
|
|
|
|
|
uint64_t table_id = static_cast<uint64_t>(param_.dense_table(i).table_id());
|
|
|
|
|
auto table = param_.dense_table(i);
|
|
|
|
|
dense_value_names_[table_id].resize(table.dense_value_name_size());
|
|
|
|
|
for (size_t j = 0; j < table.dense_value_name_size(); ++j) {
|
|
|
|
|
for (int j = 0; j < table.dense_value_name_size(); ++j) {
|
|
|
|
|
dense_value_names_[table_id][j] = table.dense_value_name(j);
|
|
|
|
|
}
|
|
|
|
|
dense_grad_names_[table_id].resize(table.dense_grad_name_size());
|
|
|
|
|
for (size_t j = 0; j < table.dense_grad_name_size(); ++j) {
|
|
|
|
|
for (int j = 0; j < table.dense_grad_name_size(); ++j) {
|
|
|
|
|
dense_grad_names_[table_id][j] = table.dense_grad_name(j);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
skip_ops_.resize(param_.skip_ops_size());
|
|
|
|
|
for (size_t i = 0; i < param_.skip_ops_size(); ++i) {
|
|
|
|
|
for (int i = 0; i < param_.skip_ops_size(); ++i) {
|
|
|
|
|
skip_ops_[i] = param_.skip_ops(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -83,14 +83,14 @@ void DownpourWorker::CollectLabelInfo(size_t table_idx) {
|
|
|
|
|
LoDTensor* tensor = var->GetMutable<LoDTensor>();
|
|
|
|
|
int64_t* label_ptr = tensor->data<int64_t>();
|
|
|
|
|
|
|
|
|
|
int global_index = 0;
|
|
|
|
|
size_t global_index = 0;
|
|
|
|
|
for (size_t i = 0; i < sparse_key_names_[table_id].size(); ++i) {
|
|
|
|
|
VLOG(3) << "sparse_key_names_[" << i
|
|
|
|
|
<< "]: " << sparse_key_names_[table_id][i];
|
|
|
|
|
Variable* fea_var = thread_scope_->FindVar(sparse_key_names_[table_id][i]);
|
|
|
|
|
LoDTensor* tensor = fea_var->GetMutable<LoDTensor>();
|
|
|
|
|
int64_t* ids = tensor->data<int64_t>();
|
|
|
|
|
int fea_idx = 0;
|
|
|
|
|
size_t fea_idx = 0;
|
|
|
|
|
// tensor->lod()[0].size() == batch_size + 1
|
|
|
|
|
for (auto lod_idx = 1u; lod_idx < tensor->lod()[0].size(); ++lod_idx) {
|
|
|
|
|
for (; fea_idx < tensor->lod()[0][lod_idx]; ++fea_idx) {
|
|
|
|
@ -138,7 +138,7 @@ void DownpourWorker::FillSparseValue(size_t table_idx) {
|
|
|
|
|
auto& tensor_lod = tensor->lod()[0];
|
|
|
|
|
LoD data_lod{tensor_lod};
|
|
|
|
|
tensor_emb->set_lod(data_lod);
|
|
|
|
|
for (auto index = 0u; index < len; ++index) {
|
|
|
|
|
for (int index = 0; index < len; ++index) {
|
|
|
|
|
if (ids[index] == 0u) {
|
|
|
|
|
memcpy(ptr + table.emb_dim() * index, init_value.data() + 2,
|
|
|
|
|
sizeof(float) * table.emb_dim());
|
|
|
|
@ -192,7 +192,7 @@ void DownpourWorker::TrainFilesWithProfiler() {
|
|
|
|
|
read_time += timeline.ElapsedSec();
|
|
|
|
|
total_time += timeline.ElapsedSec();
|
|
|
|
|
VLOG(3) << "program config size: " << param_.program_config_size();
|
|
|
|
|
for (size_t i = 0; i < param_.program_config(0).pull_sparse_table_id_size();
|
|
|
|
|
for (int i = 0; i < param_.program_config(0).pull_sparse_table_id_size();
|
|
|
|
|
++i) {
|
|
|
|
|
uint64_t tid = static_cast<uint64_t>(
|
|
|
|
|
param_.program_config(0).pull_sparse_table_id(i));
|
|
|
|
@ -244,8 +244,8 @@ void DownpourWorker::TrainFilesWithProfiler() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (need_to_push_sparse_) {
|
|
|
|
|
for (size_t i = 0;
|
|
|
|
|
i < param_.program_config(0).push_sparse_table_id_size(); ++i) {
|
|
|
|
|
for (int i = 0; i < param_.program_config(0).push_sparse_table_id_size();
|
|
|
|
|
++i) {
|
|
|
|
|
uint64_t tid = static_cast<uint64_t>(
|
|
|
|
|
param_.program_config(0).push_sparse_table_id(i));
|
|
|
|
|
TableParameter table;
|
|
|
|
@ -268,8 +268,8 @@ void DownpourWorker::TrainFilesWithProfiler() {
|
|
|
|
|
|
|
|
|
|
if (need_to_push_dense_) {
|
|
|
|
|
timeline.Start();
|
|
|
|
|
for (size_t i = 0;
|
|
|
|
|
i < param_.program_config(0).push_dense_table_id_size(); ++i) {
|
|
|
|
|
for (int i = 0; i < param_.program_config(0).push_dense_table_id_size();
|
|
|
|
|
++i) {
|
|
|
|
|
uint64_t tid = static_cast<uint64_t>(
|
|
|
|
|
param_.program_config(0).push_dense_table_id(i));
|
|
|
|
|
fleet_ptr_->PushDenseVarsAsync(
|
|
|
|
@ -315,8 +315,8 @@ void DownpourWorker::TrainFilesWithProfiler() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (need_to_push_dense_) {
|
|
|
|
|
for (size_t i = 0;
|
|
|
|
|
i < param_.program_config(0).push_dense_table_id_size(); ++i) {
|
|
|
|
|
for (int i = 0; i < param_.program_config(0).push_dense_table_id_size();
|
|
|
|
|
++i) {
|
|
|
|
|
uint64_t tid = static_cast<uint64_t>(
|
|
|
|
|
param_.program_config(0).push_dense_table_id(i));
|
|
|
|
|
pull_dense_worker_->IncreaseThreadVersion(thread_id_, tid);
|
|
|
|
@ -362,7 +362,7 @@ void DownpourWorker::TrainFiles() {
|
|
|
|
|
int cur_batch;
|
|
|
|
|
while ((cur_batch = device_reader_->Next()) > 0) {
|
|
|
|
|
// pull sparse here
|
|
|
|
|
for (size_t i = 0; i < param_.program_config(0).pull_sparse_table_id_size();
|
|
|
|
|
for (int i = 0; i < param_.program_config(0).pull_sparse_table_id_size();
|
|
|
|
|
++i) {
|
|
|
|
|
uint64_t tid = static_cast<uint64_t>(
|
|
|
|
|
param_.program_config(0).pull_sparse_table_id(i));
|
|
|
|
@ -397,8 +397,8 @@ void DownpourWorker::TrainFiles() {
|
|
|
|
|
|
|
|
|
|
if (need_to_push_sparse_) {
|
|
|
|
|
// push gradients here
|
|
|
|
|
for (size_t i = 0;
|
|
|
|
|
i < param_.program_config(0).push_sparse_table_id_size(); ++i) {
|
|
|
|
|
for (int i = 0; i < param_.program_config(0).push_sparse_table_id_size();
|
|
|
|
|
++i) {
|
|
|
|
|
uint64_t tid = static_cast<uint64_t>(
|
|
|
|
|
param_.program_config(0).push_sparse_table_id(i));
|
|
|
|
|
TableParameter table;
|
|
|
|
@ -416,8 +416,8 @@ void DownpourWorker::TrainFiles() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (need_to_push_dense_) {
|
|
|
|
|
for (size_t i = 0;
|
|
|
|
|
i < param_.program_config(0).push_dense_table_id_size(); ++i) {
|
|
|
|
|
for (int i = 0; i < param_.program_config(0).push_dense_table_id_size();
|
|
|
|
|
++i) {
|
|
|
|
|
uint64_t tid = static_cast<uint64_t>(
|
|
|
|
|
param_.program_config(0).push_dense_table_id(i));
|
|
|
|
|
fleet_ptr_->PushDenseVarsAsync(
|
|
|
|
@ -461,8 +461,8 @@ void DownpourWorker::TrainFiles() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (need_to_push_dense_) {
|
|
|
|
|
for (size_t i = 0;
|
|
|
|
|
i < param_.program_config(0).push_dense_table_id_size(); ++i) {
|
|
|
|
|
for (int i = 0; i < param_.program_config(0).push_dense_table_id_size();
|
|
|
|
|
++i) {
|
|
|
|
|
uint64_t tid = static_cast<uint64_t>(
|
|
|
|
|
param_.program_config(0).push_dense_table_id(i));
|
|
|
|
|
pull_dense_worker_->IncreaseThreadVersion(thread_id_, tid);
|
|
|
|
|