Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaocaibei123 committed Oct 20, 2021
1 parent 2b96d14 commit d7ee7f6
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 83 deletions.
20 changes: 6 additions & 14 deletions paddle/fluid/distributed/ps.proto
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,16 @@ message TableParameter {

message TableAccessorParameter {
optional string accessor_class = 1;
optional SparseSGDRuleParameter sparse_sgd_param = 2;
optional uint32 fea_dim = 4 [ default = 11 ];
optional uint32 embedx_dim = 5 [ default = 8 ];
optional uint32 embedx_threshold = 6 [ default = 10 ];
optional DownpourTableAccessorParameter downpour_accessor_param = 7;
optional CtrAccessorParameter downpour_accessor_param = 7;
repeated TableAccessorSaveParameter table_accessor_save_param = 8;
optional SparseCommonSGDRuleParameter sparse_commonsgd_param = 9;
optional SparseCommonSGDRuleParameter embed_sgd_param = 10;
optional SparseCommonSGDRuleParameter embedx_sgd_param = 11;
}

message DownpourTableAccessorParameter {
message CtrAccessorParameter {
optional float nonclk_coeff = 1
[ default = 0.1 ]; // to calculate show_click_score
optional float click_coeff = 2
Expand Down Expand Up @@ -182,34 +180,28 @@ message TableAccessorSaveParameter {
optional string deconverter = 3;
}

message SparseSGDRuleParameter {
optional double learning_rate = 1 [ default = 0.05 ];
optional double initial_g2sum = 2 [ default = 3.0 ];
optional double initial_range = 3 [ default = 0.0001 ];
repeated float weight_bounds = 4;
}

message SparseCommonSGDRuleParameter {
optional string name = 1;
optional SparseNaiveSGDRuleParameter naive = 2;
optional SparseAdagradSGDRuleParameter adagrad = 3;
optional SparseAdamSGDParameter adam = 4;
}

message SparseNaiveSGDRuleParameter {
message SparseNaiveSGDRuleParameter { // SparseNaiveSGDRule
optional double learning_rate = 1 [ default = 0.05 ];
optional double initial_range = 2 [ default = 0.0001 ];
repeated float weight_bounds = 3;
}

message SparseAdagradSGDRuleParameter {
message
SparseAdagradSGDRuleParameter { // SparseAdaGradSGDRule|StdAdaGradSGDRule
optional double learning_rate = 1 [ default = 0.05 ];
optional double initial_g2sum = 2 [ default = 3.0 ];
optional double initial_range = 3 [ default = 0.0001 ];
repeated float weight_bounds = 4;
}

message SparseAdamSGDParameter {
message SparseAdamSGDParameter { // SparseAdamSGDRule
optional double learning_rate = 1 [ default = 0.001 ];
optional double initial_range = 2 [ default = 0.0001 ];
optional double beta1_decay_rate = 3 [ default = 0.9 ];
Expand Down
6 changes: 3 additions & 3 deletions paddle/fluid/distributed/table/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ cc_library(tensor_accessor SRCS tensor_accessor.cc DEPS ${TABLE_DEPS} eigen3 ps_
cc_library(tensor_table SRCS tensor_table.cc DEPS eigen3 ps_framework_proto executor scope device_context tensor ${TABLE_DEPS})
set_source_files_properties(table.cc PROPERTIES COMPILE_FLAGS ${DISTRIBUTE_COMPILE_FLAGS})

set_source_files_properties(ctr_sparse_sgd.cc PROPERTIES COMPILE_FLAGS ${DISTRIBUTE_COMPILE_FLAGS})
cc_library(ctr_sparse_sgd SRCS ctr_sparse_sgd.cc DEPS ${TABLE_DEPS} ps_framework_proto)
set_source_files_properties(sparse_sgd_rule.cc PROPERTIES COMPILE_FLAGS ${DISTRIBUTE_COMPILE_FLAGS})
cc_library(sparse_sgd_rule SRCS sparse_sgd_rule.cc DEPS ${TABLE_DEPS} ps_framework_proto)


cc_library(table SRCS table.cc DEPS common_table tensor_accessor tensor_table ps_framework_proto string_helper device_context gflags glog boost ctr_sparse_sgd)
cc_library(table SRCS table.cc DEPS common_table tensor_accessor tensor_table ps_framework_proto string_helper device_context gflags glog boost sparse_sgd_rule)
6 changes: 3 additions & 3 deletions paddle/fluid/distributed/table/depends/feature_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ class FixedFeatureValue {
std::vector<float> data_;
};

class CtrValueBlock {
class SparseTableShard {
public:
typedef typename robin_hood::unordered_map<uint64_t, FixedFeatureValue *>
map_type;
CtrValueBlock() {}
~CtrValueBlock() {}
SparseTableShard() {}
~SparseTableShard() {}

FixedFeatureValue *Init(const uint64_t &id) {
size_t hash = hasher_(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "paddle/fluid/distributed/table/ctr_sparse_sgd.h"
#include "paddle/fluid/distributed/table/sparse_sgd_rule.h"
#include <gflags/gflags.h>
#include "glog/logging.h"

Expand All @@ -21,8 +21,8 @@ DEFINE_bool(enable_show_scale_gradient, true, "enable show scale gradient");
namespace paddle {
namespace distributed {

void CtrSparseNaiveSGDRule::load_config(
const SparseCommonSGDRuleParameter& param, size_t emb_dim) {
void SparseNaiveSGDRule::load_config(const SparseCommonSGDRuleParameter& param,
size_t emb_dim) {
_embedding_dim = emb_dim;
auto naive_param = param.naive();
learning_rate_ = naive_param.learning_rate();
Expand All @@ -39,17 +39,17 @@ void CtrSparseNaiveSGDRule::load_config(
}
}

void CtrSparseNaiveSGDRule::update_value_work(float* w, float* sgd,
const float* push_value,
float scale) {
void SparseNaiveSGDRule::update_value_work(float* w, float* sgd,
const float* push_value,
float scale) {
for (size_t i = 0; i < _embedding_dim; ++i) {
w[i] -= learning_rate_ * push_value[i];
bound_value(w[i]);
}
}

void CtrSparseNaiveSGDRule::init_value_work(float* value, float* sgd,
bool zero_init) {
void SparseNaiveSGDRule::init_value_work(float* value, float* sgd,
bool zero_init) {
if (zero_init) {
for (size_t i = 0; i < _embedding_dim; ++i) {
value[i] = 0;
Expand All @@ -64,7 +64,7 @@ void CtrSparseNaiveSGDRule::init_value_work(float* value, float* sgd,
}
}
}
void CtrSparseAdaGradSGDRule::load_config(
void SparseAdaGradSGDRule::load_config(
const SparseCommonSGDRuleParameter& param, size_t emb_dim) {
_embedding_dim = emb_dim;
auto adagrad_param = param.adagrad();
Expand All @@ -84,9 +84,8 @@ void CtrSparseAdaGradSGDRule::load_config(
}
}

void CtrSparseAdaGradSGDRule::update_value_work(float* w, float* sgd,
const float* grad,
float scale) {
void SparseAdaGradSGDRule::update_value_work(float* w, float* sgd,
const float* grad, float scale) {
float& g2sum = sgd[g2sum_index()];
double add_g2sum = 0;

Expand All @@ -101,8 +100,8 @@ void CtrSparseAdaGradSGDRule::update_value_work(float* w, float* sgd,
g2sum += add_g2sum / _embedding_dim;
}

void CtrSparseAdaGradSGDRule::init_value_work(float* value, float* sgd,
bool zero_init) {
void SparseAdaGradSGDRule::init_value_work(float* value, float* sgd,
bool zero_init) {
for (int i = 0; i < _embedding_dim; ++i) {
if (zero_init) {
value[i] = 0.0;
Expand All @@ -119,8 +118,8 @@ void CtrSparseAdaGradSGDRule::init_value_work(float* value, float* sgd,
sgd[g2sum_index()] = 0;
}

void CtrStdAdaGradSGDRule::load_config(
const SparseCommonSGDRuleParameter& param, size_t emb_dim) {
void StdAdaGradSGDRule::load_config(const SparseCommonSGDRuleParameter& param,
size_t emb_dim) {
_embedding_dim = emb_dim;
auto adagrad_param = param.adagrad();
learning_rate_ = adagrad_param.learning_rate();
Expand All @@ -139,8 +138,8 @@ void CtrStdAdaGradSGDRule::load_config(
}
}

void CtrStdAdaGradSGDRule::update_value_work(float* w, float* sgd,
const float* grad, float scale) {
void StdAdaGradSGDRule::update_value_work(float* w, float* sgd,
const float* grad, float scale) {
for (int i = 0; i < _embedding_dim; i++) {
float& g2sum = sgd[g2sum_index() + i];
double scaled_grad = grad[i] / scale;
Expand All @@ -151,8 +150,8 @@ void CtrStdAdaGradSGDRule::update_value_work(float* w, float* sgd,
}
}

void CtrStdAdaGradSGDRule::init_value_work(float* value, float* sgd,
bool zero_init) {
void StdAdaGradSGDRule::init_value_work(float* value, float* sgd,
bool zero_init) {
for (int i = 0; i < _embedding_dim; ++i) {
if (zero_init) {
value[i] = 0.0;
Expand All @@ -169,8 +168,8 @@ void CtrStdAdaGradSGDRule::init_value_work(float* value, float* sgd,
}
}

void CtrSparseAdamSGDRule::load_config(
const SparseCommonSGDRuleParameter& param, size_t emb_dim) {
void SparseAdamSGDRule::load_config(const SparseCommonSGDRuleParameter& param,
size_t emb_dim) {
_embedding_dim = emb_dim;
auto adam_param = param.adam();
learning_rate_ = adam_param.learning_rate();
Expand All @@ -190,8 +189,8 @@ void CtrSparseAdamSGDRule::load_config(
}
}

void CtrSparseAdamSGDRule::update_value_work(float* w, float* sgd,
const float* grad, float scale) {
void SparseAdamSGDRule::update_value_work(float* w, float* sgd,
const float* grad, float scale) {
float* gsum = sgd + gsum_index();
float* g2sum = sgd + g2sum_index();
float* beta1_pow = sgd + beta1_pow_index();
Expand All @@ -217,8 +216,8 @@ void CtrSparseAdamSGDRule::update_value_work(float* w, float* sgd,
(*beta2_pow) *= _beta2_decay_rate;
}

void CtrSparseAdamSGDRule::init_value_work(float* value, float* sgd,
bool zero_init) {
void SparseAdamSGDRule::init_value_work(float* value, float* sgd,
bool zero_init) {
for (int i = 0; i < _embedding_dim; ++i) {
if (zero_init) {
value[i] = 0.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
namespace paddle {
namespace distributed {

class CtrSparseValueSGDRule {
class SparseValueSGDRule {
public:
CtrSparseValueSGDRule() {}
virtual ~CtrSparseValueSGDRule() {}
SparseValueSGDRule() {}
virtual ~SparseValueSGDRule() {}
virtual void load_config(const SparseCommonSGDRuleParameter& param,
size_t emb_dim) {
_embedding_dim = emb_dim;
Expand Down Expand Up @@ -66,9 +66,9 @@ class CtrSparseValueSGDRule {
std::string _name;
};

REGISTER_PSCORE_REGISTERER(CtrSparseValueSGDRule);
REGISTER_PSCORE_REGISTERER(SparseValueSGDRule);

class CtrSparseNaiveSGDRule : public CtrSparseValueSGDRule {
class SparseNaiveSGDRule : public SparseValueSGDRule {
public:
virtual void load_config(const SparseCommonSGDRuleParameter& param,
size_t emb_dim);
Expand All @@ -81,7 +81,7 @@ class CtrSparseNaiveSGDRule : public CtrSparseValueSGDRule {
float learning_rate_;
};

class CtrSparseAdaGradSGDRule : public CtrSparseValueSGDRule {
class SparseAdaGradSGDRule : public SparseValueSGDRule {
public:
virtual void load_config(const SparseCommonSGDRuleParameter& param,
size_t emb_dim);
Expand All @@ -96,7 +96,7 @@ class CtrSparseAdaGradSGDRule : public CtrSparseValueSGDRule {
float _initial_g2sum;
};

class CtrStdAdaGradSGDRule : public CtrSparseValueSGDRule {
class StdAdaGradSGDRule : public SparseValueSGDRule {
public:
virtual void load_config(const SparseCommonSGDRuleParameter& param,
size_t emb_dim);
Expand All @@ -111,7 +111,7 @@ class CtrStdAdaGradSGDRule : public CtrSparseValueSGDRule {
float _initial_g2sum;
};

class CtrSparseAdamSGDRule : public CtrSparseValueSGDRule {
class SparseAdamSGDRule : public SparseValueSGDRule {
public:
virtual void load_config(const SparseCommonSGDRuleParameter& param,
size_t emb_dim);
Expand Down
8 changes: 4 additions & 4 deletions paddle/fluid/distributed/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ cc_test(brpc_utils_test SRCS brpc_utils_test.cc DEPS brpc_utils scope math_funct
set_source_files_properties(graph_node_test.cc PROPERTIES COMPILE_FLAGS ${DISTRIBUTE_COMPILE_FLAGS})
cc_test(graph_node_test SRCS graph_node_test.cc DEPS graph_py_service scope server client communicator ps_service boost table ps_framework_proto ${COMMON_DEPS})

set_source_files_properties(ctr_large_scale_test.cc PROPERTIES COMPILE_FLAGS ${DISTRIBUTE_COMPILE_FLAGS})
cc_test(ctr_large_scale_test SRCS ctr_large_scale_test.cc DEPS ${COMMON_DEPS} boost table)
set_source_files_properties(feature_value_test.cc PROPERTIES COMPILE_FLAGS ${DISTRIBUTE_COMPILE_FLAGS})
cc_test(feature_value_test SRCS feature_value_test.cc DEPS ${COMMON_DEPS} boost table)

set_source_files_properties(ctr_sparse_sgd_test.cc PROPERTIES COMPILE_FLAGS ${DISTRIBUTE_COMPILE_FLAGS})
cc_test(ctr_sparse_sgd_test SRCS ctr_sparse_sgd_test.cc DEPS ${COMMON_DEPS} boost table)
set_source_files_properties(sparse_sgd_rule_test.cc PROPERTIES COMPILE_FLAGS ${DISTRIBUTE_COMPILE_FLAGS})
cc_test(sparse_sgd_rule_test SRCS sparse_sgd_rule_test.cc DEPS ${COMMON_DEPS} boost table)
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ namespace paddle {
namespace distributed {

TEST(BENCHMARK, LargeScaleKV) {
std::shared_ptr<CtrValueBlock> shard = std::make_shared<CtrValueBlock>();
std::shared_ptr<SparseTableShard> shard =
std::make_shared<SparseTableShard>();
uint64_t key = 1;
auto itr = shard->Find(key);
ASSERT_TRUE(itr == shard->end());
Expand Down
Loading

0 comments on commit d7ee7f6

Please sign in to comment.