【MODEL UPDATE】Combine params and model#2800
Conversation
Superjomn
left a comment
There was a problem hiding this comment.
给出 mobile so 前后的大小变化,避免feature 增加大小
| memcpy(paddle_version_table.cursor(), paddle_version.c_str(), 16); | ||
| paddle_version_table.Consume(16); | ||
| paddle_version_table.AppendToFile(prog_path); | ||
| std::cout << "paddle_version:" << paddle_version << std::endl; |
There was a problem hiding this comment.
所有的 cout 改为 glog
非必须log 可以去掉,或者使用 VLOG
There was a problem hiding this comment.
已经🙆♂️修改为VLOG(4)
| const std::string& param_buffer = "", | ||
| bool model_from_memory = false, | ||
| lite_api::LiteModelType model_type = lite_api::LiteModelType::kProtobuf) { | ||
| LightPredictor(const std::string& lite_model_file, |
There was a problem hiding this comment.
加注释
已经在MobileConfig中所有函数与成员添加注释,当调用set_model_buffer老接口是LOG(WARNING)输出warning,建议使用新接口。
|
|
||
| public: | ||
| void set_model_from_file(const std::string& x) { lite_model_file_ = x; } | ||
| void set_model_from_buffer(const std::string& x) { |
There was a problem hiding this comment.
实现都放到.cc 里
头文件里放重要接口和注释文档,方便看代码的人快速了解相关接口,不陷入实现细节里
There was a problem hiding this comment.
实现都放到.cc 里
头文件里放重要接口和注释文档,方便看代码的人快速了解相关接口,不陷入实现细节里
已经修改完毕
|
|
||
| // Save lite_version(char[16]) into file | ||
| naive_buffer::BinaryTable paddle_version_table; | ||
| paddle_version_table.Require(16); |
There was a problem hiding this comment.
不要有 magic number
16 和其他数字,特别跟二进制表格式有关的,用 const 常量定义,并且加注释解释下
There was a problem hiding this comment.
不要有 magic number
16 和其他数字,特别跟二进制表格式有关的,用 const 常量定义,并且加注释解释下
已经修改为const int8 paddle_version_length = 16 * sizeof(char);
经测试:本PR加入前armv8、GCC Android动态库大小:1653528字节,本PR加入后动态库大小1653528字节,对动态库大小没有影响 |
| Build(lite_model_file, model_from_memory); | ||
| } | ||
|
|
||
| // warning: old inference and will be abandened in release/v3.0.0 |
There was a problem hiding this comment.
NOTE: This is a deprecated API and will be removed in latter release.
There was a problem hiding this comment.
NOTE: This is a deprecated API and will be removed in latter release.
已经替换
| void Build(const std::string& lite_model_file, | ||
| bool model_from_memory = false); | ||
|
|
||
| // warning: old inference and will be abandened in release/v3.0.0 |
| lite_model_file_ = x; | ||
| model_from_memory_ = true; | ||
| } | ||
| // warning: set model data from memory buffer, which is in old format and will |
There was a problem hiding this comment.
.cc 的实现里面不需要加这个 warning,.h 里面需要。 一般人只会看 .h 里面的接口,不会深入到实现
There was a problem hiding this comment.
.cc 的实现里面不需要加这个 warning,.h 里面需要。 一般人只会看 .h 里面的接口,不会深入到实现
已经删除cc文件中的warning 信息
285e362 to
b242189
Compare
| # global variables | ||
| BUILD_EXTRA=OFF | ||
| BUILD_JAVA=ON | ||
| BUILD_JAVA=OFF |
| @@ -296,10 +296,10 @@ if (LITE_ON_TINY_PUBLISH) | |||
| endif() | |||
There was a problem hiding this comment.
修改optimize_tool的名称:从OPT 修改为opt
| @@ -64,6 +64,44 @@ public int getPowerModeInt() { | |||
| return powerMode.value(); | |||
| } | |||
|
|
|||
| # global variables | ||
| BUILD_EXTRA=OFF | ||
| BUILD_JAVA=ON | ||
| BUILD_JAVA=OFF |


本PR目的:修改Paddle-Lite的模型格式,新的模型格式要求请参考:[设计说明]()
【本PR的修改】:
【1】修改Lite的version,当前代码最后一个commit 不是git log时,将最后一个short commit id作为version :
lite/api/version.h.in【2】修改
model_parser.cc模型保存与加载方法:模型存储:
SaveModelNaive方法,修改为保存为单个文件模型加载: 原来加载方法保存
LoadModelNaive、LoadModelNaiveFromMemory(...)添加新模型的加载方法:
LoadModelNaiveFromFile、LoadModelNaiveFromMemory(...)【3】API接口:
paddle_api.cc: MobileConfig添加新接口set_model_from_file、set_model_from_buffer,添加变lite_model_file和返回值函数lite_model_file()light_api.cc: 重载新的Build函数、和predictor的构造函数(老方法保存)。用于light_api加载新格式的模型light_api_impl.cc: 修改CreatePredictor(MobileConfig)方法,实现根据MobileConfig的值选择调用老接口、还是新接口。 (当set_model_dir或set_model_buffer后会使用老方法;set_model_from_file、set_model_from_buffer后会使用新方法)注意:因为发现light_api实际没有加载pb格式模型的接口,本PR在新的light_predictor::build()函数中去除了model_type接口,只加载naive_buffer格式模型。
【4】相关单测修改:
model_parser_test.cclight_api_test.cc,cxx_api_test.cc,paddle_api_test.cc,apis_test.cc其他:
subgraph_pass_test.cc(因为调用了SaveOptimizedModel + LoadNaiveModel 过程)【5】关联模块修改 (因为下面两者都调用了SaveOptimizedModel + LoadNaiveModel过程)
benchmark:
benchmark.ccmodel_test:
model_test.cc【6】添加
Python接口:pybind.cc中mobileconfig添加接口:set_model_from_buffer和set_model_from_file【7】添加
Java接口: 在MobileConfig.java和convert_util_jni.h中为JavaAPI添加MobileConfig接口:setModelFromFile和setModelFromBuffer编译时默认不编译Java API,只有当build_java=ON时才编译java预测库。
【8】本PR将模型转化工具名称修改为opt
编译出的二进制文件名为 opt
流程:输入命令: ./lite/tool/build.sh build_optimize_tool
编译结果:build.opt/lite/api/opt
工具使用方法 : ./opt --model_dir= ...
【9】本次修改对预测库体积大小的影响:
经测试:本PR加入前armv8、GCC Android动态库大小:1653528字节,本PR加入后动态库大小1653528字节,对动态库大小没有影响