Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
777a5cca
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看板
提交
777a5cca
编写于
7月 13, 2017
作者:
H
Helin Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Client test: concurrently init param. Concurrently send grad and get param
上级
11660eab
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
68 addition
and
22 deletion
+68
-22
go/pserver/client/client_test.go
go/pserver/client/client_test.go
+68
-22
未找到文件。
go/pserver/client/client_test.go
浏览文件 @
777a5cca
...
@@ -3,11 +3,13 @@ package client_test
...
@@ -3,11 +3,13 @@ package client_test
import
(
import
(
"context"
"context"
"io/ioutil"
"io/ioutil"
"math/rand"
"net"
"net"
"net/http"
"net/http"
"net/rpc"
"net/rpc"
"strconv"
"strconv"
"strings"
"strings"
"sync"
"testing"
"testing"
"time"
"time"
...
@@ -111,16 +113,23 @@ func testClient(t *testing.T, c *client.Client) {
...
@@ -111,16 +113,23 @@ func testClient(t *testing.T, c *client.Client) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"read optimizer proto failed"
)
t
.
Fatalf
(
"read optimizer proto failed"
)
}
}
var
wg
sync
.
WaitGroup
for
i
:=
0
;
i
<
numParameter
;
i
++
{
for
i
:=
0
;
i
<
numParameter
;
i
++
{
var
p
pserver
.
Parameter
wg
.
Add
(
1
)
p
.
Name
=
"p_"
+
strconv
.
Itoa
(
i
)
go
func
(
i
int
)
{
p
.
ElementType
=
pserver
.
Float32
var
p
pserver
.
Parameter
p
.
Content
=
make
([]
byte
,
(
i
+
1
)
*
100
)
p
.
Name
=
"p_"
+
strconv
.
Itoa
(
i
)
err
:=
c
.
InitParam
(
pserver
.
ParameterWithConfig
{
Param
:
p
,
Config
:
config
})
p
.
ElementType
=
pserver
.
Float32
if
err
!=
nil
{
p
.
Content
=
make
([]
byte
,
(
i
+
1
)
*
100
)
t
.
Fatal
(
err
)
err
:=
c
.
InitParam
(
pserver
.
ParameterWithConfig
{
Param
:
p
,
Config
:
config
})
}
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
wg
.
Done
()
}(
i
)
}
}
wg
.
Wait
()
err
=
c
.
FinishInitParams
()
err
=
c
.
FinishInitParams
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -136,9 +145,31 @@ func testClient(t *testing.T, c *client.Client) {
...
@@ -136,9 +145,31 @@ func testClient(t *testing.T, c *client.Client) {
grads
=
append
(
grads
,
g
)
grads
=
append
(
grads
,
g
)
}
}
err
=
c
.
SendGrads
(
grads
)
const
paramPerGroup
=
10
if
err
!=
nil
{
const
numGroups
=
numParameter
/
paramPerGroup
t
.
Fatal
(
err
)
// shuffle send grads order
for
i
:=
range
grads
{
j
:=
rand
.
Intn
(
i
+
1
)
grads
[
i
],
grads
[
j
]
=
grads
[
j
],
grads
[
i
]
}
for
i
:=
0
;
i
<
numGroups
;
i
++
{
var
gs
[]
pserver
.
Gradient
if
i
==
numGroups
-
1
{
gs
=
grads
[
i
*
paramPerGroup
:
]
}
else
{
gs
=
grads
[
i
*
paramPerGroup
:
(
i
+
1
)
*
paramPerGroup
]
}
wg
.
Add
(
1
)
go
func
(
gs
[]
pserver
.
Gradient
)
{
err
=
c
.
SendGrads
(
gs
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
wg
.
Done
()
}(
gs
)
}
}
names
:=
make
([]
string
,
numParameter
)
names
:=
make
([]
string
,
numParameter
)
...
@@ -146,20 +177,35 @@ func testClient(t *testing.T, c *client.Client) {
...
@@ -146,20 +177,35 @@ func testClient(t *testing.T, c *client.Client) {
names
[
i
]
=
"p_"
+
strconv
.
Itoa
(
i
)
names
[
i
]
=
"p_"
+
strconv
.
Itoa
(
i
)
}
}
params
,
err
:=
c
.
GetParams
(
names
)
for
i
:=
0
;
i
<
numGroups
;
i
++
{
if
err
!=
nil
{
var
ns
[]
string
t
.
Fatal
(
err
)
if
i
==
numGroups
-
1
{
}
ns
=
names
[
i
*
paramPerGroup
:
]
}
else
{
ns
=
names
[
i
*
paramPerGroup
:
(
i
+
1
)
*
paramPerGroup
]
}
if
len
(
names
)
!=
len
(
params
)
{
wg
.
Add
(
1
)
t
.
Fatalf
(
"parameter size not match, need: %d, have: %d"
,
len
(
names
),
len
(
params
))
go
func
(
ns
[]
string
)
{
}
params
,
err
:=
c
.
GetParams
(
ns
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
for
i
:=
range
params
{
if
len
(
ns
)
!=
len
(
params
)
{
if
names
[
i
]
!=
params
[
i
]
.
Name
{
t
.
Fatalf
(
"parameter size not match, need: %d, have: %d"
,
len
(
names
),
len
(
params
))
t
.
Fatalf
(
"order of returned parameter does not required: parameter name: %s, required name: %s"
,
names
[
i
],
params
[
i
]
.
Name
)
}
}
for
i
:=
range
params
{
if
ns
[
i
]
!=
params
[
i
]
.
Name
{
t
.
Fatalf
(
"order of returned parameter does not required: parameter name: %s, required name: %s"
,
ns
[
i
],
params
[
i
]
.
Name
)
}
}
wg
.
Done
()
}(
ns
)
}
}
wg
.
Wait
()
}
}
func
TestNativeClient
(
t
*
testing
.
T
)
{
func
TestNativeClient
(
t
*
testing
.
T
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录