> \u53c2\u6570\uff1a teacher_var_name (str): teacher_var\u7684\u540d\u79f0. student_var_name (str): student_var\u7684\u540d\u79f0. program (Program): \u7528\u4e8e\u84b8\u998f\u8bad\u7ec3\u7684fluid program\u3002\u9ed8\u8ba4\u503c\uff1a fluid.default_main_program() teacher_temperature (float): \u5bf9teacher_var\u8fdb\u884csoft\u64cd\u4f5c\u7684\u6e29\u5ea6\u503c\uff0c\u6e29\u5ea6\u503c\u8d8a\u5927\u5f97\u5230\u7684\u7279\u5f81\u56fe\u8d8a\u5e73\u6ed1 student_temperature (float): \u5bf9student_var\u8fdb\u884csoft\u64cd\u4f5c\u7684\u6e29\u5ea6\u503c\uff0c\u6e29\u5ea6\u503c\u8d8a\u5927\u5f97\u5230\u7684\u7279\u5f81\u56fe\u8d8a\u5e73\u6ed1 \u8fd4\u56de\uff1a \u7531teacher_var, student_var\u7ec4\u5408\u5f97\u5230\u7684soft_label_loss \u4f7f\u7528\u793a\u4f8b\uff1a 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 import paddle.fluid as fluid import paddleslim.dist as dist student_program = fluid . Program () with fluid . program_guard ( student_program ): x = fluid . layers . data ( name = 'x' , shape = [ 1 , 28 , 28 ]) conv = fluid . layers . conv2d ( x , 32 , 1 , name = 's1' ) out = fluid . layers . conv2d ( conv , 64 , 3 , padding = 1 , name = 's2' ) teacher_program = fluid . Program () with fluid . program_guard ( teacher_program ): y = fluid . layers . data ( name = 'y' , shape = [ 1 , 28 , 28 ]) conv = fluid . layers . conv2d ( y , 32 , 1 , name = 't1' ) conv = fluid . layers . conv2d ( conv , 32 , 3 , padding = 1 ) out = fluid . layers . conv2d ( conv , 64 , 3 , padding = 1 , name = 't2' ) data_name_map = { 'y' : 'x' } USE_GPU = False place = fluid . CUDAPlace ( 0 ) if USE_GPU else fluid . CPUPlace () main_program = merge ( teacher_program , student_program , data_name_map , place ) with fluid . program_guard ( main_program ): distillation_loss = dist . soft_label_loss ( 'teacher_t2.tmp_1' , 's2.tmp_1' , main_program , 1. , 1. )","title":"soft_label_loss"},{"location":"api/single_distiller_api/#loss","text":"paddleslim.dist.loss(loss_func, program=fluid.default_main_program(), **kwargs) [\u6e90\u4ee3\u7801] loss\u51fd\u6570\u652f\u6301\u5bf9\u4efb\u610f\u591a\u5bf9teacher_var\u548cstudent_var\u4f7f\u7528\u81ea\u5b9a\u4e49\u635f\u5931\u51fd\u6570 \u53c2\u6570\uff1a loss_func (python function): \u81ea\u5b9a\u4e49\u7684\u635f\u5931\u51fd\u6570\uff0c\u8f93\u5165\u4e3ateacher var\u548cstudent var\uff0c\u8f93\u51fa\u4e3a\u81ea\u5b9a\u4e49\u7684loss program (Program): \u7528\u4e8e\u84b8\u998f\u8bad\u7ec3\u7684fluid program\u3002\u9ed8\u8ba4\u503c\uff1a fluid.default_main_program() **kwargs : loss_func\u8f93\u5165\u540d\u4e0e\u5bf9\u5e94variable\u540d\u79f0 \u8fd4\u56de \uff1a\u81ea\u5b9a\u4e49\u7684\u635f\u5931\u51fd\u6570loss \u4f7f\u7528\u793a\u4f8b\uff1a 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 import paddle.fluid as fluid import paddleslim.dist as dist student_program = fluid . Program () with fluid . program_guard ( student_program ): x = fluid . layers . data ( name = 'x' , shape = [ 1 , 28 , 28 ]) conv = fluid . layers . conv2d ( x , 32 , 1 , name = 's1' ) out = fluid . layers . conv2d ( conv , 64 , 3 , padding = 1 , name = 's2' ) teacher_program = fluid . Program () with fluid . program_guard ( teacher_program ): y = fluid . layers . data ( name = 'y' , shape = [ 1 , 28 , 28 ]) conv = fluid . layers . conv2d ( y , 32 , 1 , name = 't1' ) conv = fluid . layers . conv2d ( conv , 32 , 3 , padding = 1 ) out = fluid . layers . conv2d ( conv , 64 , 3 , padding = 1 , name = 't2' ) data_name_map = { 'y' : 'x' } USE_GPU = False place = fluid . CUDAPlace ( 0 ) if USE_GPU else fluid . CPUPlace () main_program = merge ( teacher_program , student_program , data_name_map , place ) def adaptation_loss ( t_var , s_var ): teacher_channel = t_var . shape [ 1 ] s_hint = fluid . layers . conv2d ( s_var , teacher_channel , 1 ) hint_loss = fluid . layers . reduce_mean ( fluid . layers . square ( s_hint - t_var )) return hint_loss with fluid . program_guard ( main_program ): distillation_loss = dist . loss ( main_program , adaptation_loss , t_var = 'teacher_t2.tmp_1' , s_var = 's2.tmp_1' ) \u6ce8\u610f\u4e8b\u9879 \u5728\u6dfb\u52a0\u84b8\u998floss\u65f6\u4f1a\u5f15\u5165\u65b0\u7684variable\uff0c\u9700\u8981\u6ce8\u610f\u65b0\u5f15\u5165\u7684variable\u4e0d\u8981\u4e0estudent variables\u547d\u540d\u51b2\u7a81\u3002\u8fd9\u91cc\u5efa\u8bae\u4e24\u79cd\u7528\u6cd5\uff08\u4e24\u79cd\u65b9\u6cd5\u4efb\u9009\u5176\u4e00\u5373\u53ef\uff09\uff1a \u5efa\u8bae\u4e0estudent_program\u4f7f\u7528\u540c\u4e00\u4e2a\u547d\u540d\u7a7a\u95f4\uff0c\u4ee5\u907f\u514d\u4e00\u4e9b\u672a\u6307\u5b9a\u540d\u79f0\u7684variables(\u4f8b\u5982tmp_0, tmp_1...)\u591a\u6b21\u5b9a\u4e49\u4e3a\u540c\u4e00\u540d\u79f0\u51fa\u73b0\u547d\u540d\u51b2\u7a81 \u5efa\u8bae\u5728\u6dfb\u52a0\u84b8\u998floss\u65f6\u6307\u5b9a\u4e00\u4e2a\u547d\u540d\u7a7a\u95f4\u524d\u7f00\uff0c\u5177\u4f53\u7528\u6cd5\u8bf7\u53c2\u8003Paddle\u5b98\u65b9\u6587\u6863 fluid.name_scope","title":"loss"},{"location":"tutorials/demo_guide/","text":"\u84b8\u998f # \u84b8\u998fdemo\u9ed8\u8ba4\u4f7f\u7528ResNet50\u4f5c\u4e3ateacher\u7f51\u7edc\uff0cMobileNet\u4f5c\u4e3astudent\u7f51\u7edc\uff0c\u6b64\u5916\u8fd8\u652f\u6301\u5c06teacher\u548cstudent\u6362\u6210 models\u76ee\u5f55 \u652f\u6301\u7684\u4efb\u610f\u6a21\u578b\u3002 demo\u4e2d\u5bf9teahcer\u6a21\u578b\u548cstudent\u6a21\u578b\u7684\u4e00\u5c42\u7279\u5f81\u56fe\u6dfb\u52a0\u4e86l2_loss\u7684\u84b8\u998f\u635f\u5931\u51fd\u6570\uff0c\u4f7f\u7528\u65f6\u4e5f\u53ef\u6839\u636e\u9700\u8981\u9009\u62e9fsp_loss, soft_label_loss\u4ee5\u53ca\u81ea\u5b9a\u4e49\u7684loss\u51fd\u6570\u3002 \u8bad\u7ec3\u9ed8\u8ba4\u4f7f\u7528\u7684\u662fcifar10\u6570\u636e\u96c6\uff0cpiecewise_decay\u5b66\u4e60\u7387\u8870\u51cf\u7b56\u7565\uff0cmomentum\u4f18\u5316\u5668\u8fdb\u884c120\u8f6e\u84b8\u998f\u8bad\u7ec3\u3002\u4f7f\u7528\u8005\u4e5f\u53ef\u4ee5\u7b80\u5355\u5730\u7528args\u53c2\u6570\u5207\u6362\u4e3a\u4f7f\u7528ImageNet\u6570\u636e\u96c6\uff0ccosine_decay\u5b66\u4e60\u7387\u8870\u51cf\u7b56\u7565\u7b49\u5176\u4ed6\u8bad\u7ec3\u914d\u7f6e\u3002 \u91cf\u5316 # \u91cf\u5316\u8bad\u7ec3demo\u6587\u6863 # \u79bb\u7ebf\u91cf\u5316demo\u6587\u6863 # Embedding\u91cf\u5316demo\u6587\u6863 # NAS # NAS\u793a\u4f8b #","title":"Demo guide"},{"location":"tutorials/demo_guide/#_1","text":"\u84b8\u998fdemo\u9ed8\u8ba4\u4f7f\u7528ResNet50\u4f5c\u4e3ateacher\u7f51\u7edc\uff0cMobileNet\u4f5c\u4e3astudent\u7f51\u7edc\uff0c\u6b64\u5916\u8fd8\u652f\u6301\u5c06teacher\u548cstudent\u6362\u6210 models\u76ee\u5f55 \u652f\u6301\u7684\u4efb\u610f\u6a21\u578b\u3002 demo\u4e2d\u5bf9teahcer\u6a21\u578b\u548cstudent\u6a21\u578b\u7684\u4e00\u5c42\u7279\u5f81\u56fe\u6dfb\u52a0\u4e86l2_loss\u7684\u84b8\u998f\u635f\u5931\u51fd\u6570\uff0c\u4f7f\u7528\u65f6\u4e5f\u53ef\u6839\u636e\u9700\u8981\u9009\u62e9fsp_loss, soft_label_loss\u4ee5\u53ca\u81ea\u5b9a\u4e49\u7684loss\u51fd\u6570\u3002 \u8bad\u7ec3\u9ed8\u8ba4\u4f7f\u7528\u7684\u662fcifar10\u6570\u636e\u96c6\uff0cpiecewise_decay\u5b66\u4e60\u7387\u8870\u51cf\u7b56\u7565\uff0cmomentum\u4f18\u5316\u5668\u8fdb\u884c120\u8f6e\u84b8\u998f\u8bad\u7ec3\u3002\u4f7f\u7528\u8005\u4e5f\u53ef\u4ee5\u7b80\u5355\u5730\u7528args\u53c2\u6570\u5207\u6362\u4e3a\u4f7f\u7528ImageNet\u6570\u636e\u96c6\uff0ccosine_decay\u5b66\u4e60\u7387\u8870\u51cf\u7b56\u7565\u7b49\u5176\u4ed6\u8bad\u7ec3\u914d\u7f6e\u3002","title":"\u84b8\u998f"},{"location":"tutorials/demo_guide/#_2","text":"","title":"\u91cf\u5316"},{"location":"tutorials/demo_guide/#demo","text":"","title":"\u91cf\u5316\u8bad\u7ec3demo\u6587\u6863"},{"location":"tutorials/demo_guide/#demo_1","text":"","title":"\u79bb\u7ebf\u91cf\u5316demo\u6587\u6863"},{"location":"tutorials/demo_guide/#embeddingdemo","text":"","title":"Embedding\u91cf\u5316demo\u6587\u6863"},{"location":"tutorials/demo_guide/#nas","text":"","title":"NAS"},{"location":"tutorials/demo_guide/#nas_1","text":"","title":"NAS\u793a\u4f8b"},{"location":"tutorials/distillation_demo/","text":"\u672c\u793a\u4f8b\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528PaddleSlim\u84b8\u998f\u63a5\u53e3\u6765\u5bf9\u6a21\u578b\u8fdb\u884c\u84b8\u998f\u8bad\u7ec3 \u63a5\u53e3\u4ecb\u7ecd # \u8bf7\u53c2\u8003 \u84b8\u998fAPI\u6587\u6863 \u3002 PaddleSlim\u84b8\u998f\u8bad\u7ec3\u6d41\u7a0b # \u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u6a21\u578b\u53c2\u6570\u91cf\u8d8a\u591a\uff0c\u7ed3\u6784\u8d8a\u590d\u6742\uff0c\u5176\u6027\u80fd\u8d8a\u597d\uff0c\u4f46\u8fd0\u7b97\u91cf\u548c\u8d44\u6e90\u6d88\u8017\u4e5f\u8d8a\u5927\u3002 \u77e5\u8bc6\u84b8\u998f \u5c31\u662f\u4e00\u79cd\u5c06\u5927\u6a21\u578b\u5b66\u4e60\u5230\u7684\u6709\u7528\u4fe1\u606f\uff08Dark Knowledge\uff09\u538b\u7f29\u8fdb\u66f4\u5c0f\u66f4\u5feb\u7684\u6a21\u578b\uff0c\u800c\u83b7\u5f97\u53ef\u4ee5\u5339\u654c\u5927\u6a21\u578b\u7ed3\u679c\u7684\u65b9\u6cd5\u3002 \u5728\u672c\u793a\u4f8b\u4e2d\u7cbe\u5ea6\u8f83\u9ad8\u7684\u5927\u6a21\u578b\u88ab\u79f0\u4e3ateacher\uff0c\u7cbe\u5ea6\u7a0d\u900a\u4f46\u901f\u5ea6\u66f4\u5feb\u7684\u5c0f\u6a21\u578b\u88ab\u79f0\u4e3astudent\u3002 1. \u5b9a\u4e49student_program # 1 2 3 4 5 6 7 8 9 10 11 student_program = fluid . Program () student_startup = fluid . Program () with fluid . program_guard ( student_program , student_startup ): image = fluid . data ( name = 'image' , shape = [ None ] + [ 3 , 224 , 224 ], dtype = 'float32' ) label = fluid . data ( name = 'label' , shape = [ None , 1 ], dtype = 'int64' ) # student model definition model = MobileNet () out = model . net ( input = image , class_dim = 1000 ) cost = fluid . layers . cross_entropy ( input = out , label = label ) avg_cost = fluid . layers . mean ( x = cost ) 2. \u5b9a\u4e49teacher_program # \u5728\u5b9a\u4e49\u597dteacher_program\u540e\uff0c\u53ef\u4ee5\u4e00\u5e76\u52a0\u8f7d\u8bad\u7ec3\u597d\u7684pretrained_model \u5728teacher_program\u5185\u9700\u8981\u52a0\u4e0a with fluid.unique_name.guard(): \uff0c\u4fdd\u8bc1teacher\u7684\u53d8\u91cf\u547d\u540d\u4e0d\u88abstudent_program\u5f71\u54cd\uff0c\u4ece\u800c\u8ddf\u80fd\u591f\u6b63\u786e\u5730\u52a0\u8f7d\u9884\u8bad\u7ec3\u53c2\u6570 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 teacher_program = fluid . Program () teacher_startup = fluid . Program () with fluid . program_guard ( teacher_program , teacher_startup ): with fluid . unique_name . guard (): image = fluid . data ( name = 'data' , shape = [ None ] + [ 3 , 224 , 224 ], dtype = 'float32' ) # teacher model definition teacher_model = ResNet () predict = teacher_model . net ( image , class_dim = 1000 ) exe . run ( teacher_startup ) def if_exist ( var ): return os . path . exists ( os . path . join ( \"./pretrained\" , var . name ) fluid . io . load_vars ( exe , \"./pretrained\" , main_program = teacher_program , predicate = if_exist ) 3.\u9009\u62e9\u7279\u5f81\u56fe # \u5b9a\u4e49\u597dstudent_program\u548cteacher_program\u540e\uff0c\u6211\u4eec\u9700\u8981\u4ece\u4e2d\u4e24\u4e24\u5bf9\u5e94\u5730\u6311\u9009\u51fa\u82e5\u5e72\u4e2a\u7279\u5f81\u56fe\uff0c\u7559\u5f85\u540e\u7eed\u4e3a\u5176\u6dfb\u52a0\u77e5\u8bc6\u84b8\u998f\u635f\u5931\u51fd\u6570 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 # get all student variables student_vars = [] for v in student_program . list_vars (): try : student_vars . append (( v . name , v . shape )) except : pass print ( \"=\" * 50 + \"student_model_vars\" + \"=\" * 50 ) print ( student_vars ) # get all teacher variables teacher_vars = [] for v in teacher_program . list_vars (): try : teacher_vars . append (( v . name , v . shape )) except : pass print ( \"=\" * 50 + \"teacher_model_vars\" + \"=\" * 50 ) print ( teacher_vars ) 4. \u5408\u5e76Program\uff08merge\uff09 # PaddlePaddle\u4f7f\u7528Program\u6765\u63cf\u8ff0\u8ba1\u7b97\u56fe\uff0c\u4e3a\u4e86\u540c\u65f6\u8ba1\u7b97student\u548cteacher\u4e24\u4e2aProgram\uff0c\u8fd9\u91cc\u9700\u8981\u5c06\u5176\u4e24\u8005\u5408\u5e76\uff08merge\uff09\u4e3a\u4e00\u4e2aProgram\u3002 merge\u8fc7\u7a0b\u64cd\u4f5c\u8f83\u591a\uff0c\u5177\u4f53\u7ec6\u8282\u8bf7\u53c2\u8003 merge API\u6587\u6863 \u3002 1 2 data_name_map = { 'data' : 'image' } student_program = merge ( teacher_program , student_program , data_name_map , place ) 5.\u6dfb\u52a0\u84b8\u998floss # \u5728\u6dfb\u52a0\u84b8\u998floss\u7684\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u80fd\u8fd8\u4f1a\u5f15\u5165\u90e8\u5206\u53d8\u91cf\uff08Variable\uff09\uff0c\u4e3a\u4e86\u907f\u514d\u547d\u540d\u91cd\u590d\u8fd9\u91cc\u53ef\u4ee5\u4f7f\u7528 with fluid.name_scope(\"distill\"): \u4e3a\u65b0\u5f15\u5165\u7684\u53d8\u91cf\u52a0\u4e00\u4e2a\u547d\u540d\u4f5c\u7528\u57df 1 2 3 4 5 6 7 8 with fluid . program_guard ( student_program , student_startup ): with fluid . name_scope ( \"distill\" ): distill_loss = l2_loss ( 'teacher_bn5c_branch2b.output.1.tmp_3' , 'depthwise_conv2d_11.tmp_0' , main ) distill_weight = 1 loss = avg_cost + distill_loss * distill_weight opt = create_optimizer () opt . minimize ( loss ) exe . run ( student_startup ) \u81f3\u6b64\uff0c\u6211\u4eec\u5c31\u5f97\u5230\u4e86\u7528\u4e8e\u84b8\u998f\u8bad\u7ec3\u7684student_program\uff0c\u540e\u9762\u5c31\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u666e\u901aprogram\u4e00\u6837\u5bf9\u5176\u5f00\u59cb\u8bad\u7ec3\u548c\u8bc4\u4f30","title":"\u77e5\u8bc6\u84b8\u998f"},{"location":"tutorials/distillation_demo/#_1","text":"\u8bf7\u53c2\u8003 \u84b8\u998fAPI\u6587\u6863 \u3002","title":"\u63a5\u53e3\u4ecb\u7ecd"},{"location":"tutorials/distillation_demo/#paddleslim","text":"\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u6a21\u578b\u53c2\u6570\u91cf\u8d8a\u591a\uff0c\u7ed3\u6784\u8d8a\u590d\u6742\uff0c\u5176\u6027\u80fd\u8d8a\u597d\uff0c\u4f46\u8fd0\u7b97\u91cf\u548c\u8d44\u6e90\u6d88\u8017\u4e5f\u8d8a\u5927\u3002 \u77e5\u8bc6\u84b8\u998f \u5c31\u662f\u4e00\u79cd\u5c06\u5927\u6a21\u578b\u5b66\u4e60\u5230\u7684\u6709\u7528\u4fe1\u606f\uff08Dark Knowledge\uff09\u538b\u7f29\u8fdb\u66f4\u5c0f\u66f4\u5feb\u7684\u6a21\u578b\uff0c\u800c\u83b7\u5f97\u53ef\u4ee5\u5339\u654c\u5927\u6a21\u578b\u7ed3\u679c\u7684\u65b9\u6cd5\u3002 \u5728\u672c\u793a\u4f8b\u4e2d\u7cbe\u5ea6\u8f83\u9ad8\u7684\u5927\u6a21\u578b\u88ab\u79f0\u4e3ateacher\uff0c\u7cbe\u5ea6\u7a0d\u900a\u4f46\u901f\u5ea6\u66f4\u5feb\u7684\u5c0f\u6a21\u578b\u88ab\u79f0\u4e3astudent\u3002","title":"PaddleSlim\u84b8\u998f\u8bad\u7ec3\u6d41\u7a0b"},{"location":"tutorials/distillation_demo/#1-student_program","text":"1 2 3 4 5 6 7 8 9 10 11 student_program = fluid . Program () student_startup = fluid . Program () with fluid . program_guard ( student_program , student_startup ): image = fluid . data ( name = 'image' , shape = [ None ] + [ 3 , 224 , 224 ], dtype = 'float32' ) label = fluid . data ( name = 'label' , shape = [ None , 1 ], dtype = 'int64' ) # student model definition model = MobileNet () out = model . net ( input = image , class_dim = 1000 ) cost = fluid . layers . cross_entropy ( input = out , label = label ) avg_cost = fluid . layers . mean ( x = cost )","title":"1. \u5b9a\u4e49student_program"},{"location":"tutorials/distillation_demo/#2-teacher_program","text":"\u5728\u5b9a\u4e49\u597dteacher_program\u540e\uff0c\u53ef\u4ee5\u4e00\u5e76\u52a0\u8f7d\u8bad\u7ec3\u597d\u7684pretrained_model \u5728teacher_program\u5185\u9700\u8981\u52a0\u4e0a with fluid.unique_name.guard(): \uff0c\u4fdd\u8bc1teacher\u7684\u53d8\u91cf\u547d\u540d\u4e0d\u88abstudent_program\u5f71\u54cd\uff0c\u4ece\u800c\u8ddf\u80fd\u591f\u6b63\u786e\u5730\u52a0\u8f7d\u9884\u8bad\u7ec3\u53c2\u6570 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 teacher_program = fluid . Program () teacher_startup = fluid . Program () with fluid . program_guard ( teacher_program , teacher_startup ): with fluid . unique_name . guard (): image = fluid . data ( name = 'data' , shape = [ None ] + [ 3 , 224 , 224 ], dtype = 'float32' ) # teacher model definition teacher_model = ResNet () predict = teacher_model . net ( image , class_dim = 1000 ) exe . run ( teacher_startup ) def if_exist ( var ): return os . path . exists ( os . path . join ( \"./pretrained\" , var . name ) fluid . io . load_vars ( exe , \"./pretrained\" , main_program = teacher_program , predicate = if_exist )","title":"2. \u5b9a\u4e49teacher_program"},{"location":"tutorials/distillation_demo/#3","text":"\u5b9a\u4e49\u597dstudent_program\u548cteacher_program\u540e\uff0c\u6211\u4eec\u9700\u8981\u4ece\u4e2d\u4e24\u4e24\u5bf9\u5e94\u5730\u6311\u9009\u51fa\u82e5\u5e72\u4e2a\u7279\u5f81\u56fe\uff0c\u7559\u5f85\u540e\u7eed\u4e3a\u5176\u6dfb\u52a0\u77e5\u8bc6\u84b8\u998f\u635f\u5931\u51fd\u6570 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 # get all student variables student_vars = [] for v in student_program . list_vars (): try : student_vars . append (( v . name , v . shape )) except : pass print ( \"=\" * 50 + \"student_model_vars\" + \"=\" * 50 ) print ( student_vars ) # get all teacher variables teacher_vars = [] for v in teacher_program . list_vars (): try : teacher_vars . append (( v . name , v . shape )) except : pass print ( \"=\" * 50 + \"teacher_model_vars\" + \"=\" * 50 ) print ( teacher_vars )","title":"3.\u9009\u62e9\u7279\u5f81\u56fe"},{"location":"tutorials/distillation_demo/#4-programmerge","text":"PaddlePaddle\u4f7f\u7528Program\u6765\u63cf\u8ff0\u8ba1\u7b97\u56fe\uff0c\u4e3a\u4e86\u540c\u65f6\u8ba1\u7b97student\u548cteacher\u4e24\u4e2aProgram\uff0c\u8fd9\u91cc\u9700\u8981\u5c06\u5176\u4e24\u8005\u5408\u5e76\uff08merge\uff09\u4e3a\u4e00\u4e2aProgram\u3002 merge\u8fc7\u7a0b\u64cd\u4f5c\u8f83\u591a\uff0c\u5177\u4f53\u7ec6\u8282\u8bf7\u53c2\u8003 merge API\u6587\u6863 \u3002 1 2 data_name_map = { 'data' : 'image' } student_program = merge ( teacher_program , student_program , data_name_map , place )","title":"4. \u5408\u5e76Program\uff08merge\uff09"},{"location":"tutorials/distillation_demo/#5loss","text":"\u5728\u6dfb\u52a0\u84b8\u998floss\u7684\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u80fd\u8fd8\u4f1a\u5f15\u5165\u90e8\u5206\u53d8\u91cf\uff08Variable\uff09\uff0c\u4e3a\u4e86\u907f\u514d\u547d\u540d\u91cd\u590d\u8fd9\u91cc\u53ef\u4ee5\u4f7f\u7528 with fluid.name_scope(\"distill\"): \u4e3a\u65b0\u5f15\u5165\u7684\u53d8\u91cf\u52a0\u4e00\u4e2a\u547d\u540d\u4f5c\u7528\u57df 1 2 3 4 5 6 7 8 with fluid . program_guard ( student_program , student_startup ): with fluid . name_scope ( \"distill\" ): distill_loss = l2_loss ( 'teacher_bn5c_branch2b.output.1.tmp_3' , 'depthwise_conv2d_11.tmp_0' , main ) distill_weight = 1 loss = avg_cost + distill_loss * distill_weight opt = create_optimizer () opt . minimize ( loss ) exe . run ( student_startup ) \u81f3\u6b64\uff0c\u6211\u4eec\u5c31\u5f97\u5230\u4e86\u7528\u4e8e\u84b8\u998f\u8bad\u7ec3\u7684student_program\uff0c\u540e\u9762\u5c31\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u666e\u901aprogram\u4e00\u6837\u5bf9\u5176\u5f00\u59cb\u8bad\u7ec3\u548c\u8bc4\u4f30","title":"5.\u6dfb\u52a0\u84b8\u998floss"},{"location":"tutorials/nas_demo/","text":"\u7f51\u7edc\u7ed3\u6784\u641c\u7d22\u793a\u4f8b # \u672c\u793a\u4f8b\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u7f51\u7edc\u7ed3\u6784\u641c\u7d22\u63a5\u53e3\uff0c\u641c\u7d22\u5230\u4e00\u4e2a\u66f4\u5c0f\u6216\u8005\u7cbe\u5ea6\u66f4\u9ad8\u7684\u6a21\u578b\uff0c\u8be5\u6587\u6863\u4ec5\u4ecb\u7ecdpaddleslim\u4e2dSANAS\u7684\u4f7f\u7528\u53ca\u5982\u4f55\u5229\u7528SANAS\u5f97\u5230\u6a21\u578b\u7ed3\u6784\uff0c\u5b8c\u6574\u793a\u4f8b\u4ee3\u7801\u8bf7\u53c2\u8003sa_nas_mobilenetv2.py\u6216\u8005block_sa_nas_mobilenetv2.py\u3002 \u63a5\u53e3\u4ecb\u7ecd # \u8bf7\u53c2\u8003\u3002 1. \u914d\u7f6e\u641c\u7d22\u7a7a\u95f4 # \u8be6\u7ec6\u7684\u641c\u7d22\u7a7a\u95f4\u914d\u7f6e\u53ef\u4ee5\u53c2\u8003 \u795e\u7ecf\u7f51\u7edc\u641c\u7d22API\u6587\u6863 \u3002 1 config = [( 'MobileNetV2Space' )] 2. \u5229\u7528\u641c\u7d22\u7a7a\u95f4\u521d\u59cb\u5316SANAS\u5b9e\u4f8b # 1 2 3 4 5 6 7 8 9 from paddleslim.nas import SANAS sa_nas = SANAS ( config , server_addr = ( \"\" , 8881 ), init_temperature = 10.24 , reduce_rate = 0.85 , search_steps = 300 , is_server = True ) 3. \u6839\u636e\u5b9e\u4f8b\u5316\u7684NAS\u5f97\u5230\u5f53\u524d\u7684\u7f51\u7edc\u7ed3\u6784 # 1 archs = sa_nas . next_archs () 4. \u6839\u636e\u5f97\u5230\u7684\u7f51\u7edc\u7ed3\u6784\u548c\u8f93\u5165\u6784\u9020\u8bad\u7ec3\u548c\u6d4b\u8bd5program # 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 import paddle.fluid as fluid train_program = fluid . Program () test_program = fluid . Program () startup_program = fluid . Program () with fluid . program_guard ( train_program , startup_program ): data = fluid . data ( name = 'data' , shape = [ None , 3 , 32 , 32 ], dtype = 'float32' ) label = fluid . data ( name = 'label' , shape = [ None , 1 ], dtype = 'int64' ) for arch in archs : data = arch ( data ) output = fluid . layers . fc ( data , 10 ) softmax_out = fluid . layers . softmax ( input = output , use_cudnn = False ) cost = fluid . layers . cross_entropy ( input = softmax_out , label = label ) avg_cost = fluid . layers . mean ( cost ) acc_top1 = fluid . layers . accuracy ( input = softmax_out , label = label , k = 1 ) test_program = train_program . clone ( for_test = True ) sgd = fluid . optimizer . SGD ( learning_rate = 1e-3 ) sgd . minimize ( avg_cost ) 5. \u6839\u636e\u6784\u9020\u7684\u8bad\u7ec3program\u6dfb\u52a0\u9650\u5236\u6761\u4ef6 # 1 2 3 4 from paddleslim.analysis import flops if flops ( train_program ) > 321208544 : continue 6. \u56de\u4f20score # 1 sa_nas . reward ( score )","title":"SA\u641c\u7d22"},{"location":"tutorials/nas_demo/#_1","text":"\u672c\u793a\u4f8b\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u7f51\u7edc\u7ed3\u6784\u641c\u7d22\u63a5\u53e3\uff0c\u641c\u7d22\u5230\u4e00\u4e2a\u66f4\u5c0f\u6216\u8005\u7cbe\u5ea6\u66f4\u9ad8\u7684\u6a21\u578b\uff0c\u8be5\u6587\u6863\u4ec5\u4ecb\u7ecdpaddleslim\u4e2dSANAS\u7684\u4f7f\u7528\u53ca\u5982\u4f55\u5229\u7528SANAS\u5f97\u5230\u6a21\u578b\u7ed3\u6784\uff0c\u5b8c\u6574\u793a\u4f8b\u4ee3\u7801\u8bf7\u53c2\u8003sa_nas_mobilenetv2.py\u6216\u8005block_sa_nas_mobilenetv2.py\u3002","title":"\u7f51\u7edc\u7ed3\u6784\u641c\u7d22\u793a\u4f8b"},{"location":"tutorials/nas_demo/#_2","text":"\u8bf7\u53c2\u8003\u3002","title":"\u63a5\u53e3\u4ecb\u7ecd"},{"location":"tutorials/nas_demo/#1","text":"\u8be6\u7ec6\u7684\u641c\u7d22\u7a7a\u95f4\u914d\u7f6e\u53ef\u4ee5\u53c2\u8003 \u795e\u7ecf\u7f51\u7edc\u641c\u7d22API\u6587\u6863 \u3002 1 config = [( 'MobileNetV2Space' )]","title":"1. \u914d\u7f6e\u641c\u7d22\u7a7a\u95f4"},{"location":"tutorials/nas_demo/#2-sanas","text":"1 2 3 4 5 6 7 8 9 from paddleslim.nas import SANAS sa_nas = SANAS ( config , server_addr = ( \"\" , 8881 ), init_temperature = 10.24 , reduce_rate = 0.85 , search_steps = 300 , is_server = True )","title":"2. \u5229\u7528\u641c\u7d22\u7a7a\u95f4\u521d\u59cb\u5316SANAS\u5b9e\u4f8b"},{"location":"tutorials/nas_demo/#3-nas","text":"1 archs = sa_nas . next_archs ()","title":"3. \u6839\u636e\u5b9e\u4f8b\u5316\u7684NAS\u5f97\u5230\u5f53\u524d\u7684\u7f51\u7edc\u7ed3\u6784"},{"location":"tutorials/nas_demo/#4-program","text":"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 import paddle.fluid as fluid train_program = fluid . Program () test_program = fluid . Program () startup_program = fluid . Program () with fluid . program_guard ( train_program , startup_program ): data = fluid . data ( name = 'data' , shape = [ None , 3 , 32 , 32 ], dtype = 'float32' ) label = fluid . data ( name = 'label' , shape = [ None , 1 ], dtype = 'int64' ) for arch in archs : data = arch ( data ) output = fluid . layers . fc ( data , 10 ) softmax_out = fluid . layers . softmax ( input = output , use_cudnn = False ) cost = fluid . layers . cross_entropy ( input = softmax_out , label = label ) avg_cost = fluid . layers . mean ( cost ) acc_top1 = fluid . layers . accuracy ( input = softmax_out , label = label , k = 1 ) test_program = train_program . clone ( for_test = True ) sgd = fluid . optimizer . SGD ( learning_rate = 1e-3 ) sgd . minimize ( avg_cost )","title":"4. \u6839\u636e\u5f97\u5230\u7684\u7f51\u7edc\u7ed3\u6784\u548c\u8f93\u5165\u6784\u9020\u8bad\u7ec3\u548c\u6d4b\u8bd5program"},{"location":"tutorials/nas_demo/#5-program","text":"1 2 3 4 from paddleslim.analysis import flops if flops ( train_program ) > 321208544 : continue","title":"5. \u6839\u636e\u6784\u9020\u7684\u8bad\u7ec3program\u6dfb\u52a0\u9650\u5236\u6761\u4ef6"},{"location":"tutorials/nas_demo/#6-score","text":"1 sa_nas . reward ( score )","title":"6. \u56de\u4f20score"},{"location":"tutorials/quant_aware_demo/","text":"\u5728\u7ebf\u91cf\u5316\u793a\u4f8b # \u672c\u793a\u4f8b\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u5728\u7ebf\u91cf\u5316\u63a5\u53e3\uff0c\u6765\u5bf9\u8bad\u7ec3\u597d\u7684\u5206\u7c7b\u6a21\u578b\u8fdb\u884c\u91cf\u5316, \u53ef\u4ee5\u51cf\u5c11\u6a21\u578b\u7684\u5b58\u50a8\u7a7a\u95f4\u548c\u663e\u5b58\u5360\u7528\u3002 \u63a5\u53e3\u4ecb\u7ecd # \u8bf7\u53c2\u8003 \u91cf\u5316API\u6587\u6863 \u3002 \u5206\u7c7b\u6a21\u578b\u7684\u79bb\u7ebf\u91cf\u5316\u6d41\u7a0b # 1. \u914d\u7f6e\u91cf\u5316\u53c2\u6570 # 1 2 3 4 5 6 7 8 9 10 11 12 quant_config = { 'weight_quantize_type' : 'abs_max' , 'activation_quantize_type' : 'moving_average_abs_max' , 'weight_bits' : 8 , 'activation_bits' : 8 , 'not_quant_pattern' : [ 'skip_quant' ], 'quantize_op_types' : [ 'conv2d' , 'depthwise_conv2d' , 'mul' ], 'dtype' : 'int8' , 'window_size' : 10000 , 'moving_rate' : 0 . 9 , 'quant_weight_only' : False } 2. \u5bf9\u8bad\u7ec3\u548c\u6d4b\u8bd5program\u63d2\u5165\u53ef\u8bad\u7ec3\u91cf\u5316op # 1 2 3 val_program = quant_aware ( val_program , place , quant_config , scope = None , for_test = True ) compiled_train_prog = quant_aware ( train_prog , place , quant_config , scope = None , for_test = False ) 3.\u5173\u6389\u6307\u5b9abuild\u7b56\u7565 # 1 2 3 4 5 6 7 8 build_strategy = fluid . BuildStrategy () build_strategy . fuse_all_reduce_ops = False build_strategy . sync_batch_norm = False exec_strategy = fluid . ExecutionStrategy () compiled_train_prog = compiled_train_prog . with_data_parallel ( loss_name = avg_cost . name , build_strategy = build_strategy , exec_strategy = exec_strategy ) 4. freeze program # 1 2 3 4 5 float_program , int8_program = convert ( val_program , place , quant_config , scope = None , save_int8 = True ) 5.\u4fdd\u5b58\u9884\u6d4b\u6a21\u578b # 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 fluid . io . save_inference_model ( dirname = float_path , feeded_var_names = [ image . name ], target_vars = [ out ], executor = exe , main_program = float_program , model_filename = float_path + ' /model ' , params_filename = float_path + ' /params ' ) fluid . io . save_inference_model ( dirname = int8_path , feeded_var_names = [ image . name ], target_vars = [ out ], executor = exe , main_program = int8_program , model_filename = int8_path + ' /model ' , params_filename = int8_path + ' /params ' )","title":"\u91cf\u5316\u8bad\u7ec3"},{"location":"tutorials/quant_aware_demo/#_1","text":"\u672c\u793a\u4f8b\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u5728\u7ebf\u91cf\u5316\u63a5\u53e3\uff0c\u6765\u5bf9\u8bad\u7ec3\u597d\u7684\u5206\u7c7b\u6a21\u578b\u8fdb\u884c\u91cf\u5316, \u53ef\u4ee5\u51cf\u5c11\u6a21\u578b\u7684\u5b58\u50a8\u7a7a\u95f4\u548c\u663e\u5b58\u5360\u7528\u3002","title":"\u5728\u7ebf\u91cf\u5316\u793a\u4f8b"},{"location":"tutorials/quant_aware_demo/#_2","text":"\u8bf7\u53c2\u8003 \u91cf\u5316API\u6587\u6863 \u3002","title":"\u63a5\u53e3\u4ecb\u7ecd"},{"location":"tutorials/quant_aware_demo/#_3","text":"","title":"\u5206\u7c7b\u6a21\u578b\u7684\u79bb\u7ebf\u91cf\u5316\u6d41\u7a0b"},{"location":"tutorials/quant_aware_demo/#1","text":"1 2 3 4 5 6 7 8 9 10 11 12 quant_config = { 'weight_quantize_type' : 'abs_max' , 'activation_quantize_type' : 'moving_average_abs_max' , 'weight_bits' : 8 , 'activation_bits' : 8 , 'not_quant_pattern' : [ 'skip_quant' ], 'quantize_op_types' : [ 'conv2d' , 'depthwise_conv2d' , 'mul' ], 'dtype' : 'int8' , 'window_size' : 10000 , 'moving_rate' : 0 . 9 , 'quant_weight_only' : False }","title":"1. \u914d\u7f6e\u91cf\u5316\u53c2\u6570"},{"location":"tutorials/quant_aware_demo/#2-programop","text":"1 2 3 val_program = quant_aware ( val_program , place , quant_config , scope = None , for_test = True ) compiled_train_prog = quant_aware ( train_prog , place , quant_config , scope = None , for_test = False )","title":"2. \u5bf9\u8bad\u7ec3\u548c\u6d4b\u8bd5program\u63d2\u5165\u53ef\u8bad\u7ec3\u91cf\u5316op"},{"location":"tutorials/quant_aware_demo/#3build","text":"1 2 3 4 5 6 7 8 build_strategy = fluid . BuildStrategy () build_strategy . fuse_all_reduce_ops = False build_strategy . sync_batch_norm = False exec_strategy = fluid . ExecutionStrategy () compiled_train_prog = compiled_train_prog . with_data_parallel ( loss_name = avg_cost . name , build_strategy = build_strategy , exec_strategy = exec_strategy )","title":"3.\u5173\u6389\u6307\u5b9abuild\u7b56\u7565"},{"location":"tutorials/quant_aware_demo/#4-freeze-program","text":"1 2 3 4 5 float_program , int8_program = convert ( val_program , place , quant_config , scope = None , save_int8 = True )","title":"4. freeze program"},{"location":"tutorials/quant_aware_demo/#5","text":"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 fluid . io . save_inference_model ( dirname = float_path , feeded_var_names = [ image . name ], target_vars = [ out ], executor = exe , main_program = float_program , model_filename = float_path + ' /model ' , params_filename = float_path + ' /params ' ) fluid . io . save_inference_model ( dirname = int8_path , feeded_var_names = [ image . name ], target_vars = [ out ], executor = exe , main_program = int8_program , model_filename = int8_path + ' /model ' , params_filename = int8_path + ' /params ' )","title":"5.\u4fdd\u5b58\u9884\u6d4b\u6a21\u578b"},{"location":"tutorials/quant_embedding_demo/","text":"Embedding\u91cf\u5316\u793a\u4f8b # \u672c\u793a\u4f8b\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Embedding\u91cf\u5316\u7684\u63a5\u53e3 paddleslim.quant.quant_embedding \u3002 quant_embedding \u63a5\u53e3\u5c06\u7f51\u7edc\u4e2d\u7684Embedding\u53c2\u6570\u4ece float32 \u7c7b\u578b\u91cf\u5316\u5230 8-bit \u6574\u6570\u7c7b\u578b\uff0c\u5728\u51e0\u4e4e\u4e0d\u635f\u5931\u6a21\u578b\u7cbe\u5ea6\u7684\u60c5\u51b5\u4e0b\u51cf\u5c11\u6a21\u578b\u7684\u5b58\u50a8\u7a7a\u95f4\u548c\u663e\u5b58\u5360\u7528\u3002 \u63a5\u53e3\u4ecb\u7ecd\u8bf7\u53c2\u8003 \u91cf\u5316API\u6587\u6863 \u3002 \u8be5\u63a5\u53e3\u5bf9program\u7684\u4fee\u6539\uff1a \u91cf\u5316\u524d: \u56fe1\uff1a\u91cf\u5316\u524d\u7684\u6a21\u578b\u7ed3\u6784 \u91cf\u5316\u540e\uff1a \u56fe2: \u91cf\u5316\u540e\u7684\u6a21\u578b\u7ed3\u6784 \u4ee5\u4e0b\u5c06\u4ee5 \u57fa\u4e8eskip-gram\u7684word2vector\u6a21\u578b \u4e3a\u4f8b\u6765\u8bf4\u660e\u5982\u4f55\u4f7f\u7528 quant_embedding \u63a5\u53e3\u3002\u9996\u5148\u4ecb\u7ecd \u57fa\u4e8eskip-gram\u7684word2vector\u6a21\u578b \u7684\u6b63\u5e38\u8bad\u7ec3\u548c\u6d4b\u8bd5\u6d41\u7a0b\u3002 \u57fa\u4e8eskip-gram\u7684word2vector\u6a21\u578b # \u4ee5\u4e0b\u662f\u672c\u4f8b\u7684\u7b80\u8981\u76ee\u5f55\u7ed3\u6784\u53ca\u8bf4\u660e\uff1a 1 2 3 4 5 6 7 8 9 10 . \u251c\u2500\u2500 cluster_train.py # \u5206\u5e03\u5f0f\u8bad\u7ec3\u51fd\u6570 \u251c\u2500\u2500 cluster_train.sh # \u672c\u5730\u6a21\u62df\u591a\u673a\u811a\u672c \u251c\u2500\u2500 train.py # \u8bad\u7ec3\u51fd\u6570 \u251c\u2500\u2500 infer.py # \u9884\u6d4b\u811a\u672c \u251c\u2500\u2500 net.py # \u7f51\u7edc\u7ed3\u6784 \u251c\u2500\u2500 preprocess.py # \u9884\u5904\u7406\u811a\u672c\uff0c\u5305\u62ec\u6784\u5efa\u8bcd\u5178\u548c\u9884\u5904\u7406\u6587\u672c \u251c\u2500\u2500 reader.py # \u8bad\u7ec3\u9636\u6bb5\u7684\u6587\u672c\u8bfb\u5199 \u251c\u2500\u2500 train.py # \u8bad\u7ec3\u51fd\u6570 \u2514\u2500\u2500 utils.py # \u901a\u7528\u51fd\u6570 \u4ecb\u7ecd # \u672c\u4f8b\u5b9e\u73b0\u4e86skip-gram\u6a21\u5f0f\u7684word2vector\u6a21\u578b\u3002 \u540c\u65f6\u63a8\u8350\u7528\u6237\u53c2\u8003 IPython Notebook demo \u6570\u636e\u4e0b\u8f7d # \u5168\u91cf\u6570\u636e\u96c6\u4f7f\u7528\u7684\u662f\u6765\u81ea1 Billion Word Language Model Benchmark\u7684( http://www.statmt.org/lm-benchmark ) \u7684\u6570\u636e\u96c6. 1 2 3 4 mkdir data wget http://www.statmt.org/lm-benchmark/1-billion-word-language-modeling-benchmark-r13output.tar.gz tar xzvf 1 -billion-word-language-modeling-benchmark-r13output.tar.gz mv 1 -billion-word-language-modeling-benchmark-r13output/training-monolingual.tokenized.shuffled/ data/ \u5907\u7528\u6570\u636e\u5730\u5740\u4e0b\u8f7d\u547d\u4ee4\u5982\u4e0b 1 2 3 4 mkdir data wget https://paddlerec.bj.bcebos.com/word2vec/1-billion-word-language-modeling-benchmark-r13output.tar tar xvf 1 -billion-word-language-modeling-benchmark-r13output.tar mv 1 -billion-word-language-modeling-benchmark-r13output/training-monolingual.tokenized.shuffled/ data/ \u4e3a\u4e86\u65b9\u4fbf\u5feb\u901f\u9a8c\u8bc1\uff0c\u6211\u4eec\u4e5f\u63d0\u4f9b\u4e86\u7ecf\u5178\u7684text8\u6837\u4f8b\u6570\u636e\u96c6\uff0c\u5305\u542b1700w\u4e2a\u8bcd\u3002 \u4e0b\u8f7d\u547d\u4ee4\u5982\u4e0b 1 2 3 4 mkdir data wget https://paddlerec.bj.bcebos.com/word2vec/text.tar tar xvf text.tar mv text data/ \u6570\u636e\u9884\u5904\u7406 # \u4ee5\u6837\u4f8b\u6570\u636e\u96c6\u4e3a\u4f8b\u8fdb\u884c\u9884\u5904\u7406\u3002\u5168\u91cf\u6570\u636e\u96c6\u6ce8\u610f\u89e3\u538b\u540e\u4ee5training-monolingual.tokenized.shuffled \u76ee\u5f55\u4e3a\u9884\u5904\u7406\u76ee\u5f55\uff0c\u548c\u6837\u4f8b\u6570\u636e\u96c6\u7684text\u76ee\u5f55\u5e76\u5217\u3002 \u8bcd\u5178\u683c\u5f0f: \u8bcd<\u7a7a\u683c>\u8bcd\u9891\u3002\u6ce8\u610f\u4f4e\u9891\u8bcd\u7528'UNK'\u8868\u793a \u53ef\u4ee5\u6309\u683c\u5f0f\u81ea\u5efa\u8bcd\u5178\uff0c\u5982\u679c\u81ea\u5efa\u8bcd\u5178\u8df3\u8fc7\u7b2c\u4e00\u6b65\u3002 1 2 3 4 5 6 7 8 9 10 the 1061396 of 593677 and 416629 one 411764 in 372201 a 325873 < UNK > 324608 to 316376 zero 264975 nine 250430 \u7b2c\u4e00\u6b65\u6839\u636e\u82f1\u6587\u8bed\u6599\u751f\u6210\u8bcd\u5178\uff0c\u4e2d\u6587\u8bed\u6599\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539text_strip\u65b9\u6cd5\u81ea\u5b9a\u4e49\u5904\u7406\u65b9\u6cd5\u3002 1 python preprocess.py --build_dict --build_dict_corpus_dir data/text/ --dict_path data/test_build_dict \u7b2c\u4e8c\u6b65\u6839\u636e\u8bcd\u5178\u5c06\u6587\u672c\u8f6c\u6210id, \u540c\u65f6\u8fdb\u884cdownsample\uff0c\u6309\u7167\u6982\u7387\u8fc7\u6ee4\u5e38\u89c1\u8bcd, \u540c\u65f6\u751f\u6210word\u548cid\u6620\u5c04\u7684\u6587\u4ef6\uff0c\u6587\u4ef6\u540d\u4e3a\u8bcd\u5178+\" word_to_id \"\u3002 1 python preprocess.py --filter_corpus --dict_path data/test_build_dict --input_corpus_dir data/text --output_corpus_dir data/convert_text8 --min_count 5 --downsample 0 .001 \u8bad\u7ec3 # \u5177\u4f53\u7684\u53c2\u6570\u914d\u7f6e\u53ef\u8fd0\u884c 1 python train.py -h \u5355\u673a\u591a\u7ebf\u7a0b\u8bad\u7ec3 1 OPENBLAS_NUM_THREADS = 1 CPU_NUM = 5 python train.py --train_data_dir data/convert_text8 --dict_path data/test_build_dict --num_passes 10 --batch_size 100 --model_output_dir v1_cpu5_b100_lr1dir --base_lr 1 .0 --print_batch 1000 --with_speed --is_sparse \u672c\u5730\u5355\u673a\u6a21\u62df\u591a\u673a\u8bad\u7ec3 1 sh cluster_train.sh \u672c\u793a\u4f8b\u4e2d\u6309\u7167\u5355\u673a\u591a\u7ebf\u7a0b\u8bad\u7ec3\u7684\u547d\u4ee4\u8fdb\u884c\u8bad\u7ec3\uff0c\u8bad\u7ec3\u5b8c\u6bd5\u540e\uff0c\u53ef\u770b\u5230\u5728\u5f53\u524d\u6587\u4ef6\u5939\u4e0b\u4fdd\u5b58\u6a21\u578b\u7684\u8def\u5f84\u4e3a: v1_cpu5_b100_lr1dir , \u8fd0\u884c ls v1_cpu5_b100_lr1dir \u53ef\u770b\u5230\u8be5\u6587\u4ef6\u5939\u4e0b\u4fdd\u5b58\u4e86\u8bad\u7ec3\u768410\u4e2aepoch\u7684\u6a21\u578b\u6587\u4ef6\u3002 1 pass - 0 pass - 1 pass - 2 pass - 3 pass - 4 pass - 5 pass - 6 pass - 7 pass - 8 pass - 9 \u9884\u6d4b # \u6d4b\u8bd5\u96c6\u4e0b\u8f7d\u547d\u4ee4\u5982\u4e0b 1 2 3 4 #\u5168\u91cf\u6570\u636e\u96c6\u6d4b\u8bd5\u96c6 wget https://paddlerec.bj.bcebos.com/word2vec/test_dir.tar #\u6837\u672c\u6570\u636e\u96c6\u6d4b\u8bd5\u96c6 wget https://paddlerec.bj.bcebos.com/word2vec/test_mid_dir.tar \u9884\u6d4b\u547d\u4ee4\uff0c\u6ce8\u610f\u8bcd\u5178\u540d\u79f0\u9700\u8981\u52a0\u540e\u7f00\" word_to_id \", \u6b64\u6587\u4ef6\u662f\u9884\u5904\u7406\u9636\u6bb5\u751f\u6210\u7684\u3002 1 python infer.py --infer_epoch --test_dir data/test_mid_dir --dict_path data/test_build_dict_word_to_id_ --batch_size 20000 --model_dir v1_cpu5_b100_lr1dir/ --start_index 0 --last_index 9 \u8fd0\u884c\u8be5\u9884\u6d4b\u547d\u4ee4, \u53ef\u770b\u5230\u5982\u4e0b\u8f93\u51fa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ( 'start index: ' , 0 , ' last_index:' , 9 ) ( 'vocab_size:' , 63642 ) step : 1 249 epoch : 0 acc : 0 . 014 step : 1 590 epoch : 1 acc : 0 . 033 step : 1 982 epoch : 2 acc : 0 . 055 step : 1 1338 epoch : 3 acc : 0 . 075 step : 1 1653 epoch : 4 acc : 0 . 093 step : 1 1914 epoch : 5 acc : 0 . 107 step : 1 2204 epoch : 6 acc : 0 . 124 step : 1 2416 epoch : 7 acc : 0 . 136 step : 1 2606 epoch : 8 acc : 0 . 146 step : 1 2722 epoch : 9 acc : 0 . 153 \u91cf\u5316 \u57fa\u4e8eskip-gram\u7684word2vector\u6a21\u578b # \u91cf\u5316\u914d\u7f6e\u4e3a: 1 2 3 4 config = { 'params_name' : 'emb' , 'quantize_type' : 'abs_max' } \u8fd0\u884c\u547d\u4ee4\u4e3a\uff1a 1 python infer.py --infer_epoch --test_dir data/test_mid_dir --dict_path data/test_build_dict_word_to_id_ --batch_size 20000 --model_dir v1_cpu5_b100_lr1dir/ --start_index 0 --last_index 9 --emb_quant True \u8fd0\u884c\u8f93\u51fa\u4e3a: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 ( 'start index: ' , 0 , ' last_index:' , 9 ) ( 'vocab_size:' , 63642 ) quant_embedding config { 'quantize_type' : 'abs_max' , 'params_name' : 'emb' , 'quantize_bits' : 8 , 'dtype' : 'int8' } step : 1 253 epoch : 0 acc : 0 . 014 quant_embedding config { 'quantize_type' : 'abs_max' , 'params_name' : 'emb' , 'quantize_bits' : 8 , 'dtype' : 'int8' } step : 1 586 epoch : 1 acc : 0 . 033 quant_embedding config { 'quantize_type' : 'abs_max' , 'params_name' : 'emb' , 'quantize_bits' : 8 , 'dtype' : 'int8' } step : 1 970 epoch : 2 acc : 0 . 054 quant_embedding config { 'quantize_type' : 'abs_max' , 'params_name' : 'emb' , 'quantize_bits' : 8 , 'dtype' : 'int8' } step : 1 1364 epoch : 3 acc : 0 . 077 quant_embedding config { 'quantize_type' : 'abs_max' , 'params_name' : 'emb' , 'quantize_bits' : 8 , 'dtype' : 'int8' } step : 1 1642 epoch : 4 acc : 0 . 092 quant_embedding config { 'quantize_type' : 'abs_max' , 'params_name' : 'emb' , 'quantize_bits' : 8 , 'dtype' : 'int8' } step : 1 1936 epoch : 5 acc : 0 . 109 quant_embedding config { 'quantize_type' : 'abs_max' , 'params_name' : 'emb' , 'quantize_bits' : 8 , 'dtype' : 'int8' } step : 1 2216 epoch : 6 acc : 0 . 124 quant_embedding config { 'quantize_type' : 'abs_max' , 'params_name' : 'emb' , 'quantize_bits' : 8 , 'dtype' : 'int8' } step : 1 2419 epoch : 7 acc : 0 . 136 quant_embedding config { 'quantize_type' : 'abs_max' , 'params_name' : 'emb' , 'quantize_bits' : 8 , 'dtype' : 'int8' } step : 1 2603 epoch : 8 acc : 0 . 146 quant_embedding config { 'quantize_type' : 'abs_max' , 'params_name' : 'emb' , 'quantize_bits' : 8 , 'dtype' : 'int8' } step : 1 2719 epoch : 9 acc : 0 . 153 \u91cf\u5316\u540e\u7684\u6a21\u578b\u4fdd\u5b58\u5728 ./output_quant \u4e2d\uff0c\u53ef\u770b\u5230\u91cf\u5316\u540e\u7684\u53c2\u6570 'emb.int8' \u7684\u5927\u5c0f\u4e3a3.9M, \u5728 ./v1_cpu5_b100_lr1dir \u4e2d\u53ef\u770b\u5230\u91cf\u5316\u524d\u7684\u53c2\u6570 'emb' \u7684\u5927\u5c0f\u4e3a16M\u3002","title":"Embedding\u91cf\u5316"},{"location":"tutorials/quant_embedding_demo/#embedding","text":"\u672c\u793a\u4f8b\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Embedding\u91cf\u5316\u7684\u63a5\u53e3 paddleslim.quant.quant_embedding \u3002 quant_embedding \u63a5\u53e3\u5c06\u7f51\u7edc\u4e2d\u7684Embedding\u53c2\u6570\u4ece float32 \u7c7b\u578b\u91cf\u5316\u5230 8-bit \u6574\u6570\u7c7b\u578b\uff0c\u5728\u51e0\u4e4e\u4e0d\u635f\u5931\u6a21\u578b\u7cbe\u5ea6\u7684\u60c5\u51b5\u4e0b\u51cf\u5c11\u6a21\u578b\u7684\u5b58\u50a8\u7a7a\u95f4\u548c\u663e\u5b58\u5360\u7528\u3002 \u63a5\u53e3\u4ecb\u7ecd\u8bf7\u53c2\u8003 \u91cf\u5316API\u6587\u6863 \u3002 \u8be5\u63a5\u53e3\u5bf9program\u7684\u4fee\u6539\uff1a \u91cf\u5316\u524d: \u56fe1\uff1a\u91cf\u5316\u524d\u7684\u6a21\u578b\u7ed3\u6784 \u91cf\u5316\u540e\uff1a \u56fe2: \u91cf\u5316\u540e\u7684\u6a21\u578b\u7ed3\u6784 \u4ee5\u4e0b\u5c06\u4ee5 \u57fa\u4e8eskip-gram\u7684word2vector\u6a21\u578b \u4e3a\u4f8b\u6765\u8bf4\u660e\u5982\u4f55\u4f7f\u7528 quant_embedding \u63a5\u53e3\u3002\u9996\u5148\u4ecb\u7ecd \u57fa\u4e8eskip-gram\u7684word2vector\u6a21\u578b \u7684\u6b63\u5e38\u8bad\u7ec3\u548c\u6d4b\u8bd5\u6d41\u7a0b\u3002","title":"Embedding\u91cf\u5316\u793a\u4f8b"},{"location":"tutorials/quant_embedding_demo/#skip-gramword2vector","text":"\u4ee5\u4e0b\u662f\u672c\u4f8b\u7684\u7b80\u8981\u76ee\u5f55\u7ed3\u6784\u53ca\u8bf4\u660e\uff1a 1 2 3 4 5 6 7 8 9 10 . \u251c\u2500\u2500 cluster_train.py # \u5206\u5e03\u5f0f\u8bad\u7ec3\u51fd\u6570 \u251c\u2500\u2500 cluster_train.sh # \u672c\u5730\u6a21\u62df\u591a\u673a\u811a\u672c \u251c\u2500\u2500 train.py # \u8bad\u7ec3\u51fd\u6570 \u251c\u2500\u2500 infer.py # \u9884\u6d4b\u811a\u672c \u251c\u2500\u2500 net.py # \u7f51\u7edc\u7ed3\u6784 \u251c\u2500\u2500 preprocess.py # \u9884\u5904\u7406\u811a\u672c\uff0c\u5305\u62ec\u6784\u5efa\u8bcd\u5178\u548c\u9884\u5904\u7406\u6587\u672c \u251c\u2500\u2500 reader.py # \u8bad\u7ec3\u9636\u6bb5\u7684\u6587\u672c\u8bfb\u5199 \u251c\u2500\u2500 train.py # \u8bad\u7ec3\u51fd\u6570 \u2514\u2500\u2500 utils.py # \u901a\u7528\u51fd\u6570","title":"\u57fa\u4e8eskip-gram\u7684word2vector\u6a21\u578b"},{"location":"tutorials/quant_embedding_demo/#_1","text":"\u672c\u4f8b\u5b9e\u73b0\u4e86skip-gram\u6a21\u5f0f\u7684word2vector\u6a21\u578b\u3002 \u540c\u65f6\u63a8\u8350\u7528\u6237\u53c2\u8003 IPython Notebook demo","title":"\u4ecb\u7ecd"},{"location":"tutorials/quant_embedding_demo/#_2","text":"\u5168\u91cf\u6570\u636e\u96c6\u4f7f\u7528\u7684\u662f\u6765\u81ea1 Billion Word Language Model Benchmark\u7684( http://www.statmt.org/lm-benchmark ) \u7684\u6570\u636e\u96c6. 1 2 3 4 mkdir data wget http://www.statmt.org/lm-benchmark/1-billion-word-language-modeling-benchmark-r13output.tar.gz tar xzvf 1 -billion-word-language-modeling-benchmark-r13output.tar.gz mv 1 -billion-word-language-modeling-benchmark-r13output/training-monolingual.tokenized.shuffled/ data/ \u5907\u7528\u6570\u636e\u5730\u5740\u4e0b\u8f7d\u547d\u4ee4\u5982\u4e0b 1 2 3 4 mkdir data wget https://paddlerec.bj.bcebos.com/word2vec/1-billion-word-language-modeling-benchmark-r13output.tar tar xvf 1 -billion-word-language-modeling-benchmark-r13output.tar mv 1 -billion-word-language-modeling-benchmark-r13output/training-monolingual.tokenized.shuffled/ data/ \u4e3a\u4e86\u65b9\u4fbf\u5feb\u901f\u9a8c\u8bc1\uff0c\u6211\u4eec\u4e5f\u63d0\u4f9b\u4e86\u7ecf\u5178\u7684text8\u6837\u4f8b\u6570\u636e\u96c6\uff0c\u5305\u542b1700w\u4e2a\u8bcd\u3002 \u4e0b\u8f7d\u547d\u4ee4\u5982\u4e0b 1 2 3 4 mkdir data wget https://paddlerec.bj.bcebos.com/word2vec/text.tar tar xvf text.tar mv text data/","title":"\u6570\u636e\u4e0b\u8f7d"},{"location":"tutorials/quant_embedding_demo/#_3","text":"\u4ee5\u6837\u4f8b\u6570\u636e\u96c6\u4e3a\u4f8b\u8fdb\u884c\u9884\u5904\u7406\u3002\u5168\u91cf\u6570\u636e\u96c6\u6ce8\u610f\u89e3\u538b\u540e\u4ee5training-monolingual.tokenized.shuffled \u76ee\u5f55\u4e3a\u9884\u5904\u7406\u76ee\u5f55\uff0c\u548c\u6837\u4f8b\u6570\u636e\u96c6\u7684text\u76ee\u5f55\u5e76\u5217\u3002 \u8bcd\u5178\u683c\u5f0f: \u8bcd<\u7a7a\u683c>\u8bcd\u9891\u3002\u6ce8\u610f\u4f4e\u9891\u8bcd\u7528'UNK'\u8868\u793a \u53ef\u4ee5\u6309\u683c\u5f0f\u81ea\u5efa\u8bcd\u5178\uff0c\u5982\u679c\u81ea\u5efa\u8bcd\u5178\u8df3\u8fc7\u7b2c\u4e00\u6b65\u3002 1 2 3 4 5 6 7 8 9 10 the 1061396 of 593677 and 416629 one 411764 in 372201 a 325873 < UNK > 324608 to 316376 zero 264975 nine 250430 \u7b2c\u4e00\u6b65\u6839\u636e\u82f1\u6587\u8bed\u6599\u751f\u6210\u8bcd\u5178\uff0c\u4e2d\u6587\u8bed\u6599\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539text_strip\u65b9\u6cd5\u81ea\u5b9a\u4e49\u5904\u7406\u65b9\u6cd5\u3002 1 python preprocess.py --build_dict --build_dict_corpus_dir data/text/ --dict_path data/test_build_dict \u7b2c\u4e8c\u6b65\u6839\u636e\u8bcd\u5178\u5c06\u6587\u672c\u8f6c\u6210id, \u540c\u65f6\u8fdb\u884cdownsample\uff0c\u6309\u7167\u6982\u7387\u8fc7\u6ee4\u5e38\u89c1\u8bcd, \u540c\u65f6\u751f\u6210word\u548cid\u6620\u5c04\u7684\u6587\u4ef6\uff0c\u6587\u4ef6\u540d\u4e3a\u8bcd\u5178+\" word_to_id \"\u3002 1 python preprocess.py --filter_corpus --dict_path data/test_build_dict --input_corpus_dir data/text --output_corpus_dir data/convert_text8 --min_count 5 --downsample 0 .001","title":"\u6570\u636e\u9884\u5904\u7406"},{"location":"tutorials/quant_embedding_demo/#_4","text":"\u5177\u4f53\u7684\u53c2\u6570\u914d\u7f6e\u53ef\u8fd0\u884c 1 python train.py -h \u5355\u673a\u591a\u7ebf\u7a0b\u8bad\u7ec3 1 OPENBLAS_NUM_THREADS = 1 CPU_NUM = 5 python train.py --train_data_dir data/convert_text8 --dict_path data/test_build_dict --num_passes 10 --batch_size 100 --model_output_dir v1_cpu5_b100_lr1dir --base_lr 1 .0 --print_batch 1000 --with_speed --is_sparse \u672c\u5730\u5355\u673a\u6a21\u62df\u591a\u673a\u8bad\u7ec3 1 sh cluster_train.sh \u672c\u793a\u4f8b\u4e2d\u6309\u7167\u5355\u673a\u591a\u7ebf\u7a0b\u8bad\u7ec3\u7684\u547d\u4ee4\u8fdb\u884c\u8bad\u7ec3\uff0c\u8bad\u7ec3\u5b8c\u6bd5\u540e\uff0c\u53ef\u770b\u5230\u5728\u5f53\u524d\u6587\u4ef6\u5939\u4e0b\u4fdd\u5b58\u6a21\u578b\u7684\u8def\u5f84\u4e3a: v1_cpu5_b100_lr1dir , \u8fd0\u884c ls v1_cpu5_b100_lr1dir \u53ef\u770b\u5230\u8be5\u6587\u4ef6\u5939\u4e0b\u4fdd\u5b58\u4e86\u8bad\u7ec3\u768410\u4e2aepoch\u7684\u6a21\u578b\u6587\u4ef6\u3002 1 pass - 0 pass - 1 pass - 2 pass - 3 pass - 4 pass - 5 pass - 6 pass - 7 pass - 8 pass - 9","title":"\u8bad\u7ec3"},{"location":"tutorials/quant_embedding_demo/#_5","text":"\u6d4b\u8bd5\u96c6\u4e0b\u8f7d\u547d\u4ee4\u5982\u4e0b 1 2 3 4 #\u5168\u91cf\u6570\u636e\u96c6\u6d4b\u8bd5\u96c6 wget https://paddlerec.bj.bcebos.com/word2vec/test_dir.tar #\u6837\u672c\u6570\u636e\u96c6\u6d4b\u8bd5\u96c6 wget https://paddlerec.bj.bcebos.com/word2vec/test_mid_dir.tar \u9884\u6d4b\u547d\u4ee4\uff0c\u6ce8\u610f\u8bcd\u5178\u540d\u79f0\u9700\u8981\u52a0\u540e\u7f00\" word_to_id \", \u6b64\u6587\u4ef6\u662f\u9884\u5904\u7406\u9636\u6bb5\u751f\u6210\u7684\u3002 1 python infer.py --infer_epoch --test_dir data/test_mid_dir --dict_path data/test_build_dict_word_to_id_ --batch_size 20000 --model_dir v1_cpu5_b100_lr1dir/ --start_index 0 --last_index 9 \u8fd0\u884c\u8be5\u9884\u6d4b\u547d\u4ee4, \u53ef\u770b\u5230\u5982\u4e0b\u8f93\u51fa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ( 'start index: ' , 0 , ' last_index:' , 9 ) ( 'vocab_size:' , 63642 ) step : 1 249 epoch : 0 acc : 0 . 014 step : 1 590 epoch : 1 acc : 0 . 033 step : 1 982 epoch : 2 acc : 0 . 055 step : 1 1338 epoch : 3 acc : 0 . 075 step : 1 1653 epoch : 4 acc : 0 . 093 step : 1 1914 epoch : 5 acc : 0 . 107 step : 1 2204 epoch : 6 acc : 0 . 124 step : 1 2416 epoch : 7 acc : 0 . 136 step : 1 2606 epoch : 8 acc : 0 . 146 step : 1 2722 epoch : 9 acc : 0 . 153","title":"\u9884\u6d4b"},{"location":"tutorials/quant_embedding_demo/#skip-gramword2vector_1","text":"\u91cf\u5316\u914d\u7f6e\u4e3a: 1 2 3 4 config = { 'params_name' : 'emb' , 'quantize_type' : 'abs_max' } \u8fd0\u884c\u547d\u4ee4\u4e3a\uff1a 1 python infer.py --infer_epoch --test_dir data/test_mid_dir --dict_path data/test_build_dict_word_to_id_ --batch_size 20000 --model_dir v1_cpu5_b100_lr1dir/ --start_index 0 --last_index 9 --emb_quant True \u8fd0\u884c\u8f93\u51fa\u4e3a: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 ( 'start index: ' , 0 , ' last_index:' , 9 ) ( 'vocab_size:' , 63642 ) quant_embedding config { 'quantize_type' : 'abs_max' , 'params_name' : 'emb' , 'quantize_bits' : 8 , 'dtype' : 'int8' } step : 1 253 epoch : 0 acc : 0 . 014 quant_embedding config { 'quantize_type' : 'abs_max' , 'params_name' : 'emb' , 'quantize_bits' : 8 , 'dtype' : 'int8' } step : 1 586 epoch : 1 acc : 0 . 033 quant_embedding config { 'quantize_type' : 'abs_max' , 'params_name' : 'emb' , 'quantize_bits' : 8 , 'dtype' : 'int8' } step : 1 970 epoch : 2 acc : 0 . 054 quant_embedding config { 'quantize_type' : 'abs_max' , 'params_name' : 'emb' , 'quantize_bits' : 8 , 'dtype' : 'int8' } step : 1 1364 epoch : 3 acc : 0 . 077 quant_embedding config { 'quantize_type' : 'abs_max' , 'params_name' : 'emb' , 'quantize_bits' : 8 , 'dtype' : 'int8' } step : 1 1642 epoch : 4 acc : 0 . 092 quant_embedding config { 'quantize_type' : 'abs_max' , 'params_name' : 'emb' , 'quantize_bits' : 8 , 'dtype' : 'int8' } step : 1 1936 epoch : 5 acc : 0 . 109 quant_embedding config { 'quantize_type' : 'abs_max' , 'params_name' : 'emb' , 'quantize_bits' : 8 , 'dtype' : 'int8' } step : 1 2216 epoch : 6 acc : 0 . 124 quant_embedding config { 'quantize_type' : 'abs_max' , 'params_name' : 'emb' , 'quantize_bits' : 8 , 'dtype' : 'int8' } step : 1 2419 epoch : 7 acc : 0 . 136 quant_embedding config { 'quantize_type' : 'abs_max' , 'params_name' : 'emb' , 'quantize_bits' : 8 , 'dtype' : 'int8' } step : 1 2603 epoch : 8 acc : 0 . 146 quant_embedding config { 'quantize_type' : 'abs_max' , 'params_name' : 'emb' , 'quantize_bits' : 8 , 'dtype' : 'int8' } step : 1 2719 epoch : 9 acc : 0 . 153 \u91cf\u5316\u540e\u7684\u6a21\u578b\u4fdd\u5b58\u5728 ./output_quant \u4e2d\uff0c\u53ef\u770b\u5230\u91cf\u5316\u540e\u7684\u53c2\u6570 'emb.int8' \u7684\u5927\u5c0f\u4e3a3.9M, \u5728 ./v1_cpu5_b100_lr1dir \u4e2d\u53ef\u770b\u5230\u91cf\u5316\u524d\u7684\u53c2\u6570 'emb' \u7684\u5927\u5c0f\u4e3a16M\u3002","title":"\u91cf\u5316\u57fa\u4e8eskip-gram\u7684word2vector\u6a21\u578b"},{"location":"tutorials/quant_post_demo/","text":"\u79bb\u7ebf\u91cf\u5316\u793a\u4f8b # \u672c\u793a\u4f8b\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u79bb\u7ebf\u91cf\u5316\u63a5\u53e3 paddleslim.quant.quant_post \u6765\u5bf9\u8bad\u7ec3\u597d\u7684\u5206\u7c7b\u6a21\u578b\u8fdb\u884c\u79bb\u7ebf\u91cf\u5316, \u8be5\u63a5\u53e3\u65e0\u9700\u5bf9\u6a21\u578b\u8fdb\u884c\u8bad\u7ec3\u5c31\u53ef\u5f97\u5230\u91cf\u5316\u6a21\u578b\uff0c\u51cf\u5c11\u6a21\u578b\u7684\u5b58\u50a8\u7a7a\u95f4\u548c\u663e\u5b58\u5360\u7528\u3002 \u63a5\u53e3\u4ecb\u7ecd # \u8bf7\u53c2\u8003 \u91cf\u5316API\u6587\u6863 \u3002 \u5206\u7c7b\u6a21\u578b\u7684\u79bb\u7ebf\u91cf\u5316\u6d41\u7a0b # \u51c6\u5907\u6570\u636e # \u5728\u5f53\u524d\u6587\u4ef6\u5939\u4e0b\u521b\u5efa data \u6587\u4ef6\u5939\uff0c\u5c06 imagenet \u6570\u636e\u96c6\u89e3\u538b\u5728 data \u6587\u4ef6\u5939\u4e0b\uff0c\u89e3\u538b\u540e data \u6587\u4ef6\u5939\u4e0b\u5e94\u5305\u542b\u4ee5\u4e0b\u6587\u4ef6\uff1a - 'train' \u6587\u4ef6\u5939\uff0c\u8bad\u7ec3\u56fe\u7247 - 'train_list.txt' \u6587\u4ef6 - 'val' \u6587\u4ef6\u5939\uff0c\u9a8c\u8bc1\u56fe\u7247 - 'val_list.txt' \u6587\u4ef6 \u51c6\u5907\u9700\u8981\u91cf\u5316\u7684\u6a21\u578b # \u56e0\u4e3a\u79bb\u7ebf\u91cf\u5316\u63a5\u53e3\u53ea\u652f\u6301\u52a0\u8f7d\u901a\u8fc7 fluid.io.save_inference_model \u63a5\u53e3\u4fdd\u5b58\u7684\u6a21\u578b\uff0c\u56e0\u6b64\u5982\u679c\u60a8\u7684\u6a21\u578b\u662f\u901a\u8fc7\u5176\u4ed6\u63a5\u53e3\u4fdd\u5b58\u7684\uff0c\u90a3\u9700\u8981\u5148\u5c06\u6a21\u578b\u8fdb\u884c\u8f6c\u5316\u3002\u672c\u793a\u4f8b\u5c06\u4ee5\u5206\u7c7b\u6a21\u578b\u4e3a\u4f8b\u8fdb\u884c\u8bf4\u660e\u3002 \u9996\u5148\u5728 imagenet\u5206\u7c7b\u6a21\u578b \u4e2d\u4e0b\u8f7d\u8bad\u7ec3\u597d\u7684 mobilenetv1 \u6a21\u578b\u3002 \u5728\u5f53\u524d\u6587\u4ef6\u5939\u4e0b\u521b\u5efa 'pretrain' \u6587\u4ef6\u5939\uff0c\u5c06 mobilenetv1 \u6a21\u578b\u5728\u8be5\u6587\u4ef6\u5939\u4e0b\u89e3\u538b\uff0c\u89e3\u538b\u540e\u7684\u76ee\u5f55\u4e3a pretrain/MobileNetV1_pretrained \u5bfc\u51fa\u6a21\u578b # \u901a\u8fc7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u53ef\u5c06\u6a21\u578b\u8f6c\u5316\u4e3a\u79bb\u7ebf\u91cf\u5316\u63a5\u53e3\u53ef\u7528\u7684\u6a21\u578b\uff1a 1 python export_model . py --model \"MobileNet\" --pretrained_model ./pretrain/MobileNetV1_pretrained --data imagenet \u8f6c\u5316\u4e4b\u540e\u7684\u6a21\u578b\u5b58\u50a8\u5728 inference_model/MobileNet/ \u6587\u4ef6\u5939\u4e0b\uff0c\u53ef\u770b\u5230\u8be5\u6587\u4ef6\u5939\u4e0b\u6709 'model' , 'weights' \u4e24\u4e2a\u6587\u4ef6\u3002 \u79bb\u7ebf\u91cf\u5316 # \u63a5\u4e0b\u6765\u5bf9\u5bfc\u51fa\u7684\u6a21\u578b\u6587\u4ef6\u8fdb\u884c\u79bb\u7ebf\u91cf\u5316\uff0c\u79bb\u7ebf\u91cf\u5316\u7684\u811a\u672c\u4e3a quant_post.py \uff0c\u811a\u672c\u4e2d\u4f7f\u7528\u63a5\u53e3 paddleslim.quant.quant_post \u5bf9\u6a21\u578b\u8fdb\u884c\u79bb\u7ebf\u91cf\u5316\u3002\u8fd0\u884c\u547d\u4ee4\u4e3a\uff1a 1 python quant_post . py --model_path ./inference_model/MobileNet --save_path ./quant_model_train/MobileNet --model_filename model --params_filename weights model_path : \u9700\u8981\u91cf\u5316\u7684\u6a21\u578b\u5750\u5728\u7684\u6587\u4ef6\u5939 save_path : \u91cf\u5316\u540e\u7684\u6a21\u578b\u4fdd\u5b58\u7684\u8def\u5f84 model_filename : \u5982\u679c\u9700\u8981\u91cf\u5316\u7684\u6a21\u578b\u7684\u53c2\u6570\u6587\u4ef6\u4fdd\u5b58\u5728\u4e00\u4e2a\u6587\u4ef6\u4e2d\uff0c\u5219\u8bbe\u7f6e\u4e3a\u8be5\u6a21\u578b\u7684\u6a21\u578b\u6587\u4ef6\u540d\u79f0\uff0c\u5982\u679c\u53c2\u6570\u6587\u4ef6\u4fdd\u5b58\u5728\u591a\u4e2a\u6587\u4ef6\u4e2d\uff0c\u5219\u4e0d\u9700\u8981\u8bbe\u7f6e\u3002 params_filename : \u5982\u679c\u9700\u8981\u91cf\u5316\u7684\u6a21\u578b\u7684\u53c2\u6570\u6587\u4ef6\u4fdd\u5b58\u5728\u4e00\u4e2a\u6587\u4ef6\u4e2d\uff0c\u5219\u8bbe\u7f6e\u4e3a\u8be5\u6a21\u578b\u7684\u53c2\u6570\u6587\u4ef6\u540d\u79f0\uff0c\u5982\u679c\u53c2\u6570\u6587\u4ef6\u4fdd\u5b58\u5728\u591a\u4e2a\u6587\u4ef6\u4e2d\uff0c\u5219\u4e0d\u9700\u8981\u8bbe\u7f6e\u3002 \u8fd0\u884c\u4ee5\u4e0a\u547d\u4ee4\u540e\uff0c\u53ef\u5728 ${save_path} \u4e0b\u770b\u5230\u91cf\u5316\u540e\u7684\u6a21\u578b\u6587\u4ef6\u548c\u53c2\u6570\u6587\u4ef6\u3002 \u4f7f\u7528\u7684\u91cf\u5316\u7b97\u6cd5\u4e3a 'KL' , \u4f7f\u7528\u8bad\u7ec3\u96c6\u4e2d\u7684160\u5f20\u56fe\u7247\u8fdb\u884c\u91cf\u5316\u53c2\u6570\u7684\u6821\u6b63\u3002 \u6d4b\u8bd5\u7cbe\u5ea6 # \u4f7f\u7528 eval.py \u811a\u672c\u5bf9\u91cf\u5316\u524d\u540e\u7684\u6a21\u578b\u8fdb\u884c\u6d4b\u8bd5\uff0c\u5f97\u5230\u6a21\u578b\u7684\u5206\u7c7b\u7cbe\u5ea6\u8fdb\u884c\u5bf9\u6bd4\u3002 \u9996\u5148\u6d4b\u8bd5\u91cf\u5316\u524d\u7684\u6a21\u578b\u7684\u7cbe\u5ea6\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a 1 python eval . py --model_path ./inference_model/MobileNet --model_name model --params_name weights \u7cbe\u5ea6\u8f93\u51fa\u4e3a: 1 top1_acc / top5_acc = [ 0 . 70913923 0 . 89548034 ] \u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6d4b\u8bd5\u79bb\u7ebf\u91cf\u5316\u540e\u7684\u6a21\u578b\u7684\u7cbe\u5ea6\uff1a 1 python eval . py --model_path ./quant_model_train/MobileNet \u7cbe\u5ea6\u8f93\u51fa\u4e3a 1 top1_acc / top5_acc = [ 0 . 70141864 0 . 89086477 ] \u4ece\u4ee5\u4e0a\u7cbe\u5ea6\u5bf9\u6bd4\u53ef\u4ee5\u770b\u51fa\uff0c\u5bf9 mobilenet \u5728 imagenet \u4e0a\u7684\u5206\u7c7b\u6a21\u578b\u8fdb\u884c\u79bb\u7ebf\u91cf\u5316\u540e top1 \u7cbe\u5ea6\u635f\u5931\u4e3a 0.77% \uff0c top5 \u7cbe\u5ea6\u635f\u5931\u4e3a 0.46% .","title":"\u79bb\u7ebf\u91cf\u5316"},{"location":"tutorials/quant_post_demo/#_1","text":"\u672c\u793a\u4f8b\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u79bb\u7ebf\u91cf\u5316\u63a5\u53e3 paddleslim.quant.quant_post \u6765\u5bf9\u8bad\u7ec3\u597d\u7684\u5206\u7c7b\u6a21\u578b\u8fdb\u884c\u79bb\u7ebf\u91cf\u5316, \u8be5\u63a5\u53e3\u65e0\u9700\u5bf9\u6a21\u578b\u8fdb\u884c\u8bad\u7ec3\u5c31\u53ef\u5f97\u5230\u91cf\u5316\u6a21\u578b\uff0c\u51cf\u5c11\u6a21\u578b\u7684\u5b58\u50a8\u7a7a\u95f4\u548c\u663e\u5b58\u5360\u7528\u3002","title":"\u79bb\u7ebf\u91cf\u5316\u793a\u4f8b"},{"location":"tutorials/quant_post_demo/#_2","text":"\u8bf7\u53c2\u8003 \u91cf\u5316API\u6587\u6863 \u3002","title":"\u63a5\u53e3\u4ecb\u7ecd"},{"location":"tutorials/quant_post_demo/#_3","text":"","title":"\u5206\u7c7b\u6a21\u578b\u7684\u79bb\u7ebf\u91cf\u5316\u6d41\u7a0b"},{"location":"tutorials/quant_post_demo/#_4","text":"\u5728\u5f53\u524d\u6587\u4ef6\u5939\u4e0b\u521b\u5efa data \u6587\u4ef6\u5939\uff0c\u5c06 imagenet \u6570\u636e\u96c6\u89e3\u538b\u5728 data \u6587\u4ef6\u5939\u4e0b\uff0c\u89e3\u538b\u540e data \u6587\u4ef6\u5939\u4e0b\u5e94\u5305\u542b\u4ee5\u4e0b\u6587\u4ef6\uff1a - 'train' \u6587\u4ef6\u5939\uff0c\u8bad\u7ec3\u56fe\u7247 - 'train_list.txt' \u6587\u4ef6 - 'val' \u6587\u4ef6\u5939\uff0c\u9a8c\u8bc1\u56fe\u7247 - 'val_list.txt' \u6587\u4ef6","title":"\u51c6\u5907\u6570\u636e"},{"location":"tutorials/quant_post_demo/#_5","text":"\u56e0\u4e3a\u79bb\u7ebf\u91cf\u5316\u63a5\u53e3\u53ea\u652f\u6301\u52a0\u8f7d\u901a\u8fc7 fluid.io.save_inference_model \u63a5\u53e3\u4fdd\u5b58\u7684\u6a21\u578b\uff0c\u56e0\u6b64\u5982\u679c\u60a8\u7684\u6a21\u578b\u662f\u901a\u8fc7\u5176\u4ed6\u63a5\u53e3\u4fdd\u5b58\u7684\uff0c\u90a3\u9700\u8981\u5148\u5c06\u6a21\u578b\u8fdb\u884c\u8f6c\u5316\u3002\u672c\u793a\u4f8b\u5c06\u4ee5\u5206\u7c7b\u6a21\u578b\u4e3a\u4f8b\u8fdb\u884c\u8bf4\u660e\u3002 \u9996\u5148\u5728 imagenet\u5206\u7c7b\u6a21\u578b \u4e2d\u4e0b\u8f7d\u8bad\u7ec3\u597d\u7684 mobilenetv1 \u6a21\u578b\u3002 \u5728\u5f53\u524d\u6587\u4ef6\u5939\u4e0b\u521b\u5efa 'pretrain' \u6587\u4ef6\u5939\uff0c\u5c06 mobilenetv1 \u6a21\u578b\u5728\u8be5\u6587\u4ef6\u5939\u4e0b\u89e3\u538b\uff0c\u89e3\u538b\u540e\u7684\u76ee\u5f55\u4e3a pretrain/MobileNetV1_pretrained","title":"\u51c6\u5907\u9700\u8981\u91cf\u5316\u7684\u6a21\u578b"},{"location":"tutorials/quant_post_demo/#_6","text":"\u901a\u8fc7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u53ef\u5c06\u6a21\u578b\u8f6c\u5316\u4e3a\u79bb\u7ebf\u91cf\u5316\u63a5\u53e3\u53ef\u7528\u7684\u6a21\u578b\uff1a 1 python export_model . py --model \"MobileNet\" --pretrained_model ./pretrain/MobileNetV1_pretrained --data imagenet \u8f6c\u5316\u4e4b\u540e\u7684\u6a21\u578b\u5b58\u50a8\u5728 inference_model/MobileNet/ \u6587\u4ef6\u5939\u4e0b\uff0c\u53ef\u770b\u5230\u8be5\u6587\u4ef6\u5939\u4e0b\u6709 'model' , 'weights' \u4e24\u4e2a\u6587\u4ef6\u3002","title":"\u5bfc\u51fa\u6a21\u578b"},{"location":"tutorials/quant_post_demo/#_7","text":"\u63a5\u4e0b\u6765\u5bf9\u5bfc\u51fa\u7684\u6a21\u578b\u6587\u4ef6\u8fdb\u884c\u79bb\u7ebf\u91cf\u5316\uff0c\u79bb\u7ebf\u91cf\u5316\u7684\u811a\u672c\u4e3a quant_post.py \uff0c\u811a\u672c\u4e2d\u4f7f\u7528\u63a5\u53e3 paddleslim.quant.quant_post \u5bf9\u6a21\u578b\u8fdb\u884c\u79bb\u7ebf\u91cf\u5316\u3002\u8fd0\u884c\u547d\u4ee4\u4e3a\uff1a 1 python quant_post . py --model_path ./inference_model/MobileNet --save_path ./quant_model_train/MobileNet --model_filename model --params_filename weights model_path : \u9700\u8981\u91cf\u5316\u7684\u6a21\u578b\u5750\u5728\u7684\u6587\u4ef6\u5939 save_path : \u91cf\u5316\u540e\u7684\u6a21\u578b\u4fdd\u5b58\u7684\u8def\u5f84 model_filename : \u5982\u679c\u9700\u8981\u91cf\u5316\u7684\u6a21\u578b\u7684\u53c2\u6570\u6587\u4ef6\u4fdd\u5b58\u5728\u4e00\u4e2a\u6587\u4ef6\u4e2d\uff0c\u5219\u8bbe\u7f6e\u4e3a\u8be5\u6a21\u578b\u7684\u6a21\u578b\u6587\u4ef6\u540d\u79f0\uff0c\u5982\u679c\u53c2\u6570\u6587\u4ef6\u4fdd\u5b58\u5728\u591a\u4e2a\u6587\u4ef6\u4e2d\uff0c\u5219\u4e0d\u9700\u8981\u8bbe\u7f6e\u3002 params_filename : \u5982\u679c\u9700\u8981\u91cf\u5316\u7684\u6a21\u578b\u7684\u53c2\u6570\u6587\u4ef6\u4fdd\u5b58\u5728\u4e00\u4e2a\u6587\u4ef6\u4e2d\uff0c\u5219\u8bbe\u7f6e\u4e3a\u8be5\u6a21\u578b\u7684\u53c2\u6570\u6587\u4ef6\u540d\u79f0\uff0c\u5982\u679c\u53c2\u6570\u6587\u4ef6\u4fdd\u5b58\u5728\u591a\u4e2a\u6587\u4ef6\u4e2d\uff0c\u5219\u4e0d\u9700\u8981\u8bbe\u7f6e\u3002 \u8fd0\u884c\u4ee5\u4e0a\u547d\u4ee4\u540e\uff0c\u53ef\u5728 ${save_path} \u4e0b\u770b\u5230\u91cf\u5316\u540e\u7684\u6a21\u578b\u6587\u4ef6\u548c\u53c2\u6570\u6587\u4ef6\u3002 \u4f7f\u7528\u7684\u91cf\u5316\u7b97\u6cd5\u4e3a 'KL' , \u4f7f\u7528\u8bad\u7ec3\u96c6\u4e2d\u7684160\u5f20\u56fe\u7247\u8fdb\u884c\u91cf\u5316\u53c2\u6570\u7684\u6821\u6b63\u3002","title":"\u79bb\u7ebf\u91cf\u5316"},{"location":"tutorials/quant_post_demo/#_8","text":"\u4f7f\u7528 eval.py \u811a\u672c\u5bf9\u91cf\u5316\u524d\u540e\u7684\u6a21\u578b\u8fdb\u884c\u6d4b\u8bd5\uff0c\u5f97\u5230\u6a21\u578b\u7684\u5206\u7c7b\u7cbe\u5ea6\u8fdb\u884c\u5bf9\u6bd4\u3002 \u9996\u5148\u6d4b\u8bd5\u91cf\u5316\u524d\u7684\u6a21\u578b\u7684\u7cbe\u5ea6\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a 1 python eval . py --model_path ./inference_model/MobileNet --model_name model --params_name weights \u7cbe\u5ea6\u8f93\u51fa\u4e3a: 1 top1_acc / top5_acc = [ 0 . 70913923 0 . 89548034 ] \u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6d4b\u8bd5\u79bb\u7ebf\u91cf\u5316\u540e\u7684\u6a21\u578b\u7684\u7cbe\u5ea6\uff1a 1 python eval . py --model_path ./quant_model_train/MobileNet \u7cbe\u5ea6\u8f93\u51fa\u4e3a 1 top1_acc / top5_acc = [ 0 . 70141864 0 . 89086477 ] \u4ece\u4ee5\u4e0a\u7cbe\u5ea6\u5bf9\u6bd4\u53ef\u4ee5\u770b\u51fa\uff0c\u5bf9 mobilenet \u5728 imagenet \u4e0a\u7684\u5206\u7c7b\u6a21\u578b\u8fdb\u884c\u79bb\u7ebf\u91cf\u5316\u540e top1 \u7cbe\u5ea6\u635f\u5931\u4e3a 0.77% \uff0c top5 \u7cbe\u5ea6\u635f\u5931\u4e3a 0.46% .","title":"\u6d4b\u8bd5\u7cbe\u5ea6"},{"location":"tutorials/sensitivity_demo/","text":"\u8be5\u793a\u4f8b\u4ecb\u7ecd\u5982\u4f55\u5206\u6790\u5377\u79ef\u7f51\u7edc\u4e2d\u5404\u5377\u79ef\u5c42\u7684\u654f\u611f\u5ea6\uff0c\u4ee5\u53ca\u5982\u4f55\u6839\u636e\u8ba1\u7b97\u51fa\u7684\u654f\u611f\u5ea6\u9009\u62e9\u4e00\u7ec4\u5408\u9002\u7684\u526a\u88c1\u7387\u3002 \u8be5\u793a\u4f8b\u9ed8\u8ba4\u4f1a\u81ea\u52a8\u4e0b\u8f7d\u5e76\u4f7f\u7528MNIST\u6570\u636e\u3002\u652f\u6301\u4ee5\u4e0b\u6a21\u578b\uff1a MobileNetV1 MobileNetV2 ResNet50 1. \u63a5\u53e3\u4ecb\u7ecd # \u8be5\u793a\u4f8b\u6d89\u53ca\u4ee5\u4e0b\u63a5\u53e3\uff1a paddleslim.prune.sensitivity paddleslim.prune.merge_sensitive paddleslim.prune.get_ratios_by_loss 2. \u8fd0\u884c\u793a\u4f8b # \u5728\u8def\u5f84 PaddleSlim/demo/sensitive \u4e0b\u6267\u884c\u4ee5\u4e0b\u4ee3\u7801\u8fd0\u884c\u793a\u4f8b\uff1a 1 2 export CUDA_VISIBLE_DEVICES = 0 python train . py --model \"MobileNetV1\" \u901a\u8fc7 python train.py --help \u67e5\u770b\u66f4\u591a\u9009\u9879\u3002 3. \u91cd\u8981\u6b65\u9aa4\u8bf4\u660e # 3.1 \u8ba1\u7b97\u654f\u611f\u5ea6 # \u8ba1\u7b97\u654f\u611f\u5ea6\u4e4b\u524d\uff0c\u7528\u6237\u9700\u8981\u642d\u5efa\u597d\u7528\u4e8e\u6d4b\u8bd5\u7684\u7f51\u7edc\uff0c\u4ee5\u53ca\u5b9e\u73b0\u8bc4\u4f30\u6a21\u578b\u7cbe\u5ea6\u7684\u56de\u8c03\u51fd\u6570\u3002 \u8c03\u7528 paddleslim.prune.sensitivity \u63a5\u53e3\u8ba1\u7b97\u654f\u611f\u5ea6\u3002\u654f\u611f\u5ea6\u4fe1\u606f\u4f1a\u8ffd\u52a0\u5230 sensitivities_file \u9009\u9879\u6240\u6307\u5b9a\u7684\u6587\u4ef6\u4e2d\uff0c\u5982\u679c\u9700\u8981\u91cd\u65b0\u8ba1\u7b97\u654f\u611f\u5ea6\uff0c\u9700\u8981\u5148\u5220\u9664 sensitivities_file \u6587\u4ef6\u3002 \u5982\u679c\u6a21\u578b\u8bc4\u4f30\u901f\u5ea6\u8f83\u6162\uff0c\u53ef\u4ee5\u901a\u8fc7\u591a\u8fdb\u7a0b\u7684\u65b9\u5f0f\u52a0\u901f\u654f\u611f\u5ea6\u8ba1\u7b97\u8fc7\u7a0b\u3002\u6bd4\u5982\u5728\u8fdb\u7a0b1\u4e2d\u8bbe\u7f6e pruned_ratios=[0.1, 0.2, 0.3, 0.4] \uff0c\u5e76\u5c06\u654f\u611f\u5ea6\u4fe1\u606f\u5b58\u653e\u5728\u6587\u4ef6 sensitivities_0.data \u4e2d\uff0c\u7136\u540e\u5728\u8fdb\u7a0b2\u4e2d\u8bbe\u7f6e pruned_ratios=[0.5, 0.6, 0.7] \uff0c\u5e76\u5c06\u654f\u611f\u5ea6\u4fe1\u606f\u5b58\u50a8\u5728\u6587\u4ef6 sensitivities_1.data \u4e2d\u3002\u8fd9\u6837\u6bcf\u4e2a\u8fdb\u7a0b\u53ea\u4f1a\u8ba1\u7b97\u6307\u5b9a\u526a\u5207\u7387\u4e0b\u7684\u654f\u611f\u5ea6\u4fe1\u606f\u3002\u591a\u8fdb\u7a0b\u53ef\u4ee5\u8fd0\u884c\u5728\u5355\u673a\u591a\u5361\uff0c\u6216\u591a\u673a\u591a\u5361\u3002 \u4ee3\u7801\u5982\u4e0b\uff1a 1 2 3 4 5 6 7 8 # \u8fdb\u7a0b 1 sensitivity ( val_program , place , params , test , sensitivities_file = \"sensitivities_0.data\" , pruned_ratios = [ 0 . 1 , 0 . 2 , 0 . 3 , 0 . 4 ]) 1 2 3 4 5 6 7 8 # \u8fdb\u7a0b 2 sensitivity ( val_program , place , params , test , sensitivities_file = \"sensitivities_1.data\" , pruned_ratios = [ 0 . 5 , 0 . 6 , 0 . 7 ]) 3.2 \u5408\u5e76\u654f\u611f\u5ea6 # \u5982\u679c\u7528\u6237\u901a\u8fc7\u4e0a\u4e00\u8282\u591a\u8fdb\u7a0b\u7684\u65b9\u5f0f\u751f\u6210\u4e86\u591a\u4e2a\u5b58\u50a8\u654f\u611f\u5ea6\u4fe1\u606f\u7684\u6587\u4ef6\uff0c\u53ef\u4ee5\u901a\u8fc7 paddleslim.prune.merge_sensitive \u5c06\u5176\u5408\u5e76\uff0c\u5408\u5e76\u540e\u7684\u654f\u611f\u5ea6\u4fe1\u606f\u5b58\u50a8\u5728\u4e00\u4e2a dict \u4e2d\u3002\u4ee3\u7801\u5982\u4e0b\uff1a 1 sens = merge_sensitive ([ \"./sensitivities_0.data\" , \"./sensitivities_1.data\" ]) 3.3 \u8ba1\u7b97\u526a\u88c1\u7387 # \u8c03\u7528 paddleslim.prune.get_ratios_by_loss \u63a5\u53e3\u8ba1\u7b97\u4e00\u7ec4\u526a\u88c1\u7387\u3002 1 ratios = get_ratios_by_loss ( sens , 0 . 01 ) \u5176\u4e2d\uff0c 0.01 \u4e3a\u4e00\u4e2a\u9608\u503c\uff0c\u5bf9\u4e8e\u4efb\u610f\u5377\u79ef\u5c42\uff0c\u5176\u526a\u88c1\u7387\u4e3a\u4f7f\u7cbe\u5ea6\u635f\u5931\u4f4e\u4e8e\u9608\u503c 0.01 \u7684\u6700\u5927\u526a\u88c1\u7387\u3002 \u7528\u6237\u5728\u8ba1\u7b97\u51fa\u4e00\u7ec4\u526a\u88c1\u7387\u4e4b\u540e\u53ef\u4ee5\u901a\u8fc7\u63a5\u53e3 paddleslim.prune.Pruner \u526a\u88c1\u7f51\u7edc\uff0c\u5e76\u7528\u63a5\u53e3 paddleslim.analysis.flops \u8ba1\u7b97 FLOPs \u3002\u5982\u679c FLOPs \u4e0d\u6ee1\u8db3\u8981\u6c42\uff0c\u8c03\u6574\u9608\u503c\u91cd\u65b0\u8ba1\u7b97\u51fa\u4e00\u7ec4\u526a\u88c1\u7387\u3002","title":"Sensitivity demo"},{"location":"tutorials/sensitivity_demo/#1","text":"\u8be5\u793a\u4f8b\u6d89\u53ca\u4ee5\u4e0b\u63a5\u53e3\uff1a paddleslim.prune.sensitivity paddleslim.prune.merge_sensitive paddleslim.prune.get_ratios_by_loss","title":"1. \u63a5\u53e3\u4ecb\u7ecd"},{"location":"tutorials/sensitivity_demo/#2","text":"\u5728\u8def\u5f84 PaddleSlim/demo/sensitive \u4e0b\u6267\u884c\u4ee5\u4e0b\u4ee3\u7801\u8fd0\u884c\u793a\u4f8b\uff1a 1 2 export CUDA_VISIBLE_DEVICES = 0 python train . py --model \"MobileNetV1\" \u901a\u8fc7 python train.py --help \u67e5\u770b\u66f4\u591a\u9009\u9879\u3002","title":"2. \u8fd0\u884c\u793a\u4f8b"},{"location":"tutorials/sensitivity_demo/#3","text":"","title":"3. \u91cd\u8981\u6b65\u9aa4\u8bf4\u660e"},{"location":"tutorials/sensitivity_demo/#31","text":"\u8ba1\u7b97\u654f\u611f\u5ea6\u4e4b\u524d\uff0c\u7528\u6237\u9700\u8981\u642d\u5efa\u597d\u7528\u4e8e\u6d4b\u8bd5\u7684\u7f51\u7edc\uff0c\u4ee5\u53ca\u5b9e\u73b0\u8bc4\u4f30\u6a21\u578b\u7cbe\u5ea6\u7684\u56de\u8c03\u51fd\u6570\u3002 \u8c03\u7528 paddleslim.prune.sensitivity \u63a5\u53e3\u8ba1\u7b97\u654f\u611f\u5ea6\u3002\u654f\u611f\u5ea6\u4fe1\u606f\u4f1a\u8ffd\u52a0\u5230 sensitivities_file \u9009\u9879\u6240\u6307\u5b9a\u7684\u6587\u4ef6\u4e2d\uff0c\u5982\u679c\u9700\u8981\u91cd\u65b0\u8ba1\u7b97\u654f\u611f\u5ea6\uff0c\u9700\u8981\u5148\u5220\u9664 sensitivities_file \u6587\u4ef6\u3002 \u5982\u679c\u6a21\u578b\u8bc4\u4f30\u901f\u5ea6\u8f83\u6162\uff0c\u53ef\u4ee5\u901a\u8fc7\u591a\u8fdb\u7a0b\u7684\u65b9\u5f0f\u52a0\u901f\u654f\u611f\u5ea6\u8ba1\u7b97\u8fc7\u7a0b\u3002\u6bd4\u5982\u5728\u8fdb\u7a0b1\u4e2d\u8bbe\u7f6e pruned_ratios=[0.1, 0.2, 0.3, 0.4] \uff0c\u5e76\u5c06\u654f\u611f\u5ea6\u4fe1\u606f\u5b58\u653e\u5728\u6587\u4ef6 sensitivities_0.data \u4e2d\uff0c\u7136\u540e\u5728\u8fdb\u7a0b2\u4e2d\u8bbe\u7f6e pruned_ratios=[0.5, 0.6, 0.7] \uff0c\u5e76\u5c06\u654f\u611f\u5ea6\u4fe1\u606f\u5b58\u50a8\u5728\u6587\u4ef6 sensitivities_1.data \u4e2d\u3002\u8fd9\u6837\u6bcf\u4e2a\u8fdb\u7a0b\u53ea\u4f1a\u8ba1\u7b97\u6307\u5b9a\u526a\u5207\u7387\u4e0b\u7684\u654f\u611f\u5ea6\u4fe1\u606f\u3002\u591a\u8fdb\u7a0b\u53ef\u4ee5\u8fd0\u884c\u5728\u5355\u673a\u591a\u5361\uff0c\u6216\u591a\u673a\u591a\u5361\u3002 \u4ee3\u7801\u5982\u4e0b\uff1a 1 2 3 4 5 6 7 8 # \u8fdb\u7a0b 1 sensitivity ( val_program , place , params , test , sensitivities_file = \"sensitivities_0.data\" , pruned_ratios = [ 0 . 1 , 0 . 2 , 0 . 3 , 0 . 4 ]) 1 2 3 4 5 6 7 8 # \u8fdb\u7a0b 2 sensitivity ( val_program , place , params , test , sensitivities_file = \"sensitivities_1.data\" , pruned_ratios = [ 0 . 5 , 0 . 6 , 0 . 7 ])","title":"3.1 \u8ba1\u7b97\u654f\u611f\u5ea6"},{"location":"tutorials/sensitivity_demo/#32","text":"\u5982\u679c\u7528\u6237\u901a\u8fc7\u4e0a\u4e00\u8282\u591a\u8fdb\u7a0b\u7684\u65b9\u5f0f\u751f\u6210\u4e86\u591a\u4e2a\u5b58\u50a8\u654f\u611f\u5ea6\u4fe1\u606f\u7684\u6587\u4ef6\uff0c\u53ef\u4ee5\u901a\u8fc7 paddleslim.prune.merge_sensitive \u5c06\u5176\u5408\u5e76\uff0c\u5408\u5e76\u540e\u7684\u654f\u611f\u5ea6\u4fe1\u606f\u5b58\u50a8\u5728\u4e00\u4e2a dict \u4e2d\u3002\u4ee3\u7801\u5982\u4e0b\uff1a 1 sens = merge_sensitive ([ \"./sensitivities_0.data\" , \"./sensitivities_1.data\" ])","title":"3.2 \u5408\u5e76\u654f\u611f\u5ea6"},{"location":"tutorials/sensitivity_demo/#33","text":"\u8c03\u7528 paddleslim.prune.get_ratios_by_loss \u63a5\u53e3\u8ba1\u7b97\u4e00\u7ec4\u526a\u88c1\u7387\u3002 1 ratios = get_ratios_by_loss ( sens , 0 . 01 ) \u5176\u4e2d\uff0c 0.01 \u4e3a\u4e00\u4e2a\u9608\u503c\uff0c\u5bf9\u4e8e\u4efb\u610f\u5377\u79ef\u5c42\uff0c\u5176\u526a\u88c1\u7387\u4e3a\u4f7f\u7cbe\u5ea6\u635f\u5931\u4f4e\u4e8e\u9608\u503c 0.01 \u7684\u6700\u5927\u526a\u88c1\u7387\u3002 \u7528\u6237\u5728\u8ba1\u7b97\u51fa\u4e00\u7ec4\u526a\u88c1\u7387\u4e4b\u540e\u53ef\u4ee5\u901a\u8fc7\u63a5\u53e3 paddleslim.prune.Pruner \u526a\u88c1\u7f51\u7edc\uff0c\u5e76\u7528\u63a5\u53e3 paddleslim.analysis.flops \u8ba1\u7b97 FLOPs \u3002\u5982\u679c FLOPs \u4e0d\u6ee1\u8db3\u8981\u6c42\uff0c\u8c03\u6574\u9608\u503c\u91cd\u65b0\u8ba1\u7b97\u51fa\u4e00\u7ec4\u526a\u88c1\u7387\u3002","title":"3.3 \u8ba1\u7b97\u526a\u88c1\u7387"}]}
\ No newline at end of file
diff --git a/sitemap.xml.gz b/sitemap.xml.gz
index 2dab1d96ad469b2e40da6cded18ac235f9497156..f92d879cbba8a31d36886e78ce3f082d7acc7155 100644
Binary files a/sitemap.xml.gz and b/sitemap.xml.gz differ
diff --git a/tutorials/distillation_demo/index.html b/tutorials/distillation_demo/index.html
index 29a942185add66b7ee7dfb24b94ff81cd9eb8deb..3b949cce2292100d3303b3747b9d0f64d559d5a2 100644
--- a/tutorials/distillation_demo/index.html
+++ b/tutorials/distillation_demo/index.html
@@ -91,7 +91,7 @@
3.选择特征图
- 4. 合并特征图(merge)
+ 4. 合并Program(merge)
5.添加蒸馏loss
@@ -294,7 +294,7 @@
-4. 合并特征图(merge)
+4. 合并Program(merge)
PaddlePaddle使用Program来描述计算图,为了同时计算student和teacher两个Program,这里需要将其两者合并(merge)为一个Program。
merge过程操作较多,具体细节请参考merge API文档。