-
Notifications
You must be signed in to change notification settings - Fork 5.9k
integrate Go with optimizer library #2560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
go/pserver/cclient/cclient.go
Outdated
| content := cArrayToSlice(unsafe.Pointer(param.content), int(param.content_len)) | ||
| pc := pserver.ParameterWithConfig{ | ||
| Param: pserver.Parameter{Name: name, ElementType: et, Content: content}, | ||
| Param: pserver.Parameter{Name: name, ElementType: et, Content: param.content, Length: para.content_len}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think para is not defined. Does this code compiles?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix done. sorry for the typo mistake, can not pass the go link problem yesterday.
| @@ -0,0 +1,13 @@ | |||
| import OptimizerConfig_pb2 as pb | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this used to generate a proto encoded file? If we only need the generated proto file, maybe we can just check the generated file under testdata folder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix done.
go/pserver/optimizer.go
Outdated
| o.opt = C.paddle_create_SGD_optimizer(C.double(learning_rate)) | ||
| p := paramWithConfigs.Param | ||
| c := paramWithConfigs.Config | ||
| o.opt = C.paddle_create_optimizer(C.uchar(c), C.int(len(c)), unsafe.Pointer(p.Content), c.int(p.Length), nullPtr, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
paddle_create_optimizer takes the ownership of the param_buffer argument. So this does not work, because p.Content is a Go pointer, which is tracked by Go garbage collector, it will be garbage collected. We need to make a copy here.
For more pointer information please see: https://golang.org/cmd/cgo/#hdr-Passing_pointers
Another question is what is the benefit of changing the type of p.Content from []byte to *byte:
- Before when
p.Contenthave[]byteas type, inpaddle_send_gradsthecArrayToSlicefunction does not make a copy of the gradient buffer. It just use the buffer as underlying storage of the created slice. So changing the type to*bytedoes not improve performance. - At this line of code, we have to make a copy anyway.
I could be wrong, but I don't see any benefit of changing the type of p.Content from []byte to *byte, it comes with added complexity: need a separate variable p.Length to track length. Plus Go programmers are more familiar with slice ([]byte) than byte pointers (*byte).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. fix the copy done.
Another question is what is the benefit of changing the type of p.Content from []byte to *byte
there is no benefit, c style language prefers pointer type. fix it
go/pserver/service.go
Outdated
| opt *optimizer | ||
| mu sync.Mutex | ||
| // injection from parameter to optimizer | ||
| optMap map[string]*optimizer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we already have optMap and Optimizer owns the parameter memory, we no longer need paramMap.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true. fixed
|
it is accidentally closed after a force update when I resolved confict. l had tried many methods, it can not be reopened, weird : ( |
|
If there is any method that can force update the branch and reopen this PR, Please let me know. |
fix2516