Skip to content

Commit ef94264

Browse files
committed
[CPU-PSLIB] Add config for scale_sparse_grad in config_fleet.py,test=develop
1 parent f421741 commit ef94264

File tree

9 files changed

+19
-6
lines changed

9 files changed

+19
-6
lines changed

paddle/fluid/framework/device_worker.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ class DeviceWorker {
212212
FetchConfig fetch_config_;
213213
bool use_cvm_;
214214
bool no_cvm_;
215+
bool scale_sparse_grad_;
215216
TrainerDesc trainer_desc_;
216217

217218
// dump params or grads for debug

paddle/fluid/framework/downpour_worker.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ void DownpourWorker::Initialize(const TrainerDesc& desc) {
8989
use_cvm_ = desc.use_cvm();
9090
// for sparse value accessor, embedding only
9191
no_cvm_ = desc.no_cvm();
92+
scale_sparse_grad_ = desc.scale_sparse_grad();
9293
scale_datanorm_ = desc.scale_datanorm();
9394
dump_slot_ = desc.dump_slot();
9495
adjust_ins_weight_config_ = desc.adjust_ins_weight_config();
@@ -591,7 +592,7 @@ void DownpourWorker::TrainFilesWithProfiler() {
591592
*thread_scope_, tid, features_[tid], feature_labels_[tid],
592593
sparse_key_names_[tid], sparse_grad_names_[tid], table.emb_dim(),
593594
&feature_grads_[tid], &push_sparse_status_, cur_batch, use_cvm_,
594-
dump_slot_, &sparse_push_keys_[tid], no_cvm_);
595+
dump_slot_, &sparse_push_keys_[tid], no_cvm_, scale_sparse_grad_);
595596
timeline.Pause();
596597
push_sparse_time += timeline.ElapsedSec();
597598
total_time += timeline.ElapsedSec();
@@ -866,7 +867,7 @@ void DownpourWorker::TrainFiles() {
866867
*thread_scope_, tid, features_[tid], feature_labels_[tid],
867868
sparse_key_names_[tid], sparse_grad_names_[tid], table.emb_dim(),
868869
&feature_grads_[tid], &push_sparse_status_, cur_batch, use_cvm_,
869-
dump_slot_, &sparse_push_keys_[tid], no_cvm_);
870+
dump_slot_, &sparse_push_keys_[tid], no_cvm_, scale_sparse_grad_);
870871
}
871872
}
872873

paddle/fluid/framework/downpour_worker_opt.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,11 +450,12 @@ void DownpourWorkerOpt::TrainFiles() {
450450
break;
451451
}
452452
}
453+
bool scale_sparse_grad_ = true;
453454
fleet_ptr_->PushSparseVarsWithLabelAsync(
454455
*thread_scope_, tid, features_[tid], feature_labels_[tid],
455456
sparse_key_names_[tid], sparse_grad_names_[tid], table.emb_dim(),
456457
&feature_grads_[tid], &push_sparse_status_, cur_batch, use_cvm_,
457-
dump_slot_, &sparse_push_keys_[tid], no_cvm_);
458+
dump_slot_, &sparse_push_keys_[tid], no_cvm_, scale_sparse_grad_);
458459
}
459460
}
460461

paddle/fluid/framework/fleet/fleet_wrapper.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,8 @@ void FleetWrapper::PushSparseVarsWithLabelAsync(
870870
std::vector<std::vector<float>>* push_values,
871871
std::vector<::std::future<int32_t>>* push_sparse_status,
872872
const int batch_size, const bool use_cvm, const bool dump_slot,
873-
std::vector<uint64_t>* sparse_push_keys, const bool no_cvm) {
873+
std::vector<uint64_t>* sparse_push_keys, const bool no_cvm,
874+
const bool scale_sparse_grad) {
874875
#ifdef PADDLE_WITH_PSLIB
875876
int offset = 2;
876877
int slot_offset = 0;
@@ -939,7 +940,7 @@ void FleetWrapper::PushSparseVarsWithLabelAsync(
939940
}
940941
float* g = g_tensor->data<float>();
941942

942-
if (scale_sparse_gradient_with_batch_size_ && grad_dim > 0) {
943+
if (scale_sparse_grad && grad_dim > 0) {
943944
int dim = emb_dim;
944945
Eigen::Map<
945946
Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>

paddle/fluid/framework/fleet/fleet_wrapper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ class FleetWrapper {
209209
std::vector<std::vector<float>>* push_values,
210210
std::vector<::std::future<int32_t>>* push_sparse_status,
211211
const int batch_size, const bool use_cvm, const bool dump_slot,
212-
std::vector<uint64_t>* sparse_push_keys, const bool no_cvm);
212+
std::vector<uint64_t>* sparse_push_keys, const bool no_cvm,
213+
const bool scale_sparse_grad);
213214

214215
// Push sparse variables to server in async mode
215216
void PushSparseFromTensorWithLabelAsync(

paddle/fluid/framework/trainer_desc.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ message TrainerDesc {
6161

6262
optional bool use_ps_gpu = 32 [ default = false ];
6363
optional string user_define_dump_filename = 33;
64+
optional bool scale_sparse_grad = 34 [ default = true ];
6465

6566
// device worker parameters
6667
optional HogwildWorkerParameter hogwild_param = 101;

python/paddle/fluid/incubate/fleet/parameter_server/pslib/optimizer_factory.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,7 @@ def _minimize(self,
825825
opt_info["worker_skipped_ops"] = worker_skipped_ops
826826
opt_info["use_cvm"] = strategy.get("use_cvm", False)
827827
opt_info["no_cvm"] = strategy.get("no_cvm", False)
828+
opt_info["scale_sparse_grad"] = strategy.get("scale_sparse_grad", True)
828829
opt_info["worker_class"] = strategy.get("worker_class",
829830
"DownpourWorker")
830831
opt_info["stat_var_names"] = strategy.get("stat_var_names", [])

python/paddle/fluid/trainer_desc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ def _set_use_cvm(self, use_cvm=False):
124124
def _set_no_cvm(self, no_cvm=False):
125125
self.proto_desc.no_cvm = no_cvm
126126

127+
def _set_scale_sparse_grad(self, scale_sparse_grad=True):
128+
self.proto_desc.scale_sparse_grad = scale_sparse_grad
129+
127130
def _set_scale_datanorm(self, scale_datanorm=-1):
128131
self.proto_desc.scale_datanorm = scale_datanorm
129132

python/paddle/fluid/trainer_factory.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ def _create_trainer(self, opt_info=None):
9595
trainer._set_use_cvm(opt_info["use_cvm"])
9696
if opt_info.get("no_cvm") is not None:
9797
trainer._set_no_cvm(opt_info["no_cvm"])
98+
if opt_info.get("scale_sparse_grad") is not None:
99+
trainer._set_scale_sparse_grad(opt_info[
100+
"scale_sparse_grad"])
98101
if opt_info.get("scale_datanorm") is not None:
99102
trainer._set_scale_datanorm(opt_info["scale_datanorm"])
100103
if opt_info.get("adjust_ins_weight") is not None:

0 commit comments

Comments
 (0)