Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
11660eab
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
提交
11660eab
编写于
7月 13, 2017
作者:
H
Helin Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix optimizer parameter buffer allocation size.
The buffer allocation size should be number of bytes, not number of floats.
上级
3c5cc644
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
34 addition
and
26 deletion
+34
-26
go/pserver/client/client_test.go
go/pserver/client/client_test.go
+7
-6
go/pserver/optimizer.go
go/pserver/optimizer.go
+8
-2
go/pserver/service_test.go
go/pserver/service_test.go
+15
-15
paddle/optimizer/optimizer.cc
paddle/optimizer/optimizer.cc
+4
-3
未找到文件。
go/pserver/client/client_test.go
浏览文件 @
11660eab
...
...
@@ -100,13 +100,13 @@ func (l lister) List() []client.Server {
return
l
}
func
ClientTes
t
(
t
*
testing
.
T
,
c
*
client
.
Client
)
{
func
testClien
t
(
t
*
testing
.
T
,
c
*
client
.
Client
)
{
selected
:=
c
.
BeginInitParams
()
if
!
selected
{
t
.
Fatal
(
"should be selected."
)
}
const
numParameter
=
100
const
numParameter
=
100
0
config
,
err
:=
ioutil
.
ReadFile
(
"./c/test/testdata/optimizer.pb"
)
if
err
!=
nil
{
t
.
Fatalf
(
"read optimizer proto failed"
)
...
...
@@ -128,7 +128,7 @@ func ClientTest(t *testing.T, c *client.Client) {
}
var
grads
[]
pserver
.
Gradient
for
i
:=
0
;
i
<
numParameter
/
2
;
i
++
{
for
i
:=
0
;
i
<
numParameter
;
i
++
{
var
g
pserver
.
Gradient
g
.
Name
=
"p_"
+
strconv
.
Itoa
(
i
)
g
.
ElementType
=
pserver
.
Float32
...
...
@@ -169,13 +169,14 @@ func TestNativeClient(t *testing.T) {
servers
[
i
]
=
client
.
Server
{
Index
:
i
,
Addr
:
":"
+
strconv
.
Itoa
(
pserverClientPorts
[
i
])}
}
c1
:=
client
.
NewClient
(
lister
(
servers
),
len
(
servers
),
selector
(
true
))
ClientTes
t
(
t
,
c1
)
testClien
t
(
t
,
c1
)
}
// TODO: tmperary disable etcdClient test for dependency of etcd)
// EtcdClient is a disabled test, since we have not embedded etcd into
// our test.
func
EtcdClient
(
t
*
testing
.
T
)
{
initEtcdClient
()
etcdClient
:=
client
.
NewEtcd
(
etcdEndpoints
)
c2
:=
client
.
NewClient
(
etcdClient
,
etcdClient
.
Desired
(),
selector
(
true
))
ClientTes
t
(
t
,
c2
)
testClien
t
(
t
,
c2
)
}
go/pserver/optimizer.go
浏览文件 @
11660eab
...
...
@@ -19,6 +19,7 @@ var nullPtr = unsafe.Pointer(uintptr(0))
type
optimizer
struct
{
opt
*
C
.
struct_paddle_optimizer
elementType
ElementType
contentLen
int
}
func
cArrayToSlice
(
p
unsafe
.
Pointer
,
len
int
)
[]
byte
{
...
...
@@ -37,10 +38,11 @@ func cArrayToSlice(p unsafe.Pointer, len int) []byte {
func
newOptimizer
(
paramWithConfigs
ParameterWithConfig
,
State
[]
byte
)
*
optimizer
{
o
:=
&
optimizer
{}
o
.
elementType
=
paramWithConfigs
.
Param
.
ElementType
o
.
contentLen
=
len
(
paramWithConfigs
.
Param
.
Content
)
p
:=
paramWithConfigs
.
Param
c
:=
paramWithConfigs
.
Config
s
:=
State
paramBufferSize
:=
C
.
size_t
(
len
(
p
.
Content
)
/
C
.
sizeof_float
)
paramBufferSize
:=
C
.
size_t
(
len
(
p
.
Content
))
log
.
WithFields
(
log
.
Fields
{
"ElementType"
:
p
.
ElementType
,
"ParamSize"
:
paramBufferSize
,
...
...
@@ -78,7 +80,11 @@ func (o *optimizer) UpdateParameter(g Gradient) error {
return
fmt
.
Errorf
(
"Name: %s, parameter and gradient element type not match, parameter: %v, gradient: %v"
,
g
.
Name
,
o
.
elementType
,
g
.
ElementType
)
}
r
:=
C
.
paddle_update_parameter
(
o
.
opt
,
C
.
paddle_element_type
(
g
.
ElementType
),
unsafe
.
Pointer
(
&
g
.
Content
[
0
]),
C
.
int
(
len
(
g
.
Content
))
/
C
.
sizeof_float
)
if
o
.
contentLen
!=
len
(
g
.
Content
)
{
return
fmt
.
Errorf
(
"Name: %s, parameter and gradient does not have same content len, parameter: %d, gradient: %d"
,
g
.
Name
,
o
.
contentLen
,
len
(
g
.
Content
))
}
r
:=
C
.
paddle_update_parameter
(
o
.
opt
,
C
.
paddle_element_type
(
g
.
ElementType
),
unsafe
.
Pointer
(
&
g
.
Content
[
0
]),
C
.
int
(
len
(
g
.
Content
)))
if
r
!=
0
{
return
fmt
.
Errorf
(
"optimizer update returned error code: %d"
,
r
)
}
...
...
go/pserver/service_test.go
浏览文件 @
11660eab
...
...
@@ -31,7 +31,7 @@ func TestServiceFull(t *testing.T) {
err
=
s
.
InitParam
(
pserver
.
ParameterWithConfig
{
Param
:
p
,
Config
:
config
},
nil
)
if
err
!=
nil
{
t
.
Fa
ilNow
(
)
t
.
Fa
tal
(
err
)
}
var
p1
pserver
.
Parameter
...
...
@@ -40,40 +40,40 @@ func TestServiceFull(t *testing.T) {
p1
.
ElementType
=
pserver
.
Float32
err
=
s
.
InitParam
(
pserver
.
ParameterWithConfig
{
Param
:
p1
,
Config
:
config
},
nil
)
if
err
!=
nil
{
t
.
Fa
ilNow
(
)
t
.
Fa
tal
(
err
)
}
err
=
s
.
FinishInitParams
(
0
,
nil
)
if
err
!=
nil
{
t
.
Fa
ilNow
(
)
t
.
Fa
tal
(
err
)
}
var
param
pserver
.
Parameter
err
=
s
.
GetParam
(
"param_b"
,
&
param
)
if
err
!=
nil
{
t
.
Fa
ilNow
(
)
t
.
Fa
tal
(
err
)
}
if
!
reflect
.
DeepEqual
(
param
,
p1
)
{
t
.
Fa
ilNow
(
)
t
.
Fa
tal
(
"not equal:"
,
param
,
p1
)
}
g1
,
g2
:=
pserver
.
Gradient
(
p1
),
pserver
.
Gradient
(
p
)
err
=
s
.
SendGrad
(
g1
,
nil
)
if
err
!=
nil
{
t
.
Fa
ilNow
(
)
t
.
Fa
tal
(
err
)
}
err
=
s
.
SendGrad
(
g2
,
nil
)
if
err
!=
nil
{
t
.
Fa
ilNow
(
)
t
.
Fa
tal
(
err
)
}
var
param1
pserver
.
Parameter
err
=
s
.
GetParam
(
"param_a"
,
&
param1
)
if
err
!=
nil
{
t
.
Fa
ilNow
(
)
t
.
Fa
tal
(
err
)
}
// don't compare content, since it's already changed by
...
...
@@ -82,7 +82,7 @@ func TestServiceFull(t *testing.T) {
p
.
Content
=
nil
if
!
reflect
.
DeepEqual
(
param1
,
p
)
{
t
.
Fa
ilNow
(
)
t
.
Fa
tal
(
"not equal:"
,
param1
,
p
)
}
}
...
...
@@ -90,16 +90,16 @@ func TestMultipleInit(t *testing.T) {
var
cp
pserver
.
Checkpoint
s
,
err
:=
pserver
.
NewService
(
0
,
1
,
""
,
nil
,
cp
)
if
err
!=
nil
{
t
.
Error
(
err
)
t
.
Fatal
(
err
)
}
err
=
s
.
FinishInitParams
(
0
,
nil
)
if
err
!=
nil
{
t
.
Fa
ilNow
(
)
t
.
Fa
tal
(
err
)
}
err
=
s
.
FinishInitParams
(
0
,
nil
)
if
err
.
Error
()
!=
pserver
.
AlreadyInitialized
{
t
.
Fa
ilNow
(
)
t
.
Fa
tal
(
err
)
}
}
...
...
@@ -108,7 +108,7 @@ func TestUninitialized(t *testing.T) {
s
,
err
:=
pserver
.
NewService
(
0
,
1
,
""
,
nil
,
cp
)
err
=
s
.
SendGrad
(
pserver
.
Gradient
{},
nil
)
if
err
.
Error
()
!=
pserver
.
Uninitialized
{
t
.
Fa
ilNow
(
)
t
.
Fa
tal
(
err
)
}
}
...
...
@@ -154,12 +154,12 @@ func TestBlockUntilInitialized(t *testing.T) {
err
=
s
.
InitParam
(
pserver
.
ParameterWithConfig
{
Param
:
p
,
Config
:
config
},
nil
)
if
err
!=
nil
{
t
.
Fa
ilNow
(
)
t
.
Fa
tal
(
err
)
}
err
=
s
.
FinishInitParams
(
0
,
nil
)
if
err
!=
nil
{
t
.
Fa
ilNow
(
)
t
.
Fa
tal
(
err
)
}
wg
.
Wait
()
...
...
paddle/optimizer/optimizer.cc
浏览文件 @
11660eab
...
...
@@ -44,8 +44,8 @@ paddle_optimizer* paddle_create_optimizer(const unsigned char* config_proto,
const
int
state_len
)
{
paddle_optimizer
*
optimizer
=
new
paddle_optimizer
;
std
::
string
config
(
config_proto
,
config_proto
+
config_proto_len
);
Tensor
*
parameter
=
new
Tensor
(
reinterpret_cast
<
float
*>
(
param_buffer
),
num_bytes
);
Tensor
*
parameter
=
new
Tensor
(
reinterpret_cast
<
float
*>
(
param_buffer
),
num_bytes
/
sizeof
(
float
)
);
optimizer
->
impl
=
ParameterOptimizer
::
Create
(
config
,
parameter
);
if
(
state
!=
nullptr
)
{
std
::
string
s
(
state
,
state
+
state_len
);
...
...
@@ -65,7 +65,8 @@ int paddle_update_parameter(paddle_optimizer* o,
int
num_bytes
)
{
// TOOD(zhihong): datatype not work. need to add the runtime datatype
auto
grad_type
=
reinterpret_cast
<
const
float
*>
(
grad_buffer
);
Tensor
*
gradient
=
new
Tensor
(
const_cast
<
float
*>
(
grad_type
),
num_bytes
);
Tensor
*
gradient
=
new
Tensor
(
const_cast
<
float
*>
(
grad_type
),
num_bytes
/
sizeof
(
float
));
o
->
impl
->
Update
(
gradient
);
return
PADDLE_SUCCESS
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录