AutoTune自动调优

概述

在模型训练阶段,可以通过Auto Tune工具全自动地完成模型中算子的性能自动优化,提升模型端到端的运行速度。Auto tune能够自动完成模型的性能优化,同时输出知识库文件。用户可以将知识库文件部署到新的环境上,同样的模型无需再次开启Auto tune即可获得之前调优的性能。

Auto Tune工具包含RL和GA两种调优模式:

默认训练过程中进行AutoTune自动调优,如需使能,请参考本节内容修改训练脚本。

关于AutoTune功能的更多介绍,请参考CANN 开发工具指南》中的“Auto Tune工具使用指南”章节

Estimator模式下使能

Estimator模式下,通过NPURunConfig中的auto_tune_mode参数设置调优模式:
from npu_bridge.npu_init import *

npu_config=NPURunConfig(
  model_dir=FLAGS.model_dir,
  save_checkpoints_steps=FLAGS.save_checkpoints_steps,
  session_config=tf.ConfigProto(allow_soft_placement=True,log_device_placement=False),
  auto_tune_mode="RL,GA"
  )

sess.run模式下使能

sess.run模式下,通过session配置项auto_tune_mode参数设置调优模式:
import tensorflow as tf
from npu_bridge.npu_init import *

config = tf.ConfigProto()

custom_op =  config.graph_options.rewrite_options.custom_optimizers.add()
custom_op.name =  "NpuOptimizer" 
custom_op.parameter_map["use_off_line"].b = True
custom_op.parameter_map["auto_tune_mode"].s = tf.compat.as_bytes("RL,GA")
config.graph_options.rewrite_options.remapping = RewriterConfig.OFF
config.graph_options.rewrite_options.memory_optimization = RewriterConfig.OFF

with tf.Session(config=config) as sess:
  print(sess.run(cost))