Skip to content

Commit 3518522

Browse files
committed
[CPU-PSLIB] Modify scale_sparse_grad to scale_sparse_gradient_with_batch_size
1 parent ef94264 commit 3518522

File tree

9 files changed

+22
-15
lines changed

9 files changed

+22
-15
lines changed

paddle/fluid/framework/device_worker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class DeviceWorker {
212212
FetchConfig fetch_config_;
213213
bool use_cvm_;
214214
bool no_cvm_;
215-
bool scale_sparse_grad_;
215+
bool scale_sparse_gradient_with_batch_size_;
216216
TrainerDesc trainer_desc_;
217217

218218
// dump params or grads for debug

paddle/fluid/framework/downpour_worker.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ 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();
92+
scale_sparse_gradient_with_batch_size_ =
93+
desc.scale_sparse_gradient_with_batch_size();
9394
scale_datanorm_ = desc.scale_datanorm();
9495
dump_slot_ = desc.dump_slot();
9596
adjust_ins_weight_config_ = desc.adjust_ins_weight_config();
@@ -592,7 +593,8 @@ void DownpourWorker::TrainFilesWithProfiler() {
592593
*thread_scope_, tid, features_[tid], feature_labels_[tid],
593594
sparse_key_names_[tid], sparse_grad_names_[tid], table.emb_dim(),
594595
&feature_grads_[tid], &push_sparse_status_, cur_batch, use_cvm_,
595-
dump_slot_, &sparse_push_keys_[tid], no_cvm_, scale_sparse_grad_);
596+
dump_slot_, &sparse_push_keys_[tid], no_cvm_,
597+
scale_sparse_gradient_with_batch_size_);
596598
timeline.Pause();
597599
push_sparse_time += timeline.ElapsedSec();
598600
total_time += timeline.ElapsedSec();
@@ -867,7 +869,8 @@ void DownpourWorker::TrainFiles() {
867869
*thread_scope_, tid, features_[tid], feature_labels_[tid],
868870
sparse_key_names_[tid], sparse_grad_names_[tid], table.emb_dim(),
869871
&feature_grads_[tid], &push_sparse_status_, cur_batch, use_cvm_,
870-
dump_slot_, &sparse_push_keys_[tid], no_cvm_, scale_sparse_grad_);
872+
dump_slot_, &sparse_push_keys_[tid], no_cvm_,
873+
scale_sparse_gradient_with_batch_size_);
871874
}
872875
}
873876

paddle/fluid/framework/downpour_worker_opt.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,12 +450,13 @@ void DownpourWorkerOpt::TrainFiles() {
450450
break;
451451
}
452452
}
453-
bool scale_sparse_grad_ = true;
453+
bool scale_sparse_gradient_with_batch_size_ = true;
454454
fleet_ptr_->PushSparseVarsWithLabelAsync(
455455
*thread_scope_, tid, features_[tid], feature_labels_[tid],
456456
sparse_key_names_[tid], sparse_grad_names_[tid], table.emb_dim(),
457457
&feature_grads_[tid], &push_sparse_status_, cur_batch, use_cvm_,
458-
dump_slot_, &sparse_push_keys_[tid], no_cvm_, scale_sparse_grad_);
458+
dump_slot_, &sparse_push_keys_[tid], no_cvm_,
459+
scale_sparse_gradient_with_batch_size_);
459460
}
460461
}
461462

paddle/fluid/framework/fleet/fleet_wrapper.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ void FleetWrapper::PushSparseVarsWithLabelAsync(
871871
std::vector<::std::future<int32_t>>* push_sparse_status,
872872
const int batch_size, const bool use_cvm, const bool dump_slot,
873873
std::vector<uint64_t>* sparse_push_keys, const bool no_cvm,
874-
const bool scale_sparse_grad) {
874+
const bool scale_sparse_gradient_with_batch_size) {
875875
#ifdef PADDLE_WITH_PSLIB
876876
int offset = 2;
877877
int slot_offset = 0;

paddle/fluid/framework/fleet/fleet_wrapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class FleetWrapper {
210210
std::vector<::std::future<int32_t>>* push_sparse_status,
211211
const int batch_size, const bool use_cvm, const bool dump_slot,
212212
std::vector<uint64_t>* sparse_push_keys, const bool no_cvm,
213-
const bool scale_sparse_grad);
213+
const bool scale_sparse_gradient_with_batch_size);
214214

215215
// Push sparse variables to server in async mode
216216
void PushSparseFromTensorWithLabelAsync(

paddle/fluid/framework/trainer_desc.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +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 ];
64+
optional bool scale_sparse_gradient_with_batch_size = 34 [ default = true ];
6565

6666
// device worker parameters
6767
optional HogwildWorkerParameter hogwild_param = 101;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,8 @@ 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)
828+
opt_info["scale_sparse_gradient_with_batch_size"] = strategy.get(
829+
"scale_sparse_gradient_with_batch_size", True)
829830
opt_info["worker_class"] = strategy.get("worker_class",
830831
"DownpourWorker")
831832
opt_info["stat_var_names"] = strategy.get("stat_var_names", [])

python/paddle/fluid/trainer_desc.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +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
127+
def _set_scale_sparse_grad_with_batch_size(
128+
self, scale_sparse_gradient_with_batch_size=True):
129+
self.proto_desc.scale_sparse_gradient_with_batch_size = scale_sparse_gradient_with_batch_size
129130

130131
def _set_scale_datanorm(self, scale_datanorm=-1):
131132
self.proto_desc.scale_datanorm = scale_datanorm

python/paddle/fluid/trainer_factory.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@ 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"])
98+
if opt_info.get(
99+
"scale_sparse_gradient_with_batch_size") is not None:
100+
trainer._set_scale_sparse_grad_with_batch_size(opt_info[
101+
"scale_sparse_gradient_with_batch_size"])
101102
if opt_info.get("scale_datanorm") is not None:
102103
trainer._set_scale_datanorm(opt_info["scale_datanorm"])
103104
if opt_info.get("adjust_ins_weight") is not None:

0 commit comments

Comments
 (0)