提交 a2fabcc1 编写于 作者: D dongzhihong

"fix client test"

上级 b49c9baa
package pserver_test package pserver_test
import ( import (
"io/ioutil"
"net" "net"
"net/http" "net/http"
"net/rpc" "net/rpc"
...@@ -71,18 +72,22 @@ func TestClientFull(t *testing.T) { ...@@ -71,18 +72,22 @@ func TestClientFull(t *testing.T) {
} }
const numParameter = 100 const numParameter = 100
config, err := ioutil.ReadFile("./cclient/test/testdata/optimizer.pb.txt")
if err != nil {
t.Fatalf("read optimizer proto failed")
}
for i := 0; i < numParameter; i++ { for i := 0; i < numParameter; i++ {
var p pserver.Parameter var p pserver.Parameter
p.Name = "p_" + strconv.Itoa(i) p.Name = "p_" + strconv.Itoa(i)
p.ElementType = pserver.Float32 p.ElementType = pserver.Float32
p.Content = make([]byte, (i+1)*100) p.Content = make([]byte, (i+1)*100)
err := c.InitParam(pserver.ParameterWithConfig{Param: p}) err := c.InitParam(pserver.ParameterWithConfig{Param: p, Config: config})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }
err := c.FinishInitParams() err = c.FinishInitParams()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
......
...@@ -61,6 +61,7 @@ func (o *optimizer) UpdateParameter(g Gradient) error { ...@@ -61,6 +61,7 @@ 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) return fmt.Errorf("Name: %s, parameter and gradient element type not match, parameter: %v, gradient: %v", g.Name, o.ElementType, g.ElementType)
} }
fmt.Println(g)
r := C.paddle_update_parameter(o.opt, C.paddle_element_type(g.ElementType), unsafe.Pointer(&g.Content[0]), C.int(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 { if r != 0 {
return fmt.Errorf("optimizer update returned error code: %d", r) return fmt.Errorf("optimizer update returned error code: %d", r)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册