mindspore.ops.TensorDump

View Source On Gitee
class mindspore.ops.TensorDump(input_output='out')[source]

Save the Tensor as an npy file in numpy format.

Warning

  • If a large amount of data is stored within a short period, it may lead to memory overflow on the device side. Consider slicing the data to reduce the data scale.

  • Since data saving is processed asynchronously, when the amount of data is too large or the main process exits too quickly, data loss may occur. You need to actively control the destruction time of the main process, such as using sleep.

Parameters

input_output (str, optional) –

Used to control Tensordump behavior. Available value is one of ['in', 'out', 'all']. Default value is out.

In case of OpA –> RedistributionOps –> OpB, The dump data of OpA's output is not equal to OpB's input (Due to the redistribution operators). So the parameter input_output is to handle this situation.

Assuming OpA's output is used as both Tensordump's input parameter and OpB's input parameter. Different requirements of saving dump data can be achieved by configuring parameter input_output:

  • If the input_output is 'out', the dump data contains only OpA's output slice.

  • If the input_output is 'all', the dump data contains both OpA's output slice and OpB's input slice.

  • If the input_output is 'in', the dump data contains only OpB's input slice.

For input_output is 'all' or 'in', the input slice npy file format is: id_fileName_cNodeID_dumpMode_rankID.npy.

For input_output is 'out' or 'all' the output slice npy file format is: id_fileName.npy.

  • id: An auto increment ID.

  • fileName: Value of the parameter file (if parameter file_name is a user-specified path, the value of fileName is the last level of the path).

  • cNodeID: The node ID of the Tensordump node in the step_parallel_end.ir file.

  • dumpMode: Value of the parameter input_output.

  • rankID: Logical device id.

Inputs:
  • file (str) - The path of the file to be saved.

  • input_x (Tensor) - Input Tensor of any dimension.

Raises
Supported Platforms:

Ascend

Examples

>>> import numpy as np
>>> import mindspore as ms
>>> import time
>>> from mindspore import nn, Tensor, ops
>>> ms.set_context(mode=ms.GRAPH_MODE, device_target="Ascend")
>>> class Net(nn.Cell):
...     def __init__(self):
...         super(Net, self).__init__()
...         self.dump = ops.TensorDump()
...
...     def construct(self, x):
...         x += 1.
...         self.dump('add', x)
...         x /= 2.
...         self.dump('div', x)
...         x *= 5.
...         self.dump('mul', x)
...         return x
...
>>> x = np.array([[1, 2, 3, 4], [5, 6, 7, 8]]).astype(np.float32)
>>> input_x = Tensor(x)
>>> net = Net()
>>> out = net(input_x)
>>> time.sleep(0.5)
>>> add = np.load('0_add.npy')
>>> print(add)
[[2. 3. 4. 5.]
 [6. 7. 8. 9.]]