Skip to content
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

integrate Go with optimizer library #2560

Closed
wants to merge 0 commits into from

Conversation

dzhwinter
Copy link
Contributor

fix2516

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},
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

@helinwang helinwang Jun 22, 2017

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix done.

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)
Copy link
Contributor

@helinwang helinwang Jun 22, 2017

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.Content have []byte as type, in paddle_send_grads the cArrayToSlice function 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 *byte does 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).

Copy link
Contributor Author

@dzhwinter dzhwinter Jun 23, 2017

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

opt *optimizer
mu sync.Mutex
// injection from parameter to optimizer
optMap map[string]*optimizer
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true. fixed

@dzhwinter
Copy link
Contributor Author

it is accidentally closed after a force update when I resolved confict. l had tried many methods, it can not be reopened, weird : (
isaacs/github#361

@dzhwinter
Copy link
Contributor Author

If there is any method that can force update the branch and reopen this PR, Please let me know.
create a related PR here:
#2610

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrate new Pserver C optimizer lib with Go.
2 participants