The --task-trace option will be discarded in later versions. Use --task-time instead.
For TensorFlow training or online inference, simply use TensorFlow APIs in your training script to activate profiling. The following features are available:
You can either modify the training script and configure profiling_mode (as elaborated in this section), or set the environment variable PROFILING_MODE (see Profiling with Environment Variables). If both are used, profiling_mode takes precedence over PROFILING_MODE.
This section describes how to enable global profiling. For more information, see TensorFlow 1.15 Model Porting and TensorFlow 2.6.5 Model Porting.
Before enabling profiling, ensure that the training or online inference script can be executed properly.
1 2 3 4 5 6 7 8 9 10 11 12 | from npu_bridge.estimator.npu.npu_config import NPURunConfig from npu_bridge.estimator.npu.npu_config import ProfilingConfig from npu_bridge.npu_init import * # enable_profiling: profiling enable. # output: path for storing profile data. Create the specified directory in the training environment (container or host) in advance. The running user configured during installation must have the read and write permissions on this path. It can be either an absolute path or a relative path. # task_trace: task trace collection enable. profiling_options = '{"output":"/home/HwHiAiUser/output","task_trace":"on"}' profiling_config = ProfilingConfig(enable_profiling=True, profiling_options= profiling_options) session_config=tf.ConfigProto() config = NPURunConfig(profiling_config=profiling_config, session_config=session_config) |
If the problem cannot be spotted, enable training_trace to profile iteration traces. The sample code is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | from npu_bridge.estimator.npu.npu_config import NPURunConfig from npu_bridge.estimator.npu.npu_config import ProfilingConfig from npu_bridge.npu_init import * # enable_profiling: profiling enable # output: path for storing profile data # task_trace: task trace collection enable # training_trace: iteration trace collection enable # fp_point: start point of the forward propagated operator in iteration traces, recording the start timestamp of forward propagation. # bp_point: end point of the backward propagated operator in iteration traces, recording the end timestamp of backward propagation. fp_point and bp_point are used to compute the time used by forward and backward propagation. profiling_options = '{"output":"/home/HwHiAiUser/output","task_trace":"on","training_trace":"on","aicpu":"on","fp_point":"","bp_point":"","aic_metrics":"PipeUtilization"}' profiling_config = ProfilingConfig(enable_profiling=True, profiling_options= profiling_options) session_config=tf.ConfigProto(allow_soft_placement=True) config = NPURunConfig(profiling_config=profiling_config, session_config=session_config) |
1 2 3 4 5 6 7 8 9 10 | 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["profiling_mode"].b = True custom_op.parameter_map["profiling_options"].s = tf.compat.as_bytes('{"output":"/home/HwHiAiUser/output","task_trace":"on"}') config.graph_options.rewrite_options.remapping = RewriterConfig.OFF config.graph_options.rewrite_options.memory_optimization = RewriterConfig.OFF with tf.Session(config=config) as sess: sess.run() |
If the problem cannot be spotted, enable training_trace to profile iteration traces. The sample code is as follows:
1 2 3 4 5 6 7 8 9 10 | 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["profiling_mode"].b = True custom_op.parameter_map["profiling_options"].s = tf.compat.as_bytes('{"output":"/home/HwHiAiUser/output","task_trace":"on","training_trace":"on","aicpu":"on","fp_point":"","bp_point":"","aic_metrics":"PipeUtilization"}') config.graph_options.rewrite_options.remapping = RewriterConfig.OFF config.graph_options.rewrite_options.memory_optimization = RewriterConfig.OFF with tf.Session(config=config) as sess: sess.run() |
After the training is complete, the PROF_XXX folder is generated in the directory specified by the output parameter to store the raw profile data.
msprof --export=on --output=/home/HwHiAiUser/profiling_output/PROF_XXX
After the parsing is complete, you can find the mindstudio_profiler_output directory generated in the PROF_XXX folder.