Are you sure you want to delete this task? Once this task is deleted, it cannot be recovered.
Megvii Engine Team 1c2d1b63b5 | 3 months ago | |
---|---|---|
.. | ||
build_config | 1 year ago | |
example | 5 months ago | |
include/lite | 3 months ago | |
lite-c | 1 year ago | |
load_and_run | 5 months ago | |
pylite | 6 months ago | |
src | 5 months ago | |
test | 5 months ago | |
tools | 1 year ago | |
CMakeLists.txt | 5 months ago | |
README.md | 2 years ago |
It is a lite warper of MegEngine, to enable MegEngine easy to be integrated in
user's SDK
cmake构建参考scripts/cmake-build/BUILD_README.md,下面example表示同时支持编译megengine
和RKNPU后端且打开OpenCL的release模式
EXTRA_CMAKE_ARGS="-DANDROID_NATIVE_API_LEVEL=24 -DLITE_BUILD_WITH_RKNPU=ON -DMGE_WITH_OPENCL=ON \
-DMGE_OPENCL_SEARCH_ALGO=ON -DCUSTOM_C_OPR_INIT_FUNC=custom_loader_func" ./scripts/cmake-build/cross_build_android_arm_inference.sh"
具体 midout 的裁减原理见 megbrain 中 midout 裁减,裁减方法见 MegBrain
和 MegEngine 的裁减方法
lite 目前支持只支持 MegEngine dump 的模型格式,可以加载的模型文件包括原始
的模型文件,原始的加密模型,pack 之后的加密或者非加密模型。加密算法以及
加密的秘钥可以用户自定义,然后注册到 lite 中,详见 example 中加解密部分。
不同的模型文件主要是通过 pack 之后的模型文件中的 model_tag 来区分.
Header 部分最开始为一个明文固定model_tag,目前定义为"packed_model"字符串,
后面主要包含模型文件各个部分的信息,每个部分的加密方式,load 模型时候可以
调用相应的解密方法对各个部分进行解密,以及model infomation 部分的解析方法。
具体细节参考lite/src/parse_model/pack_model.fbs
Info 部分主要用来解释模型,如用户关心的:模型的输入数据的格式,模型运行的平台
等信息,这部分信息也可以用于用户进行 check 运行的模型是否在指定的条件下运行。
由于这个 Info 部分不同的用户需求不一致,想传递的信息也无法统一,所以目前
Lite 中提供自定义的方式,用户可以自定义自己 Info 部分的类容,并在 Header 中
指定 Info 解析方式名字 ,并注册以该名字为 key 的解析函数到 Lite 中,
以这样方式来可以实现用户自定义 Info 格式。同时,Lite 中也提供了一套定义好的
格式,其名字为 "LITE_default",并已经实现了对应的解析函数,该 info
为 JSON 格式,具体内容定义如下:
{
"name": "shufflenet_test",
"valid": true,
"version": "8.9999.0",
"has_compression": false,
"device": {
"type": "CPU",
"device_id": 0,
"number_threads": 1,
"use_tensor_rt": false,
"enable_inplace_model": false
},
"options":{
"weight_preprocess": false,
"var_sanity_check_first_run": true,
"const_shape": false,
"jit_level": 0,
"record_level": 0
},
"IO":{
"inputs":[
{
"name": "data",
"io_type": "value",
"is_host": true,
"dtype": "float32",
"shape": {
"dim0": 1,
"dim1": 3,
"dim2": 224,
"dim3": 224
}
}
],
"outputs":[
{
"name": "TRUE_DIV(EXP[12065],reduce0[12067])[12077]",
"io_type": "value",
"is_host": true,
"dtype": "float32",
"shape": {
"dim0": 1,
"dim1": 1000,
"dim2": 0,
"dim3": 0
}
}
]
}
}
可以是加密的模型文件或者未加密的模型文件
丰富的使用方法详见文件 example 中文档和对应的 example。
目前 lite 中有三个工具保存在 tools 目录中,其他 megbrain 工具
没有包含在内,分别为:
pack_model_and_info.py 为上面提到的模型打包工具,其为一个
python 脚本,可以直接用其对已有的模型和模型 information 的文件,按照上面
的格式进行打包模型,用户可以指定模型名字,模型加密方式,模型信息
文件加密方式,解析方式等,如下:
python3 pack_model_and_info.py --input-model xxx.mge \
--model-name="shufflenet_test" \
--model-cryption="RC4_default" \
--input-info xxx.json \
--info-cryption="RC4_default" \
--info-parser="LITE_default" \
-o xxx.lite
aes_encrypt.sh 为一个 aes 加密方式的加密脚本,可以将一个文件,
通过指定的的 key 加密成一个 aes 加密的文件,其中 key 为 32 个字节
16进制数。
aes_encrypt.sh xxx.mdl xxx_encrypted.mdl \
000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F
天元(MegEngine)是旷视自主研发的开源深度学习框架,于2020年3月正式在 OpenI 启智社区开源,天元能够帮助开发者高效的完成深度学习算法的设计、训练、部署,有效提升AI研发工作效率。
C++ Cuda Python C Starlark other
Dear OpenI User
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.
For more agreement content, please refer to the《Openl Qizhi Community AI Collaboration Platform Usage Agreement》