Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
28476f5f
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
28476f5f
编写于
6月 09, 2017
作者:
Q
qiaolongfei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix the problem of paddle_send_grad
上级
6f1c91da
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
85 addition
and
39 deletion
+85
-39
go/pserver/cclient/cclient.go
go/pserver/cclient/cclient.go
+2
-2
go/pserver/cclient/test/main.c
go/pserver/cclient/test/main.c
+45
-5
paddle/trainer/NewRemoteParameterUpdater.cpp
paddle/trainer/NewRemoteParameterUpdater.cpp
+6
-2
paddle/trainer/NewRemoteParameterUpdater.h
paddle/trainer/NewRemoteParameterUpdater.h
+32
-30
未找到文件。
go/pserver/cclient/cclient.go
浏览文件 @
28476f5f
...
...
@@ -164,10 +164,10 @@ func paddle_finish_init_params(client C.client) C.int {
}
//export paddle_send_grads
func
paddle_send_grads
(
client
C
.
client
,
grads
*
C
.
paddle_gradient
,
total
C
.
int
)
C
.
int
{
func
paddle_send_grads
(
client
C
.
client
,
grads
*
*
C
.
paddle_gradient
,
total
C
.
int
)
C
.
int
{
var
gs
[]
pserver
.
Gradient
for
i
:=
0
;
i
<
int
(
total
);
i
++
{
grad
:=
(
*
C
.
paddle_gradient
)(
unsafe
.
Pointer
((
uintptr
(
unsafe
.
Pointer
(
grads
))
+
uintptr
(
i
)
*
unsafe
.
Sizeof
(
*
grads
))))
grad
:=
*
(
*
*
C
.
paddle_gradient
)(
unsafe
.
Pointer
((
uintptr
(
unsafe
.
Pointer
(
grads
))
+
uintptr
(
i
)
*
unsafe
.
Sizeof
(
*
grads
))))
et
:=
pserver
.
ElementType
(
grad
.
element_type
)
name
:=
C
.
GoString
(
grad
.
name
)
content
:=
cArrayToSlice
(
unsafe
.
Pointer
(
grad
.
content
),
int
(
grad
.
content_len
))
...
...
go/pserver/cclient/test/main.c
浏览文件 @
28476f5f
#include <stdio.h>
#include <stdlib.h>
#include "libpaddle_pserver_cclient.h"
...
...
@@ -9,6 +10,21 @@ void fail() {
exit
(
-
1
);
}
void
print_parameter
(
paddle_gradient
*
param
)
{
if
(
param
==
NULL
)
{
printf
(
"param is NULL!!
\n
"
);
}
else
{
printf
(
"==== parameter ====
\n
"
);
printf
(
"name: %s
\n
"
,
param
->
name
);
printf
(
"content_len: %d
\n
"
,
param
->
content_len
);
printf
(
"content_type: %d
\n
"
,
param
->
element_type
);
for
(
int
i
=
0
;
i
<
param
->
content_len
;
++
i
)
{
printf
(
"0x%x "
,
param
->
content
[
i
]);
}
printf
(
"
\n
"
);
}
}
int
main
()
{
char
addr
[]
=
"localhost:3000"
;
client
c
=
paddle_new_pserver_client
(
addr
,
1
);
...
...
@@ -40,12 +56,27 @@ retry:
fail
();
}
unsigned
char
content
[]
=
{
0x00
,
0x11
,
0x22
};
paddle_gradient
grads
[
2
]
=
{
{
"param_a"
,
PADDLE_ELEMENT_TYPE_FLOAT32
,
content
,
3
},
{
"param_b"
,
PADDLE_ELEMENT_TYPE_INT32
,
content
,
3
}};
unsigned
char
content1
[]
=
{
0x12
,
0x23
,
0x34
};
unsigned
char
content2
[]
=
{
0x45
,
0x56
,
0x67
};
paddle_gradient
**
new_params
=
(
paddle_gradient
**
)
malloc
(
sizeof
(
paddle_gradient
*
)
*
2
);
new_params
[
0
]
=
(
paddle_gradient
*
)
malloc
(
sizeof
(
paddle_gradient
));
new_params
[
0
]
->
name
=
"param_a"
;
new_params
[
0
]
->
content
=
content1
;
new_params
[
0
]
->
content_len
=
3
;
new_params
[
0
]
->
element_type
=
PADDLE_ELEMENT_TYPE_FLOAT32
;
if
(
paddle_send_grads
(
c
,
grads
,
2
)
!=
0
)
{
new_params
[
1
]
=
(
paddle_gradient
*
)
malloc
(
sizeof
(
paddle_gradient
));
new_params
[
1
]
->
name
=
"param_b"
;
new_params
[
1
]
->
content
=
content2
;
new_params
[
1
]
->
content_len
=
3
;
new_params
[
1
]
->
element_type
=
PADDLE_ELEMENT_TYPE_INT32
;
print_parameter
(
new_params
[
0
]);
print_parameter
(
new_params
[
1
]);
if
(
paddle_send_grads
(
c
,
new_params
,
2
)
!=
0
)
{
fail
();
}
...
...
@@ -55,6 +86,15 @@ retry:
fail
();
}
print_parameter
(
params
[
0
]);
print_parameter
(
params
[
1
]);
/// change name of parameter.
char
*
names2
[]
=
{
"param_1"
,
"param_2"
};
if
(
paddle_get_params
(
c
,
names2
,
params
,
2
)
==
0
)
{
fail
();
}
// get parameters again by reusing the allocated parameter buffers.
if
(
paddle_get_params
(
c
,
names
,
params
,
2
)
!=
0
)
{
fail
();
...
...
paddle/trainer/NewRemoteParameterUpdater.cpp
浏览文件 @
28476f5f
...
...
@@ -22,7 +22,11 @@ DECLARE_string(save_dir);
namespace
paddle
{
NewRemoteParameterUpdater
::
NewRemoteParameterUpdater
(
const
OptimizationConfig
&
config
,
const
std
::
string
pserverSpec
)
:
pserverSpec_
(
pserverSpec
)
{}
:
parameterClient_
(
-
1
),
newParameters_
(
nullptr
),
newGradients_
(
nullptr
),
names_
(
nullptr
),
pserverSpec_
(
pserverSpec
)
{}
void
NewRemoteParameterUpdater
::
init
(
const
std
::
vector
<
ParameterPtr
>
&
parameters
)
{
...
...
@@ -72,7 +76,7 @@ void NewRemoteParameterUpdater::finishBatch(real cost) {
LOG
(
INFO
)
<<
"finishBatch in, cost: "
<<
cost
;
// send gradient to parameter server.
paddle_send_grads
(
parameterClient_
,
*
newGradients_
,
parameterSize
());
paddle_send_grads
(
parameterClient_
,
newGradients_
,
parameterSize
());
// get the updated parameter from parameterClient.
paddle_get_params
(
parameterClient_
,
names_
,
newParameters_
,
parameterSize
());
...
...
paddle/trainer/NewRemoteParameterUpdater.h
浏览文件 @
28476f5f
...
...
@@ -32,6 +32,7 @@ public:
NewRemoteParameterUpdater
(
const
OptimizationConfig
&
config
,
const
std
::
string
pserverSpec
);
~
NewRemoteParameterUpdater
()
{
LOG
(
INFO
)
<<
"~NewRemoteParameterUpdater in"
;
releaseNewParameter
(
newParameters_
);
releaseNewParameter
(
newGradients_
);
if
(
parameterClient_
>=
0
)
paddle_pserver_client_release
(
parameterClient_
);
...
...
@@ -64,46 +65,47 @@ protected:
virtual
void
updateImpl
(
Parameter
*
para
);
private:
int
parameterSize
()
{
return
(
int
)
parameters_
.
size
();
}
int
parameterSize
()
{
return
(
int
)
parameters_
.
size
();
}
/**
* init parameter of
paddle pserver cclient.
* @param new_params
* @param type
*/
paddle_parameter
**
initNewParameter
(
ParameterType
type
)
{
paddle_parameter
**
new_params
=
(
paddle_parameter
**
)
malloc
(
sizeof
(
paddle_parameter
*
)
*
parameterSize
());
for
(
int
i
=
0
;
i
<
parameterSize
();
++
i
)
{
new_params
[
i
]
=
(
paddle_parameter
*
)
malloc
(
sizeof
(
paddle_parameter
));
memset
(
new_params
[
i
],
0
,
sizeof
(
paddle_parameter
));
}
/**
* init parameter of go
paddle pserver cclient.
* @param new_params
* @param type
*/
paddle_parameter
**
initNewParameter
(
ParameterType
type
)
{
paddle_parameter
**
new_params
=
(
paddle_parameter
**
)
malloc
(
sizeof
(
paddle_parameter
*
)
*
parameterSize
());
for
(
int
i
=
0
;
i
<
parameterSize
();
++
i
)
{
new_params
[
i
]
=
(
paddle_parameter
*
)
malloc
(
sizeof
(
paddle_parameter
));
memset
(
new_params
[
i
],
0
,
sizeof
(
paddle_parameter
));
}
for
(
int
i
=
0
;
i
<
parameterSize
();
++
i
)
{
ParameterPtr
param
=
parameters_
[
i
];
new_params
[
i
]
->
content_len
=
10
;
new_params
[
i
]
->
element_type
=
PADDLE_ELEMENT_TYPE_FLOAT32
;
new_params
[
i
]
->
name
=
(
char
*
)
param
->
getName
().
c_str
();
new_params
[
i
]
->
content
=
(
unsigned
char
*
)(
param
->
getBuf
(
type
).
get
()
->
getData
());
new_params
[
i
]
->
content_len
=
(
int
)
param
->
getBuf
(
type
).
get
()
->
getSize
();
}
return
new_params
;
for
(
int
i
=
0
;
i
<
parameterSize
();
++
i
)
{
ParameterPtr
param
=
parameters_
[
i
];
new_params
[
i
]
->
content_len
=
10
;
new_params
[
i
]
->
element_type
=
PADDLE_ELEMENT_TYPE_FLOAT32
;
new_params
[
i
]
->
name
=
(
char
*
)
param
->
getName
().
c_str
();
new_params
[
i
]
->
content
=
(
unsigned
char
*
)(
param
->
getBuf
(
type
).
get
()
->
getData
());
new_params
[
i
]
->
content_len
=
(
int
)
param
->
getBuf
(
type
).
get
()
->
getSize
();
}
return
new_params
;
}
void
releaseNewParameter
(
paddle_parameter
**
newParams
)
{
if
(
newParams
!=
NULL
)
{
for
(
int
i
=
0
;
i
<
parameterSize
();
++
i
)
{
paddle_release_param
(
newParams
[
i
]);
void
releaseNewParameter
(
paddle_parameter
**
newParams
)
{
if
(
newParams
!=
nullptr
)
{
for
(
int
i
=
0
;
i
<
parameterSize
();
++
i
)
{
auto
param
=
newParams
[
i
];
if
(
param
!=
nullptr
)
{
paddle_release_param
(
param
);
}
}
}
}
protected:
/// internal parameter client object for exchanging data with pserver
client
parameterClient_
=
-
1
;
client
parameterClient_
;
/// the parameters for new pserver client
paddle_parameter
**
newParameters_
;
/// the gradinets for new pserver client
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录