Use original protostr for unittest of trainer_config_helper
Currently, the unittest at python/paddle/trainer_config_helper/tests/configs/run_tests.sh compares the generated protostr with the desired protostr using md5sum. The problem is that once something is changed in a PR, it is very hard for the code reviewers to figure out the changes to the original protostr.
如果github上的单测可以过,说明改过的protostr是没有问题的。
We thought that to add the generated protostr into git is too noising, but it is very hard to code review. We should change them ASAP.
@wen-bo-yang Could you help us to fix this issue? Just a good chance to learn how to use git, submit PR, and Paddle unittest process.
@wen-bo-yang 我说一下我们目前单测配置文件的一些上下文。
Paddle配置文件解析
目前Paddle的配置文件通过在Python端一并序列化成 protobuf 的二进制格式,然后再交由C++端进行处理。配置文件的解析使用python,这样可以方便用户去配置网络格式,而不用手写繁杂的protostring
具体示意图如下:

Paddle目前的配置文件单元测试
目前Paddle的配置文件单测在 这里。它首先将这个目录的配置文件,转换成protostring文件,然后对比这个protostring文件的md5是否和原来记录的md5一致。
这样做就有一个问题是,我们在版本库里记录了md5值,而没有记录protostring应该是什么样子。导致我们写一个新的配置,或者修改了原来的配置,只能看到md5的变更,而看不到protostring的变更,这样不利于被code review。
这个issue想要更换的单测格式
我们想要先将每一个配置的protostr生成出来,然后保存到git版本管理中。
然后,再对比每一次单测时候,新生成的配置与在git中的配置是否一致即可。是否一致的对比我们还可以用md5来做。
比如,对于一个配置 test_fc.py。我们先用paddle生成一个配置文件 test_fc.protostr,保存在git中。在单测的时候,我们再生成一个文件 test_fc.protostr.unittest, 然后对比这两个文件的md5值一致即可。
整体的设计思路如上,请 @wen-bo-yang 确认一下
@reyoung 明白,我先了解下整体流程。
@reyoung https://github.com/baidu/Paddle/pull/363
- 添加了新路径protostr用于保存以当前配置文件生成的protostr,同时将每次生成的protostr.unitest也保存在该路径下,路径名为:“Paddle/python/paddle/trainer_config_helpers/tests/configs/protostr” 如,test_fc.py 当前生成的protostr文件问test_fc.protostr,每次单侧生成的文件名问test_fc.protostr.unitest
- 修改了check.md5文件第二列,检测生成文件的路径
- 修改了generate_protostr.sh 将每次生成的protostr重新命名为xxx.protostr.unitest并保存在protostr路径下