Function Differences with torch.full

View Source On Gitee

torch.full

torch.full(
    size,
    fill_value,
    *,
    out=None,
    dtype=None,
    layout=torch.strided,
    device=None,
    requires_grad=False
) -> Tensor

For more information, see torch.full.

mindspore.ops.full

mindspore.ops.full(size, fill_value, *, dtype=None) -> Tensor

For more information, see mindspore.ops.full.

Differences

PyTorch: Return the tensor of the given size filled with fill_value.

MindSpore: MindSpore API implements basically the same function as PyTorch, but with different parameter names.

Categories

Subcategories

PyTorch

MindSpore

Difference

Parameters

Parameter 1

size

size

Consistent function

Parameter 2

fill_value

fill_value

For the parameter fill_value, PyTorch full operator supports the number type, and MindSpore does not support the plural type.

Parameter 3

dtype

dtype

Consistent function

Parameter 4

out

-

Not involved

Parameter 5

layout

-

Not involved

Parameter 6

device

-

Not involved

Parameter 7

requires_grad

-

MindSpore does not have this parameter and supports reverse derivation by default

Code Example 1

# PyTorch
import torch

torch_output = torch.full((2, 3), 1)
print(torch_output.numpy())
# [[1 1 1]
#  [1 1 1]]

# MindSpore
import mindspore

ms_tensor_output = mindspore.ops.full((2, 3), 1)
print(ms_tensor_output)
# [[1 1 1]
#  [1 1 1]]