提交 37594eae 编写于 作者: Q qiaolongfei

add paramConfig for each parameter

上级 dc458a0d
...@@ -76,7 +76,5 @@ retry: ...@@ -76,7 +76,5 @@ retry:
fail(); fail();
} }
printf("test success!\n");
return 0; return 0;
} }
...@@ -21,7 +21,7 @@ void print_parameter(paddle_gradient* param) { ...@@ -21,7 +21,7 @@ void print_parameter(paddle_gradient* param) {
printf("content_len: %d\n", param->content_len); printf("content_len: %d\n", param->content_len);
printf("content_type: %d\n", param->element_type); printf("content_type: %d\n", param->element_type);
int i; int i;
for (i = 0; i < param->content_len / sizeof(real); ++i) { for (i = 0; i < param->content_len / (int)sizeof(real); ++i) {
printf("%f ", ((float*)param->content)[i]); printf("%f ", ((float*)param->content)[i]);
} }
printf("\n\n"); printf("\n\n");
...@@ -110,6 +110,5 @@ retry: ...@@ -110,6 +110,5 @@ retry:
fail(); fail();
} }
printf("test success!\n");
return 0; return 0;
} }
...@@ -32,7 +32,6 @@ int update_SGD(void* optimizer, ...@@ -32,7 +32,6 @@ int update_SGD(void* optimizer,
const void* gradient, const void* gradient,
int num_bytes) { int num_bytes) {
SGD_optimizer* o = (SGD_optimizer*)optimizer; SGD_optimizer* o = (SGD_optimizer*)optimizer;
// TODO(a simple SGD implement)
float* parameter = (float*)buffer; float* parameter = (float*)buffer;
float* grad = (float*)gradient; float* grad = (float*)gradient;
......
...@@ -29,10 +29,6 @@ type Parameter struct { ...@@ -29,10 +29,6 @@ type Parameter struct {
Content []byte Content []byte
} }
func (p *Parameter) toString() {
fmt.Println(p.Name, p.ElementType, p.Content)
}
// ParameterWithConfig contains the parameter and the configuration. // ParameterWithConfig contains the parameter and the configuration.
type ParameterWithConfig struct { type ParameterWithConfig struct {
Param Parameter Param Parameter
...@@ -53,7 +49,7 @@ type Service struct { ...@@ -53,7 +49,7 @@ type Service struct {
// NewService creates a new service. // NewService creates a new service.
func NewService() *Service { func NewService() *Service {
s := &Service{opt: newOptimizer(sgd, 0.01)} s := &Service{opt: newOptimizer(sgd, 0.005)}
s.paramMap = make(map[string]Parameter) s.paramMap = make(map[string]Parameter)
s.initialized = make(chan struct{}) s.initialized = make(chan struct{})
return s return s
......
...@@ -31,7 +31,6 @@ NewRemoteParameterUpdater::NewRemoteParameterUpdater( ...@@ -31,7 +31,6 @@ NewRemoteParameterUpdater::NewRemoteParameterUpdater(
void NewRemoteParameterUpdater::init( void NewRemoteParameterUpdater::init(
const std::vector<ParameterPtr> &parameters) { const std::vector<ParameterPtr> &parameters) {
ParameterUpdater::init(parameters); ParameterUpdater::init(parameters);
LOG(INFO) << "NewRemoteParameterUpdater init in";
for (auto &para : parameters_) { for (auto &para : parameters_) {
para->getBuf(PARAMETER_VALUE)->zeroMem(); para->getBuf(PARAMETER_VALUE)->zeroMem();
...@@ -58,7 +57,12 @@ void NewRemoteParameterUpdater::init( ...@@ -58,7 +57,12 @@ void NewRemoteParameterUpdater::init(
if (paddle_begin_init_params(parameterClient_)) { if (paddle_begin_init_params(parameterClient_)) {
LOG(INFO) << "paddle_begin_init_params start"; LOG(INFO) << "paddle_begin_init_params start";
for (int i = 0; i < parameterSize(); ++i) { for (int i = 0; i < parameterSize(); ++i) {
paddle_init_param(parameterClient_, *newParameters_[i], NULL, 0); auto paramConfig = parameters_[i]->getConfig();
std::string bytes = paramConfig.SerializeAsString();
const char *array = bytes.data();
int size = (int)bytes.size();
paddle_init_param(
parameterClient_, *newParameters_[i], (void *)array, size);
} }
paddle_finish_init_params(parameterClient_); paddle_finish_init_params(parameterClient_);
LOG(INFO) << "paddle_begin_init_params done"; LOG(INFO) << "paddle_begin_init_params done";
......
...@@ -84,7 +84,6 @@ private: ...@@ -84,7 +84,6 @@ private:
for (int i = 0; i < parameterSize(); ++i) { for (int i = 0; i < parameterSize(); ++i) {
ParameterPtr param = parameters_[i]; ParameterPtr param = parameters_[i];
new_params[i]->content_len = 10;
new_params[i]->element_type = PADDLE_ELEMENT_TYPE_FLOAT32; new_params[i]->element_type = PADDLE_ELEMENT_TYPE_FLOAT32;
new_params[i]->name = (char*)param->getName().c_str(); new_params[i]->name = (char*)param->getName().c_str();
new_params[i]->content = new_params[i]->content =
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册