mindspore.profiler.tensorboard_trace_handler
- mindspore.profiler.tensorboard_trace_handler(dir_name: str = None, worker_name: str = None, analyse_flag: bool = True, async_mode: bool = False)[source]
For each step in dynamic graph mode, call this method for online analyse.
- Parameters
dir_name (str, optional) – Specifies the directory path to save the analysis results. The default is
None
. The default save path is"./data"
.worker_name (str, optional) – Specifies the system version name. The default is
None
. The default project thread name is"Name of the current operating system + process ID"
.analyse_flag (bool, optional) – Whether to enable online analysis. The default value is
True
. Indicates online analysis.async_mode (bool, optional) – Whether to use asynchronous parsing mode. The default value is
False
. Indicates the use of synchronous parsing mode.
Examples
>>> import numpy as np >>> import mindspore >>> import mindspore.dataset as ds >>> from mindspore import context, nn >>> from mindspore.profiler import ProfilerLevel, AicoreMetrics, ExportType, ProfilerActivity >>> >>> class Net(nn.Cell): ... def __init__(self): ... super(Net, self).__init__() ... self.fc = nn.Dense(2, 2) ... ... def construct(self, x): ... return self.fc(x) >>> >>> def generator_net(): ... for _ in range(2): ... yield np.ones([2, 2]).astype(np.float32), np.ones([2]).astype(np.int32) >>> >>> def train(test_net): ... optimizer = nn.Momentum(test_net.trainable_params(), 1, 0.9) ... loss = nn.SoftmaxCrossEntropyWithLogits(sparse=True) ... data = ds.GeneratorDataset(generator_net(), ["data", "label"]) ... model = mindspore.train.Model(test_net, loss, optimizer) ... model.train(1, data) >>> >>> if __name__ == '__main__': ... # If the device_target is GPU, set the device_target to "GPU" ... context.set_context(mode=mindspore.GRAPH_MODE) ... mindspore.set_device("Ascend") ... ... # Init Profiler ... experimental_config = mindspore.profiler._ExperimentalConfig( ... profiler_level=ProfilerLevel.Level0, ... aic_metrics=AicoreMetrics.AiCoreNone, ... l2_cache=False, ... mstx=False, ... data_simplification=False, ... export_type=[ExportType.Text]) ... steps = 10 ... net = Net() ... # Note that the Profiler should be initialized before model.train ... with mindspore.profiler.profile(activities=[ProfilerActivity.CPU, ProfilerActivity.NPU], ... schedule=mindspore.profiler.schedule(wait=1, warmup=1, active=2, ... repeat=1, skip_first=2), ... on_trace_ready=mindspore.profiler.tensorboard_trace_handler("./data"), ... profile_memory=False, ... experimental_config=experimental_config) as prof: ... ... # Train Model ... for step in range(steps): ... train(net) ... prof.step()