mindspore.ops.TensorDump
- class mindspore.ops.TensorDump(input_output='out')[source]
Save the Tensor as an npy file in numpy format.
Warning
The parameter input_output will no longer support the value 'all'.
Note
In Ascend platform with graph mode, the environment variables MS_DUMP_SLICE_SIZE and MS_DUMP_WAIT_TIME can be set to solve operator execution failure when outputting big tensor or outputting tensor intensively.
- Parameters
input_output (str, optional) –
Used to control Tensordump behavior. Available value is one of ['in', 'out']. 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 'in', the dump data contains only OpB's input slice.
For input_output is 'in', the input slice npy file format is: fileName_dumpMode_dtype_id.npy.
For input_output is 'out', the output slice npy file format is: fileName_dtype_id.npy.
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).
dumpMode: Value of the parameter input_output.
dtype: The original data type. Data of type bfloat16 stored in the .npy file will be converted to float32.
id: An auto increment ID.
- Inputs:
file (str) - The path of the file to be saved.
input_x (Tensor) - Input Tensor of any dimension.
- 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('add_float32_0.npy') >>> print(add) [[2. 3. 4. 5.] [6. 7. 8. 9.]]