-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[Done] Feature/mnist train api #971
[Done] Feature/mnist train api #971
Conversation
…re/mnist_train_api
ok, I will work based on this, Thanks~ |
def main(): | ||
api.initPaddle("-use_gpu=false", "-trainer_count=4") # use 4 cpu cores | ||
config = paddle.trainer.config_parser.parse_config( | ||
'simple_mnist_network.py', '') |
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.
没看明白,我们昨天讨论的目的是用Python API写的Paddle程序都在一个py文件里。为什么这是还是分了两个.py文件呢?
这个PR的目的是用目前的Python API来实现MNIST training,还是用新的API来写demo呢?
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.
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.
这个PR的目的是用目前的Python API来实现MNIST training,还是用新的API来写demo呢?
用第一步目前的Python API实现,第二步把一堆python文件合成一个,第三步确定Python API究竟是啥样的。
m.start() | ||
|
||
for _ in xrange(100): | ||
updater.startPass() |
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.
通常startXXX要有对应的endXXX。比如 https://golang.org/pkg/os/exec/#Cmd.Start 有对应的 https://golang.org/pkg/os/exec/#Cmd.Wait。如果意思是“做且做完”,可以叫 run_one_pass
,比如 https://golang.org/pkg/os/exec/#Cmd.Run
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.
恩,之前的code开发了一半,发现其他的一些问题,然后交另一个PR了。。
这个后面的code补上了。
updater = api.ParameterUpdater.createLocalUpdater(opt_config) | ||
assert isinstance(updater, api.ParameterUpdater) | ||
updater.init(m) | ||
m.start() |
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.
start得有一个宾语。 如果是method,有时候class就是宾语,也有时候得明确指定宾语。比如
class BashCommand {
public:
void Run(); // Run the bash command.
void SetStderrPipe(Pipe* p); // Set is the predicate, Pipe is the subject.
}
这里比较诡异的是m的类型是GradientMachine
,如果method叫 start
,我不明白是 "start computing gradient” 还是 "start machine”。根据下文看,貌似是 start_training
,那么最好的安排貌似是m的类型起名叫做 Trainer
且method name是 start
,这样就成了 start trainer 的意思了。
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.
好,不过用户态的代码应该不这样。。可能类似于
with gradient_machine.enter_training():
gradient_machine.forwardBackward这样。
assert isinstance(m, api.GradientMachine) | ||
init_parameter(network=m) | ||
|
||
updater = api.ParameterUpdater.createLocalUpdater(opt_config) |
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.
我不常用Python,所以我去看了一下各种style guide里关于naming的描述。以下style guide都要求function names和method names都是 function_name
的形式,而不是 createLocalUpdater
的形式。
如果我们的API要被Python社区接受,我估计得是Python style的吧。
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.
ParameterUpdater和createLocalUpdater是直接从cpp中用swig expose出来的结构和方法,所以是cpp中的命名规范。我理解这些都不是直接暴露给用户的,而是经过我们封装一下,统一成python style。
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.
是的,不过这就是swig api的悲剧点之一了。
这个名字直接从C++的头文件PaddleAPI.h自动化翻译过来的,没有办法自定义。
如果是C-API会好很多。
for _ in xrange(100): | ||
updater.startPass() | ||
|
||
m.finish() |
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.
m.complete_training
另外,finish和complete的区别是“完蛋”和“完美”的区别,比如:
If you married a wrong woman, you are finished.
If you married the right woman, your are completed.
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.
haha
ParameterUpdater(); | ||
|
||
public: | ||
static ParameterUpdater* createLocalUpdater(OptimizationConfig* config); |
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.
在 Google C++ Style Guide 里,function/method names 应该是 CreateLocalUpdater
。
虽然现在Paddle的C++ naming和Google style不同,但是我建议(至少新代码里)采用Google style,因为一旦有人违反,我们在code review comments里可以贴一个链接(如上),告诉开发者为什么naming需要修正,而不需要一遍又一遍地手工输入解释。
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中的变量命名规则是.
对于类型名,采用全大写的CamelCase. 例如 GradientMachine, NeuralNetwork.
对于变量名:
- 普通变量名使用首字母小写的CamelCase, gradientMachine.
- 类内成员变量,采用首字母小写的CamelCase,同时尾缀为_。 比如 gradientMachine_。
- 对于静态全局变量,采用首字母为g的CamelCase,比如 gSyncThreadPool;
对于namespace的名称,为下划线分割的名字,例如 cpu_avx
Paddle目前有一套完整的命名风格了,所以似乎不需要非要改。
另外,关于变量命名方式的guide,有很多风格(Qt,stl,boost,linux,google)。只要在一个库里面统一,看到某一个名字,能够反应出变量大概是什么,其实就还好了。
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.
我们必须要遵守一个条款。遵守的最大用处,就是不要留给每个人纷争哪些条款值得遵守,否则review就总是会陷入在这类无休止的纷争里。
准守Google style的原因是:它对pros和cons都有分析,并且每一条条款都有一个URL。这样我们code review的时候只需要贴URL,不需要反复解释。
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目前使用的条款,而没有必要全改成google风格的。
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.
@reyoung paddle现在有关于naming的条款,可以在code review comments里贴URL的吗?如果没有,我建议就用Google style就好了。
@@ -0,0 +1,16 @@ | |||
from paddle.trainer_config_helpers import * | |||
|
|||
settings(learning_rate=1e-4, learning_method=AdamOptimizer(), batch_size=1000) |
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.
函数名字应该是动词或者动宾短语,settings是一个名词。这里的函数名看上去应该是 config_training_settings
吧?
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.
这里估计最后会改。。
我对这个pr的意图不一定理解对了,但是我感觉API的naming convention最好得符合C++和Python社区的大众习惯。所以我的comments里有引自code styles的,也有我关于英语语法的描述。希望这两点得到重视。 @reyoung @jacquesqiao |
@wangkuiyi 关于code style的部分非常重要,后面改造过程中还需要持续反馈提供意见,保证我们输出的是符合预期的,封装良好的api style。 |
@jacquesqiao 谢谢回复。我了解这个pr的上下文了。谢谢大家! @reyoung |
* hidden decorator kwargs in DataProvider.__init__ * also add unit test for this.
* hidden decorator kwargs in DataProvider.__init__ * also add unit test for this.
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.
这个PR目前还在开发,有一些事情会慢慢修复的。
assert isinstance(m, api.GradientMachine) | ||
init_parameter(network=m) | ||
|
||
updater = api.ParameterUpdater.createLocalUpdater(opt_config) |
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.
是的,不过这就是swig api的悲剧点之一了。
这个名字直接从C++的头文件PaddleAPI.h自动化翻译过来的,没有办法自定义。
如果是C-API会好很多。
updater = api.ParameterUpdater.createLocalUpdater(opt_config) | ||
assert isinstance(updater, api.ParameterUpdater) | ||
updater.init(m) | ||
m.start() |
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.
好,不过用户态的代码应该不这样。。可能类似于
with gradient_machine.enter_training():
gradient_machine.forwardBackward这样。
m.start() | ||
|
||
for _ in xrange(100): | ||
updater.startPass() |
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.
恩,之前的code开发了一半,发现其他的一些问题,然后交另一个PR了。。
这个后面的code补上了。
@@ -0,0 +1,16 @@ | |||
from paddle.trainer_config_helpers import * | |||
|
|||
settings(learning_rate=1e-4, learning_method=AdamOptimizer(), batch_size=1000) |
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.
这里估计最后会改。。
for _ in xrange(100): | ||
updater.startPass() | ||
|
||
m.finish() |
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.
haha
ParameterUpdater(); | ||
|
||
public: | ||
static ParameterUpdater* createLocalUpdater(OptimizationConfig* config); |
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中的变量命名规则是.
对于类型名,采用全大写的CamelCase. 例如 GradientMachine, NeuralNetwork.
对于变量名:
- 普通变量名使用首字母小写的CamelCase, gradientMachine.
- 类内成员变量,采用首字母小写的CamelCase,同时尾缀为_。 比如 gradientMachine_。
- 对于静态全局变量,采用首字母为g的CamelCase,比如 gSyncThreadPool;
对于namespace的名称,为下划线分割的名字,例如 cpu_avx
Paddle目前有一套完整的命名风格了,所以似乎不需要非要改。
另外,关于变量命名方式的guide,有很多风格(Qt,stl,boost,linux,google)。只要在一个库里面统一,看到某一个名字,能够反应出变量大概是什么,其实就还好了。
…e/mnist_train_api
…nto feature/mnist_train_api
@jacquesqiao your 843b63b and 763a30f are cherry picked to my branch. And @jacquesqiao , maybe you should associate your email address to your github account. Then github will show the correct avatar of your commits. |
Done, I have associate my email, thanx |
@wangkuiyi 这个PR已经完成了,我们使用SWIG API可以训练MNIST的demo了。 这里并不涉及任何Python用户态的API应该如何设计,只是从裸的SWIG API出发,完成这个功能。 PythonAPI的设计和提取在另一个PR里面做。 |
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.
the remaining work will be done in #1005
不好意思,因为我休假,耽误了这个pr 的merge。 我approve了。 但是有一点需要指出: 我们必须要严格遵守一个code style。遵守的最大用处,就是不要留给每个人纷争哪些条款值得遵守,否则review就总是会陷入在这类无休止的纷争里。 准守Google style的原因是:它对pros和cons都有分析,并且每一条条款都有一个URL。这样我们code review的时候只需要贴URL,不需要反复解释。 |
@reyoung 好! 因为和ADU同学合作的那个primier,是对google code style的一个修订,基本原则还是google style,所以我们comnents里贴的链接我估计绝大多数还是google style。 |
* bugfix (PaddlePaddle#967) * bugfix * Update release_note_cn.rst * bug fix (PaddlePaddle#968)
1. typo fix: stm_hidden_size -> lstm_hidden_size. 2. import fix: add missing imports in export_model.py 3. nit: remove unused imports.
Under developing. Trying to expose ParameterUpdater APIs.
@jacquesqiao but to make read trainer_config.py to one file can be under developing now.
You can get my feature branch by
and push your commits into your repo. Thx.