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

Add some functions to PaddleAPI.h #1013

Merged
merged 5 commits into from
Jan 10, 2017

Conversation

reyoung
Copy link
Collaborator

@reyoung reyoung commented Dec 26, 2016

These functions are used to implement training progress in Python. Used by PR #1005

@reyoung reyoung requested a review from jacquesqiao December 26, 2016 06:24
@reyoung reyoung changed the title Add sum cost to Arguments Add some function to PaddleAPI.h Dec 26, 2016
@reyoung reyoung changed the title Add some function to PaddleAPI.h Add some functions to PaddleAPI.h Dec 26, 2016
@@ -0,0 +1,6 @@
___fc_layer_0__.w0
Copy link
Member

Choose a reason for hiding this comment

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

这里是否可以使用通配符进行匹配

@@ -137,6 +137,10 @@ void Arguments::setSlotSequenceDim(size_t idx, IVector* vec) throw(RangeError) {
a.cpuSequenceDims = m->cast<paddle::IVector>(vec->getSharedPtr());
}

float Arguments::sumCosts() const {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Function names should be Camel Cased: https://google.github.io/styleguide/cppguide.html#Function_Names

是不是至少对于新加的函数,应该符合code style,这样至少提醒大家关注规范;现有的函数,可以以后写个工具重命名?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

麻烦review一下这个 baidu-adu/cpp-primer-digest#1
这个是Paddle目前的命名风格。

@@ -454,6 +454,8 @@ class Arguments {
IVector* vec) throw(RangeError);
void setSlotSequenceDim(size_t idx, IVector* vec) throw(RangeError);

float sumCosts() const;
Copy link
Collaborator

@wangkuiyi wangkuiyi Dec 27, 2016

Choose a reason for hiding this comment

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

PR的description里说明一下为什么需要增加这几个函数吧。加了之后能有什么好处:

  • sumCosts
  • load
  • save

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done.

Copy link
Member

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@jacquesqiao jacquesqiao left a comment

Choose a reason for hiding this comment

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

关于codestyle现在啥结论@@

@wangkuiyi
Copy link
Collaborator

不好意思,休假耽误了code style的讨论。我刚才comment了https://github.com/PaddlePaddle/cpp-primer-digest/pull/1: baidu-adu/cpp-primer-digest#1 (review)

@@ -70,3 +70,11 @@ ParameterConfig* Parameter::getConfig() {
size_t Parameter::getID() const { return m->getPtr()->getID(); }

void Parameter::setValueUpdated() { m->getPtr()->setValueUpdated(); }

bool Parameter::save(const std::string& filename) const {
Copy link
Collaborator

Choose a reason for hiding this comment

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

我之前一直迟迟没有approve这个PR的一个主要原因是,save/load(filename) 这样的methods不是一个好的设计。

首先这些methods不容易被unit test。除非我们有一个in-memory mock filesystem。但实际上我们不需要这么复杂的test facility。而且这些methods里的内容经常和网络传输methods里的内容重复——都是要 serialize/deserialize class memebers。

一个比较常见的设计是用 serialize/deserialize 来代替 save/load:

std::string serialize();
error deserialize(const std::string& input);

这样一来容易unit test,二来容易用于网络传输和磁盘I/O:

File f("/tmp/a");
Parameters ps;
f.write(ps.serialize());

Copy link
Member

Choose a reason for hiding this comment

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

非常有道理!现在的接口是不适合分布式化的,serialize/deserialize才能更方便传输。目前暴露的接口是老接口,仅仅是暴露出来,下一步提供c-api的时候可以考虑重构。

@reyoung reyoung merged commit a765c7c into PaddlePaddle:develop Jan 10, 2017
@reyoung reyoung deleted the feature/add_sum_cost_in_args branch January 18, 2017 06:13
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.

3 participants