[{"data":1,"prerenderedAt":1154},["ShallowReactive",2],{"content-query-9Huz204RzS":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"cover":11,"type":12,"body":13,"_type":1148,"_id":1149,"_source":1150,"_file":1151,"_stem":1152,"_extension":1153},"/technology-blogs/zh/370","zh",false,"","华为智慧终端背后的黑科技----超轻量AI引擎MindSpore Lite","华为终端设备搭载了众多黑科技，今天我们就来揭秘一下端上的AI引擎：MindSpore Lite。","2021-01-05","https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/01/05/a388d198a1094714b3456ed1c8217be7.png","technology-blogs",{"type":14,"children":15,"toc":1119},"root",[16,24,29,68,80,90,101,107,111,116,121,129,141,158,165,170,178,183,190,195,202,207,222,234,239,250,255,263,270,275,283,290,295,310,316,323,333,337,350,369,394,401,406,410,418,423,430,435,439,454,459,463,468,474,490,508,517,522,531,536,543,551,556,568,575,580,592,603,615,633,638,643,654,659,664,671,676,687,692,697,702,707,712,717,722,727,731,736,741,746,751,756,761,766,771,776,781,786,791,796,801,806,811,816,821,826,831,836,841,846,851,856,861,866,871,876,881,886,891,895,900,912,916,921,933,937,942,960,964,969,987,992,1019,1029,1062,1067,1076,1086,1091,1095,1104,1109],{"type":17,"tag":18,"props":19,"children":21},"element","h1",{"id":20},"华为智慧终端背后的黑科技-超轻量ai引擎mindspore-lite",[22],{"type":23,"value":8},"text",{"type":17,"tag":25,"props":26,"children":27},"p",{},[28],{"type":23,"value":9},{"type":17,"tag":25,"props":30,"children":31},{},[32,38,40,45,47,52,54,59,61,66],{"type":17,"tag":33,"props":34,"children":35},"strong",{},[36],{"type":23,"value":37},"MindSpore Lite****是",{"type":23,"value":39},"MindSpore全场景",{"type":17,"tag":33,"props":41,"children":42},{},[43],{"type":23,"value":44},"AI",{"type":23,"value":46},"框架的",{"type":17,"tag":33,"props":48,"children":49},{},[50],{"type":23,"value":51},"端侧引擎",{"type":23,"value":53},"，目前MindSpore Lite作为华为HMS Core机器学习服务的推理引擎底座，已",{"type":17,"tag":33,"props":55,"children":56},{},[57],{"type":23,"value":58},"为全球1000+应用提供推理引擎服务",{"type":23,"value":60},"，日均调用量",{"type":17,"tag":33,"props":62,"children":63},{},[64],{"type":23,"value":65},"超过3亿",{"type":23,"value":67},"，同时在各类手机、穿戴感知、智慧屏等设备的AI特性上得到了广泛应用。",{"type":17,"tag":25,"props":69,"children":70},{},[71,73,78],{"type":23,"value":72},"MindSpore Lite 1.0.0 已经在今年9月份开源，开源之后，其接口易用性、算子性能与完备度、第三方模型的广泛支持等方面，得到了众多手机应用开发者的广泛认可。目前，1.0.0版本发布已经过去3个月，最新的MindSpore Lite 1.1.0 在算子性能优化、模型小型化、加速库自动裁剪工具、端侧模型训练、语音类模型支持、Java接口开放、模型可视化等方面进行了全面升级，",{"type":17,"tag":33,"props":74,"children":75},{},[76],{"type":23,"value":77},"升级后的版本更轻、更快、更易用",{"type":23,"value":79},"。接下来我们看一下 MindSpore Lite 1.1.0 。",{"type":17,"tag":25,"props":81,"children":82},{},[83,88],{"type":17,"tag":33,"props":84,"children":85},{},[86],{"type":23,"value":87},"获取1.1.0版本MindSpore Lite",{"type":23,"value":89},"：",{"type":17,"tag":25,"props":91,"children":92},{},[93],{"type":17,"tag":94,"props":95,"children":99},"a",{"href":96,"rel":97},"https://www.mindspore.cn/tutorial/lite/zh-CN/r1.1/use/downloads.html",[98],"nofollow",[100],{"type":23,"value":96},{"type":17,"tag":18,"props":102,"children":104},{"id":103},"_1-算子库优化与扩展",[105],{"type":23,"value":106},"1. 算子库优化与扩展",{"type":17,"tag":108,"props":109,"children":110},"h2",{"id":7},[],{"type":17,"tag":25,"props":112,"children":113},{},[114],{"type":23,"value":115},"1.1 性能优化",{"type":17,"tag":25,"props":117,"children":118},{},[119],{"type":23,"value":120},"推理性能优化依然是我们本次版本的重头戏，除了持续的ARM CPU(FP16/FP32/INT8)性能优化，ARM GPU和X86_64的优化也是本次的亮点，GPU方面我们除了传统的算子优化，还加入了在线融合、AutoTuning等技术，使得ARM GPU推理性能大幅提升；同时为了更好的支持PC侧推理，在X86_64算子方面我们做了大量汇编层面的优化；经过大量模型的实测，MindSpore Lite 1.1.0 在推理性能方面在业界各类框架中极具竞争力。",{"type":17,"tag":25,"props":122,"children":123},{},[124],{"type":17,"tag":33,"props":125,"children":126},{},[127],{"type":23,"value":128},"1.1.1 ARM CPU优化",{"type":17,"tag":25,"props":130,"children":131},{},[132,134,139],{"type":23,"value":133},"我们从引入减少计算量的更优算法，到尽可能减少硬件访存从而提高指令吞吐量，MindSpore Lite 的CPU算子性能大幅提升。我们使用TF Hub官网上100+端侧预置模型进行了推理时延对比测试，测试结果显示在Mate30/P30等高端机型上",{"type":17,"tag":33,"props":135,"children":136},{},[137],{"type":23,"value":138},"MindSpore Lite已全面超越TFLite",{"type":23,"value":140},"，在P20等中低端机型上推理性能优于TFLite的占比也达到97%。",{"type":17,"tag":142,"props":143,"children":144},"ul",{},[145],{"type":17,"tag":146,"props":147,"children":148},"li",{},[149,153],{"type":17,"tag":108,"props":150,"children":152},{"id":151},"_1",[],{"type":17,"tag":33,"props":154,"children":155},{},[156],{"type":23,"value":157},"FP16推理性能",{"type":17,"tag":159,"props":160,"children":162},"h4",{"id":161},"mindspore-lite全面支持armv82的fp16推理推理时延基本达到了fp32类型推理的二分之一在推理时延大幅降低的同时精度满足业务要求我们的fp16推理方案已经在华为hms-mlkit和华为手机预置的各类ai服务中普遍应用",[163],{"type":23,"value":164},"MindSpore Lite全面支持ARMv8.2的FP16推理，推理时延基本达到了FP32类型推理的二分之一，在推理时延大幅降低的同时精度满足业务要求；我们的FP16推理方案已经在华为HMS MLKit和华为手机预置的各类AI服务中普遍应用。",{"type":17,"tag":25,"props":166,"children":167},{},[168],{"type":23,"value":169},"由于TF Lite不支持FP16推理，所以在FP16推理性能对比测试环节中我们只选择了阿里MNN最新的1.1版本，从测试结果看MindSpore Lite在FP16推理性能上展现出一定的优势。",{"type":17,"tag":25,"props":171,"children":172},{},[173],{"type":17,"tag":174,"props":175,"children":177},"img",{"alt":7,"src":176},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/01/05/7e530064b7dc4f9d8011d6c1ab6d2003.jpg",[],{"type":17,"tag":25,"props":179,"children":180},{},[181],{"type":23,"value":182},"华为Mate30(麒麟990)上网络整体时延对比情况",{"type":17,"tag":25,"props":184,"children":185},{},[186],{"type":17,"tag":174,"props":187,"children":189},{"alt":7,"src":188},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/01/05/1833a476789f4dda867e45faf6edd4d4.jpg",[],{"type":17,"tag":25,"props":191,"children":192},{},[193],{"type":23,"value":194},"华为Mate30(麒麟990)上FP16推理时延对比",{"type":17,"tag":25,"props":196,"children":197},{},[198],{"type":17,"tag":174,"props":199,"children":201},{"alt":7,"src":200},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/01/05/4fc1f9fd826f48c9a61d9458a671b5c3.jpg",[],{"type":17,"tag":25,"props":203,"children":204},{},[205],{"type":23,"value":206},"三星Note20(骁龙865+)上FP16推理时延对比",{"type":17,"tag":142,"props":208,"children":209},{},[210],{"type":17,"tag":146,"props":211,"children":212},{},[213,217],{"type":17,"tag":108,"props":214,"children":216},{"id":215},"_2",[],{"type":17,"tag":33,"props":218,"children":219},{},[220],{"type":23,"value":221},"Int8量化模型推理性能",{"type":17,"tag":25,"props":223,"children":224},{},[225,227,232],{"type":23,"value":226},"对于量化算子，当前版本MindSpore Lite实现了在算法层面加入如Convolution Kernel为3x3的Winograd优化算法（目前主要针对非ARMv8.2机型），在支持ARMv8.2的高端机上使用SDOT指令对MatMul、Fully Connection、Convolution等算子进行优化，以及提高底层缓存命中率的一系列优化策略，使得MindSpore Lite量化推理性能得到大幅提升，",{"type":17,"tag":33,"props":228,"children":229},{},[230],{"type":23,"value":231},"相较于FP16推理有40%+的性能提升",{"type":23,"value":233},"。",{"type":17,"tag":25,"props":235,"children":236},{},[237],{"type":23,"value":238},"我们选择了TF Lite最新2.4版本和MNN最新的1.1版本进行推理性能对比测试，使用的模型为TF Hub官方预置的量化模型（测试过程中我们发现MNN存在大量量化模型无法转换问题，甚至TF Lite对自家模型也存在转换问题），从测试结果看MindSpore Lite对量化模型无论在支持度还是推理性能方面，都较其他框架有明显优势。",{"type":17,"tag":25,"props":240,"children":241},{},[242,246],{"type":17,"tag":174,"props":243,"children":245},{"alt":7,"src":244},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/01/05/b224cc58aa42420db002eb93c764602e.jpg",[],{"type":17,"tag":174,"props":247,"children":249},{"alt":7,"src":248},"data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==",[],{"type":17,"tag":25,"props":251,"children":252},{},[253],{"type":23,"value":254},"华为Mate30(麒麟990)上量化网络整体时延对比情况",{"type":17,"tag":25,"props":256,"children":257},{},[258],{"type":17,"tag":33,"props":259,"children":260},{},[261],{"type":23,"value":262},"ARMv8.2机型测试",{"type":17,"tag":25,"props":264,"children":265},{},[266],{"type":17,"tag":174,"props":267,"children":269},{"alt":7,"src":268},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/01/05/ca34ca9787c04fe7933f109d15a3139d.jpg",[],{"type":17,"tag":25,"props":271,"children":272},{},[273],{"type":23,"value":274},"三星Note20上量化模型时延对比",{"type":17,"tag":25,"props":276,"children":277},{},[278],{"type":17,"tag":33,"props":279,"children":280},{},[281],{"type":23,"value":282},"ARMv8机型测试",{"type":17,"tag":25,"props":284,"children":285},{},[286],{"type":17,"tag":174,"props":287,"children":289},{"alt":7,"src":288},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/01/05/f9606d4ac0804e96bd248b914f37c976.jpg",[],{"type":17,"tag":25,"props":291,"children":292},{},[293],{"type":23,"value":294},"华为P20上量化模型时延对比",{"type":17,"tag":142,"props":296,"children":297},{},[298],{"type":17,"tag":146,"props":299,"children":300},{},[301,305],{"type":17,"tag":108,"props":302,"children":304},{"id":303},"_3",[],{"type":17,"tag":33,"props":306,"children":307},{},[308],{"type":23,"value":309},"FP32推理性能",{"type":17,"tag":159,"props":311,"children":313},{"id":312},"同时为了确保在低端cpu上使用mindspore-lite推理时能够同样获得业界最优的推理性能我们持续对fp32的推理性能进行了优化我们在华为p20上以tflite24版本mnn11版本作为对比对象进行了benchmark性能测试从测试结果中可以看出mindspore-lite-fp32推理性能依然处理领先地位但与其他框架的差距正在缩小",[314],{"type":23,"value":315},"同时为了确保在低端CPU上使用MindSpore Lite推理时能够同样获得业界最优的推理性能，我们持续对FP32的推理性能进行了优化。我们在华为P20上以TFLite(2.4版本)、MNN(1.1版本)作为对比对象，进行了benchmark性能测试，从测试结果中可以看出MindSpore Lite FP32推理性能依然处理领先地位，但与其他框架的差距正在缩小。",{"type":17,"tag":25,"props":317,"children":318},{},[319],{"type":17,"tag":174,"props":320,"children":322},{"alt":7,"src":321},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/01/05/c26a01a7bd88442999da4c46186b2df6.jpg",[],{"type":17,"tag":25,"props":324,"children":325},{},[326,328],{"type":23,"value":327},"华为P20上FP32推理时延对比",{"type":17,"tag":174,"props":329,"children":332},{"alt":330,"src":331},"图片","https://mmbiz.qpic.cn/sz_mmbiz_png/xfBicxTBmNWV2gDdzQm0ZlicrxAs4vNU9A46ApMjhf50xrFl8fW3eLs7ltF0xmYTIh02sWLNd3gFNlkVJFzxgTGQ/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1",[],{"type":17,"tag":108,"props":334,"children":336},{"id":335},"_4",[],{"type":17,"tag":25,"props":338,"children":339},{},[340],{"type":17,"tag":33,"props":341,"children":342},{},[343,348],{"type":17,"tag":33,"props":344,"children":345},{},[346],{"type":23,"value":347},"1.1.2",{"type":23,"value":349}," ARM GPU优化",{"type":17,"tag":25,"props":351,"children":352},{},[353,355,360,362,367],{"type":23,"value":354},"MindSpore Lite 1.1.0 版本我们",{"type":17,"tag":33,"props":356,"children":357},{},[358],{"type":23,"value":359},"对GPU推理性能进行了重点优化",{"type":23,"value":361},"，除了在算子层面进行了常规优化外，还增加了在线融合、AutoTuning、OpenCL kernel二进制cache机制等多种优化方式，使得整体性能较MindSpore Lite 1.0 ",{"type":17,"tag":33,"props":363,"children":364},{},[365],{"type":23,"value":366},"有25%+的提升",{"type":23,"value":368},"；",{"type":17,"tag":25,"props":370,"children":371},{},[372,374,379,381,386,388,393],{"type":23,"value":373},"我们同样在华为Mate30上使用TF Hub官网100+预置模型与MNN(1.1版本)和TF(2.4版本)进行了GPU推理性能对比测试，可以从下图的测试结果看出MindSpore Lite GPU",{"type":17,"tag":33,"props":375,"children":376},{},[377],{"type":23,"value":378},"推理性能",{"type":23,"value":380},"在大部分模型上",{"type":17,"tag":33,"props":382,"children":383},{},[384],{"type":23,"value":385},"优于TF Lite",{"type":23,"value":387},"，而",{"type":17,"tag":33,"props":389,"children":390},{},[391],{"type":23,"value":392},"对于MNN则优势明显",{"type":23,"value":233},{"type":17,"tag":25,"props":395,"children":396},{},[397],{"type":17,"tag":174,"props":398,"children":400},{"alt":7,"src":399},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/01/05/4f0be1ae174f49b38affa56273e449f7.jpg",[],{"type":17,"tag":25,"props":402,"children":403},{},[404],{"type":23,"value":405},"华为Mate30上GPU FP32推理时延对比",{"type":17,"tag":108,"props":407,"children":409},{"id":408},"_5",[],{"type":17,"tag":25,"props":411,"children":412},{},[413],{"type":17,"tag":33,"props":414,"children":415},{},[416],{"type":23,"value":417},"1.1.3 X86_64 CPU优化",{"type":17,"tag":25,"props":419,"children":420},{},[421],{"type":23,"value":422},"本次版本我们还对X86_64平台上的推理性能进行了大量优化工作，我们在Intel Core i7-8700的CPU上与Intel OpenVINO和MNN在几个经典CV类网络上进行了benchmark测试，从测试结果看MindSpore Lite性能相比于MNN和OpenVINO都有一定的优势。",{"type":17,"tag":25,"props":424,"children":425},{},[426],{"type":17,"tag":174,"props":427,"children":429},{"alt":7,"src":428},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/01/05/0fe8de8be3f34422ba56016251719768.jpg",[],{"type":17,"tag":25,"props":431,"children":432},{},[433],{"type":23,"value":434},"Intel Core i7-8700 X86_64 CPU推理性能对比",{"type":17,"tag":108,"props":436,"children":438},{"id":437},"_6",[],{"type":17,"tag":25,"props":440,"children":441},{},[442,447,449],{"type":17,"tag":33,"props":443,"children":444},{},[445],{"type":23,"value":446},"1.1.4",{"type":23,"value":448}," ",{"type":17,"tag":33,"props":450,"children":451},{},[452],{"type":23,"value":453},"更多的融合",{"type":17,"tag":25,"props":455,"children":456},{},[457],{"type":23,"value":458},"当前MindSpore Lite版本已经基本覆盖了机器视觉领域通用的卷积相关融合pattern，同时针对基于Transformer结构的语音模型和LSTM结构的模型进行了深度融合优化，主要包括将小算子融合成Layernorm、LSTM等大算子，多个MatMul融合成BatchMatMul算子，Slice算子切分矩阵的前移融合等，使得语音类模型获得20%+的提升，后续我们将尝试融合pattern的自动schedule功能。",{"type":17,"tag":108,"props":460,"children":462},{"id":461},"_7",[],{"type":17,"tag":25,"props":464,"children":465},{},[466],{"type":23,"value":467},"1.2 算子完备度扩展",{"type":17,"tag":108,"props":469,"children":471},{"id":470},"mindspore-lite支持包括arm-cpuarm-gpux86-cpukirin-npumtk-apu在内的多种硬件平台",[472],{"type":23,"value":473},"MindSpore Lite支持包括ARM CPU、ARM GPU、X86 CPU、Kirin NPU、MTK APU在内的多种硬件平台。",{"type":17,"tag":475,"props":476,"children":478},"h3",{"id":477},"_121-arm-cpu",[479,484,485],{"type":17,"tag":33,"props":480,"children":481},{},[482],{"type":23,"value":483},"1.2.1",{"type":23,"value":448},{"type":17,"tag":33,"props":486,"children":487},{},[488],{"type":23,"value":489},"ARM CPU",{"type":17,"tag":25,"props":491,"children":492},{},[493,495,500,502,507],{"type":23,"value":494},"MindSpore Lite是目前端侧推理框架中CPU算子支持最丰富的框架之一，当前我们的模型转换工具支持TF Lite（100个）、TF(53个)、ONNX（96个）以及Caffe（26个）等第三方框架算子定义的解析，做到了",{"type":17,"tag":33,"props":496,"children":497},{},[498],{"type":23,"value":499},"高兼容性",{"type":23,"value":501},"，上文性能测试中我们也提到过MNN对很多模型无法转换，甚至连TF Lite对自家官网预置模型的支持度也不够完善；同时MindSpore Lite实现了121个FP32，55个FP16以及71个INT8 CPU算子；而此次的1.1版本我们对控制流算子也进行一次大的调整与完善，以便更",{"type":17,"tag":33,"props":503,"children":504},{},[505],{"type":23,"value":506},"好的支持语音类模型",{"type":23,"value":233},{"type":17,"tag":475,"props":509,"children":511},{"id":510},"_122-arm-gpu",[512],{"type":17,"tag":33,"props":513,"children":514},{},[515],{"type":23,"value":516},"1.2.2 ARM GPU",{"type":17,"tag":25,"props":518,"children":519},{},[520],{"type":23,"value":521},"新增OpenCL算子10+，当前支持GPU算子总数为58，基本实现常见CV类网络覆盖；新增在线融合、Auto Tuning等特性支持，同时支持权重量化，实现8bit权重量化网络在GPU整网运行。",{"type":17,"tag":475,"props":523,"children":525},{"id":524},"_123-kirin-npu",[526],{"type":17,"tag":33,"props":527,"children":528},{},[529],{"type":23,"value":530},"1.2.3 Kirin NPU",{"type":17,"tag":25,"props":532,"children":533},{},[534],{"type":23,"value":535},"1.1版本我们完善了对华为麒麟NPU硬件平台的支持，增加了对Kirin 9000芯片的支持，同时新增了50+ NPU算子支持，从而实现支持大部分CV类场景在NPU上的加速执行；我们在华为最新的Mate 40手机上进行了几个典型网络的benchmark验证，NPU上推理时延较CPU推理有明显提升；",{"type":17,"tag":25,"props":537,"children":538},{},[539],{"type":17,"tag":174,"props":540,"children":542},{"alt":7,"src":541},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/01/05/24ba55961bbf44e9b1e68d1460eec89a.jpg",[],{"type":17,"tag":25,"props":544,"children":545},{},[546,548],{"type":23,"value":547},"Mate 40上NPU和CPU FP32/16推理时延对比",{"type":17,"tag":174,"props":549,"children":550},{"alt":7,"src":248},[],{"type":17,"tag":25,"props":552,"children":553},{},[554],{"type":23,"value":555},"2. 支持端侧训练",{"type":17,"tag":25,"props":557,"children":558},{},[559,561,566],{"type":23,"value":560},"由于使用公共数据集训练的模型与真实用户场景存一定的偏差，比如语音识别等场景，我们往往需要利用本地数据对预训练模型进行微调，从而",{"type":17,"tag":33,"props":562,"children":563},{},[564],{"type":23,"value":565},"提高本地模型推理的精度",{"type":23,"value":567},"，改善用户体验。",{"type":17,"tag":25,"props":569,"children":570},{},[571],{"type":17,"tag":174,"props":572,"children":574},{"alt":7,"src":573},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/01/05/1e47c8b5e8f94de48f87e4fc1ef99a75.jpg",[],{"type":17,"tag":25,"props":576,"children":577},{},[578],{"type":23,"value":579},"MindSpore Lite 1.1.0 版本我们将端侧训练框架进行了开源，首个版本给我们带来了以下特性：",{"type":17,"tag":25,"props":581,"children":582},{},[583,585,590],{"type":23,"value":584},"1. 支持30+反向算子，提供SGD、ADAM等常见优化器及CrossEntropy/SparsCrossEntropy/MSE等损失函数；既可从零训练模型，也可指定特定网络层微调，",{"type":17,"tag":33,"props":586,"children":587},{},[588],{"type":23,"value":589},"达到迁移学习目的",{"type":23,"value":591},";",{"type":17,"tag":25,"props":593,"children":594},{},[595,597,602],{"type":23,"value":596},"2. 已支持LeNet/AlexNet/ResNet/MobileNetV1/V2/V3和EffectiveNet等网络训练，提供完整的模型加载，转换和训练脚本，",{"type":17,"tag":33,"props":598,"children":599},{},[600],{"type":23,"value":601},"方便用户使用和调测",{"type":23,"value":591},{"type":17,"tag":25,"props":604,"children":605},{},[606,608,613],{"type":23,"value":607},"3. MindSpore云侧训练和端侧训练",{"type":17,"tag":33,"props":609,"children":610},{},[611],{"type":23,"value":612},"实现无缝对接",{"type":23,"value":614},"，云侧模型可直接加载到端侧进行训练;",{"type":17,"tag":25,"props":616,"children":617},{},[618,620,625,627,632],{"type":23,"value":619},"4. 支持checkpoint机制，训练过程",{"type":17,"tag":33,"props":621,"children":622},{},[623],{"type":23,"value":624},"异常中断",{"type":23,"value":626},"后可",{"type":17,"tag":33,"props":628,"children":629},{},[630],{"type":23,"value":631},"快速恢复继续训练",{"type":23,"value":591},{"type":17,"tag":25,"props":634,"children":635},{},[636],{"type":23,"value":637},"我们的端侧训练框架已经在华为部分设备的AI应用比如家庭相册等场景进行了商用，并取得了很好的用户体验。",{"type":17,"tag":25,"props":639,"children":640},{},[641],{"type":23,"value":642},"3. 训练后量化",{"type":17,"tag":25,"props":644,"children":645},{},[646,648,653],{"type":23,"value":647},"随着AI应用在端侧设备部署越来越普遍，而受制于端侧资源的局限性，对于模型小型化和推理性能提升的挑战日益倍增。MindSpore Lite提供了简单实用的训练后量化功能，",{"type":17,"tag":33,"props":649,"children":650},{},[651],{"type":23,"value":652},"最大程度压缩模型大小，减小内存占用，提升推理速度，降低功耗",{"type":23,"value":233},{"type":17,"tag":25,"props":655,"children":656},{},[657],{"type":23,"value":658},"训练后量化相较于量化重训具有两个明显优势，一是无需大量训练数据集，二是无需重新训练，离线快速转换。MindSpore Lite训练后量化工具提供权重量化和全量化两种方法，支持1~16bit量化，支持分类，检测，NLP等多种模型。",{"type":17,"tag":25,"props":660,"children":661},{},[662],{"type":23,"value":663},"为保障训练后量化模型精度损失小，我们采用pipeline组合量化方法，一阶段采用常规线性量化手段对权重和激活值进行量化，二阶段对量化误差进行分析，利用统计学方法对量化模型进行校正，补偿因量化带来的精度损失。",{"type":17,"tag":25,"props":665,"children":666},{},[667],{"type":17,"tag":174,"props":668,"children":670},{"alt":7,"src":669},"https://obs-mindspore-file.obs.cn-north-4.myhuaweicloud.com/file/2021/01/05/7c496b00c3584d5b82d4936d05ffde93.jpg",[],{"type":17,"tag":25,"props":672,"children":673},{},[674],{"type":23,"value":675},"Pipeline 组合量化",{"type":17,"tag":25,"props":677,"children":678},{},[679,681,686],{"type":23,"value":680},"以TF官网MobileNet_v2模型为例，MindSpore Lite训练后量化A8W8（激活值8bit量化、权重8bit量化）精度与FP32模型相比，经损失校正后，精度损失由0.82%降到0.4%，同样适用7bit量化下，",{"type":17,"tag":33,"props":682,"children":683},{},[684],{"type":23,"value":685},"精度损失仍不超过1%",{"type":23,"value":233},{"type":17,"tag":25,"props":688,"children":689},{},[690],{"type":23,"value":691},"mobilenet_v2",{"type":17,"tag":25,"props":693,"children":694},{},[695],{"type":23,"value":696},"ACC",{"type":17,"tag":25,"props":698,"children":699},{},[700],{"type":23,"value":701},"(On ImageNet)",{"type":17,"tag":25,"props":703,"children":704},{},[705],{"type":23,"value":706},"FP32",{"type":17,"tag":25,"props":708,"children":709},{},[710],{"type":23,"value":711},"71.56%",{"type":17,"tag":25,"props":713,"children":714},{},[715],{"type":23,"value":716},"A8W8",{"type":17,"tag":25,"props":718,"children":719},{},[720],{"type":23,"value":721},"71.16%",{"type":17,"tag":25,"props":723,"children":724},{},[725],{"type":23,"value":726},"(TF Lite官网后量化ACC：63.7%)",{"type":17,"tag":25,"props":728,"children":729},{},[730],{"type":23,"value":716},{"type":17,"tag":25,"props":732,"children":733},{},[734],{"type":23,"value":735},"(不做BiasCorrection)",{"type":17,"tag":25,"props":737,"children":738},{},[739],{"type":23,"value":740},"70.74%",{"type":17,"tag":25,"props":742,"children":743},{},[744],{"type":23,"value":745},"A8W7",{"type":17,"tag":25,"props":747,"children":748},{},[749],{"type":23,"value":750},"71.06%",{"type":17,"tag":25,"props":752,"children":753},{},[754],{"type":23,"value":755},"A7W7",{"type":17,"tag":25,"props":757,"children":758},{},[759],{"type":23,"value":760},"70.78%",{"type":17,"tag":25,"props":762,"children":763},{},[764],{"type":23,"value":765},"训练后全量化mobilenet_v2模型精度对比",{"type":17,"tag":25,"props":767,"children":768},{},[769],{"type":23,"value":770},"我们在HMS Face场景下模型进行了INT8权重量化(模型size范围364KB~2.9MB)，实际端到端识别精度完全满足服务要求。权重量化精度损失矫正方案的相对精度误差对比如下，可以看到损失矫正方案下量化精度损失有明显降低。",{"type":17,"tag":25,"props":772,"children":773},{},[774],{"type":23,"value":775},"模型",{"type":17,"tag":25,"props":777,"children":778},{},[779],{"type":23,"value":780},"Int8",{"type":17,"tag":25,"props":782,"children":783},{},[784],{"type":23,"value":785},"Int8+BiasCorrection",{"type":17,"tag":25,"props":787,"children":788},{},[789],{"type":23,"value":790},"face_tracking",{"type":17,"tag":25,"props":792,"children":793},{},[794],{"type":23,"value":795},"1.28214%",{"type":17,"tag":25,"props":797,"children":798},{},[799],{"type":23,"value":800},"1.00386%",{"type":17,"tag":25,"props":802,"children":803},{},[804],{"type":23,"value":805},"face_age",{"type":17,"tag":25,"props":807,"children":808},{},[809],{"type":23,"value":810},"8.40158%",{"type":17,"tag":25,"props":812,"children":813},{},[814],{"type":23,"value":815},"3.21885%",{"type":17,"tag":25,"props":817,"children":818},{},[819],{"type":23,"value":820},"face_beard",{"type":17,"tag":25,"props":822,"children":823},{},[824],{"type":23,"value":825},"3.72371%",{"type":17,"tag":25,"props":827,"children":828},{},[829],{"type":23,"value":830},"1.50271%",{"type":17,"tag":25,"props":832,"children":833},{},[834],{"type":23,"value":835},"face_contour",{"type":17,"tag":25,"props":837,"children":838},{},[839],{"type":23,"value":840},"0.196258%",{"type":17,"tag":25,"props":842,"children":843},{},[844],{"type":23,"value":845},"0.129654%",{"type":17,"tag":25,"props":847,"children":848},{},[849],{"type":23,"value":850},"face_emotion",{"type":17,"tag":25,"props":852,"children":853},{},[854],{"type":23,"value":855},"17.5848%",{"type":17,"tag":25,"props":857,"children":858},{},[859],{"type":23,"value":860},"3.19592%",{"type":17,"tag":25,"props":862,"children":863},{},[864],{"type":23,"value":865},"face_glasses",{"type":17,"tag":25,"props":867,"children":868},{},[869],{"type":23,"value":870},"5.8514%",{"type":17,"tag":25,"props":872,"children":873},{},[874],{"type":23,"value":875},"2.73312%",{"type":17,"tag":25,"props":877,"children":878},{},[879],{"type":23,"value":880},"Face场景模型权重量化精度损失矫正方案相对精度损失对比",{"type":17,"tag":25,"props":882,"children":883},{},[884],{"type":23,"value":885},"经内部大量测试和实际商用交付反馈，pipeline组合量化方法效果显著，甚至小至300KB的模型，经INT8量化压缩后精度仍满足商用要求。",{"type":17,"tag":25,"props":887,"children":888},{},[889],{"type":23,"value":890},"4. 易用性增强",{"type":17,"tag":108,"props":892,"children":894},{"id":893},"_8",[],{"type":17,"tag":25,"props":896,"children":897},{},[898],{"type":23,"value":899},"4.1 加速库自动裁剪工具",{"type":17,"tag":108,"props":901,"children":903},{"id":902},"为了满足部分对发布包大小有极致小型化诉求的场景我们提供了一个一键式裁剪工具该工具可以根据用户指定的模型列表自动裁剪出足以运行列表中指定模型的最小化mindspore-lite版本",[904,906,911],{"type":23,"value":905},"为了满足部分对发布包大小有极致小型化诉求的场景，我们提供了一个一键式裁剪工具，该工具可以根据用户指定的模型列表，",{"type":17,"tag":33,"props":907,"children":908},{},[909],{"type":23,"value":910},"自动裁剪出足以运行列表中指定模型的最小化MindSpore Lite版本",{"type":23,"value":233},{"type":17,"tag":108,"props":913,"children":915},{"id":914},"_9",[],{"type":17,"tag":25,"props":917,"children":918},{},[919],{"type":23,"value":920},"4.2 离线工具参数精简",{"type":17,"tag":25,"props":922,"children":923},{},[924,926,931],{"type":23,"value":925},"我们对离线转换工具参数进行了精简，",{"type":17,"tag":33,"props":927,"children":928},{},[929],{"type":23,"value":930},"最大程度地提高转换工具的易用性",{"type":23,"value":932},"，让开发者在转换三方模型时，无需感知三方模型的量化类型、输入输出节点名称和对应的数据类型等。",{"type":17,"tag":108,"props":934,"children":936},{"id":935},"_10",[],{"type":17,"tag":25,"props":938,"children":939},{},[940],{"type":23,"value":941},"4.3 支持Java接口",{"type":17,"tag":25,"props":943,"children":944},{},[945,947,952,954,959],{"type":23,"value":946},"1.1版本正式开放了Java接口，以方便安卓开发者",{"type":17,"tag":33,"props":948,"children":949},{},[950],{"type":23,"value":951},"更简单",{"type":23,"value":953},"的使用MindSpore Lite进行",{"type":17,"tag":33,"props":955,"children":956},{},[957],{"type":23,"value":958},"应用开发",{"type":23,"value":233},{"type":17,"tag":108,"props":961,"children":963},{"id":962},"_11",[],{"type":17,"tag":25,"props":965,"children":966},{},[967],{"type":23,"value":968},"4.4 模型可视化",{"type":17,"tag":25,"props":970,"children":971},{},[972,974,979,981,986],{"type":23,"value":973},"为了方便开发者调试，我们在Netron开源社区提交了支持MindSpore Lite模型可视化的代码，现在开发者可以使用Netron工具可视化MindSpore Lite模型。相信能",{"type":17,"tag":33,"props":975,"children":976},{},[977],{"type":23,"value":978},"给开发者调试模型",{"type":23,"value":980},"，尤其是一些结构复杂的模型，",{"type":17,"tag":33,"props":982,"children":983},{},[984],{"type":23,"value":985},"带来极大的方便",{"type":23,"value":233},{"type":17,"tag":25,"props":988,"children":989},{},[990],{"type":23,"value":991},"5. 开放更多的端侧预置模型",{"type":17,"tag":25,"props":993,"children":994},{},[995,997,1002,1004,1009,1011,1017],{"type":23,"value":996},"为了方便开发者在端侧",{"type":17,"tag":33,"props":998,"children":999},{},[1000],{"type":23,"value":1001},"快速部署",{"type":23,"value":1003},"自己的",{"type":17,"tag":33,"props":1005,"children":1006},{},[1007],{"type":23,"value":1008},"AI业务",{"type":23,"value":1010},"，MindSpore开放了更多的适合端侧使用的模型，其中不乏一些MindSpore首发的原创模型，这些模型可以方便的在MindSpore Hub(链接：",{"type":17,"tag":94,"props":1012,"children":1015},{"href":1013,"rel":1014},"https://www.mindspore.cn/resources/hub",[98],[1016],{"type":23,"value":1013},{"type":23,"value":1018},")上获取。",{"type":17,"tag":25,"props":1020,"children":1021},{},[1022,1024],{"type":23,"value":1023},"1. ",{"type":17,"tag":33,"props":1025,"children":1026},{},[1027],{"type":23,"value":1028},"使用SCOP算法在Oxford-III Pet数据集对ResNet50网络剪枝的模型",{"type":17,"tag":25,"props":1030,"children":1031},{},[1032,1034,1039,1041,1053,1055,1060],{"type":23,"value":1033},"SCOP：Scientific Control for Reliable Neural Network Pruning，是华为诺亚方舟实验室和北京大学联合提出了一种科学控制机制最小化剪枝节点对网络输出的影响。采用这种剪枝方法，能够实现ImageNet数据集上",{"type":17,"tag":33,"props":1035,"children":1036},{},[1037],{"type":23,"value":1038},"仅损失",{"type":23,"value":1040},"ResNet101网络",{"type":17,"tag":33,"props":1042,"children":1043},{},[1044,1046,1051],{"type":23,"value":1045},"0.01%",{"type":17,"tag":33,"props":1047,"children":1048},{},[1049],{"type":23,"value":1050},"的top-1准确率，模型",{"type":23,"value":1052},"参数量",{"type":23,"value":1054},"和计算量分别",{"type":17,"tag":33,"props":1056,"children":1057},{},[1058],{"type":23,"value":1059},"减少57.8%和60.2%",{"type":23,"value":1061},"，显著优于SOTA方法。",{"type":17,"tag":25,"props":1063,"children":1064},{},[1065],{"type":23,"value":1066},"模型链接：",{"type":17,"tag":25,"props":1068,"children":1069},{},[1070],{"type":17,"tag":94,"props":1071,"children":1074},{"href":1072,"rel":1073},"https://www.mindspore.cn/resources/hub/details?noah-cvlab/gpu/1.0/resnet-0.65x_v1.0_oxford_pets",[98],[1075],{"type":23,"value":1072},{"type":17,"tag":25,"props":1077,"children":1078},{},[1079,1081],{"type":23,"value":1080},"2. ",{"type":17,"tag":33,"props":1082,"children":1083},{},[1084],{"type":23,"value":1085},"基于SLB轻量化技术的模型VGG-Small",{"type":17,"tag":25,"props":1087,"children":1088},{},[1089],{"type":23,"value":1090},"该模型使用华为诺亚方舟实验室入选NeurIPS 2020模型轻量化技术中的SLB量化技术(Searching for Low-Bit Weights in Quantized Neural NetWorks)，在CIFAR10上基于2-bit weight和2-bit activation量化得到的端侧模型。",{"type":17,"tag":25,"props":1092,"children":1093},{},[1094],{"type":23,"value":1066},{"type":17,"tag":25,"props":1096,"children":1097},{},[1098],{"type":17,"tag":94,"props":1099,"children":1102},{"href":1100,"rel":1101},"https://www.mindspore.cn/resources/hub/details?noah-cvlab/gpu/1.0/VGG-Small-low-bit_cifar10",[98],[1103],{"type":23,"value":1100},{"type":17,"tag":25,"props":1105,"children":1106},{},[1107],{"type":23,"value":1108},"如果想了解更多关于以上MindSpore首发模型中使用的轻量化技术，请参考",{"type":17,"tag":25,"props":1110,"children":1111},{},[1112],{"type":17,"tag":94,"props":1113,"children":1116},{"href":1114,"rel":1115},"http://mp.weixin.qq.com/s?__biz=MzAxMDA1MDM0NQ==&mid=2247502325&idx=1&sn=5c7e21d06f04a0f62759c945d9243a90&chksm=9b54c7b3ac234ea50b4bac9f1bbe0fcc571cb848e15e6ab1dd2ac0927967556804b6800cf675&scene=21#wechat_redirect",[98],[1117],{"type":23,"value":1118},"MindSpore首发：诺亚NeurIPS 2020多篇轻量化技术端侧模型",{"title":7,"searchDepth":1120,"depth":1120,"links":1121},4,[1122,1124,1127,1128,1131,1132,1133,1134,1135,1142,1143,1145,1146,1147],{"id":7,"depth":1123,"text":7},2,{"id":151,"depth":1123,"text":7,"children":1125},[1126],{"id":161,"depth":1120,"text":164},{"id":215,"depth":1123,"text":7},{"id":303,"depth":1123,"text":7,"children":1129},[1130],{"id":312,"depth":1120,"text":315},{"id":335,"depth":1123,"text":7},{"id":408,"depth":1123,"text":7},{"id":437,"depth":1123,"text":7},{"id":461,"depth":1123,"text":7},{"id":470,"depth":1123,"text":473,"children":1136},[1137,1140,1141],{"id":477,"depth":1138,"text":1139},3,"1.2.1 ARM CPU",{"id":510,"depth":1138,"text":516},{"id":524,"depth":1138,"text":530},{"id":893,"depth":1123,"text":7},{"id":902,"depth":1123,"text":1144},"为了满足部分对发布包大小有极致小型化诉求的场景，我们提供了一个一键式裁剪工具，该工具可以根据用户指定的模型列表，自动裁剪出足以运行列表中指定模型的最小化MindSpore Lite版本。",{"id":914,"depth":1123,"text":7},{"id":935,"depth":1123,"text":7},{"id":962,"depth":1123,"text":7},"markdown","content:technology-blogs:zh:370.md","content","technology-blogs/zh/370.md","technology-blogs/zh/370","md",1776506133319]