mindspore.profiler.tensor_board_trace_handler
- mindspore.profiler.tensor_board_trace_handler()[source]
For each step in dynamic graph mode, call this method for online analyse.
Examples
>>> import numpy as np >>> import mindspore as ms >>> import mindspore.dataset as ds >>> from mindspore import context, nn, Profiler >>> from mindspore.profiler import schedule, tensor_board_trace_handler >>> >>> 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 = ms.train.Model(test_net, loss, optimizer) ... model.train(1, data) >>> >>> if __name__ == '__main__': ... context.set_context(mode=ms.PYNATIVE_MODE, device_target="Ascend") ... ... net = Net() ... STEP_NUM = 15 ... ... with Profiler(schedule=schedule(wait=1, warm_up=1, active=2, repeat=1, skip_first=2), ... on_trace_ready=tensor_board_trace_handler) as prof: ... for i in range(STEP_NUM): ... train(net) ... prof.step()