!21714 unify softplus data description and verification

Merge pull request !21714 from zhangbuxue/unify_softplus_data_description_and_verification
This commit is contained in:
i-robot 2021-08-12 13:39:28 +00:00 committed by Gitee
commit 2a9f1bf768
4 changed files with 16 additions and 16 deletions

View File

@ -39,7 +39,7 @@ TypePtr SoftplusInferType(const PrimitivePtr &prim, const std::vector<AbstractBa
MS_EXCEPTION_IF_NULL(prim);
auto prim_name = prim->name();
// check
std::set<TypePtr> valid_index_types = {kFloat16, kFloat32, kFloat64};
std::set<TypePtr> valid_index_types = {kFloat16, kFloat32};
auto x_type = input_args[0]->BuildType();
(void)CheckAndConvertUtils::CheckTensorTypeValid("x", x_type, valid_index_types, prim_name);
return x_type;

View File

@ -346,17 +346,17 @@ class Softplus(Primitive):
Inputs:
- **input_x** (Tensor) - Tensor of shape :math:`(N, *)`, where :math:`*` means, any number of
additional dimensions, with float16, float32 or float64 data type.
additional dimensions, with float16 or float32 data type.
Outputs:
Tensor, with the same type and shape as the `input_x`.
Raises:
TypeError: If `input_x` is not a Tensor.
TypeError: If dtype of `input_x` does not belong to any of [float16, float32, float64].
TypeError: If the dtype of `input_x` is neither float16 nor float32.
Supported Platforms:
``Ascend`` ``GPU``
``Ascend`` ``GPU`` ``CPU``
Examples:
>>> input_x = Tensor(np.array([1, 2, 3, 4, 5]), mindspore.float32)

View File

@ -48,7 +48,7 @@ class Grad(nn.Cell):
@pytest.mark.level0
@pytest.mark.platform_x86_cpu
@pytest.mark.env_onecard
def test_softplus_grad():
def test_softplus_grad_1d_fp32():
x = np.array([0.58401114, 0.68800163, 0.9760397, 0.14702141, 0.46563736, 0.9607501,
0.14567593, 0.12261796, 0.37054458, 0.46421242]).astype(np.float32)
dy = np.array([0.5559598, 0.96994054, 0.24770357, 0.34646875, 0.2984393, 0.03287048,
@ -67,7 +67,7 @@ def test_softplus_grad():
@pytest.mark.level0
@pytest.mark.platform_x86_cpu
@pytest.mark.env_onecard
def test_softplus_grad_fp16():
def test_softplus_grad_3d_fp16():
np.random.seed(42)
x_np = np.random.randn(5, 3, 6).astype(np.float16)
dy_np = np.random.randn(5, 3, 6).astype(np.float16)
@ -81,10 +81,10 @@ def test_softplus_grad_fp16():
@pytest.mark.level0
@pytest.mark.platform_x86_cpu
@pytest.mark.env_onecard
def test_softplus_grad_7d_fp64():
def test_softplus_grad_7d_fp32():
np.random.seed(20)
x_np = np.random.randn(5, 3, 6, 3, 4, 5, 6).astype(np.float64)
dy_np = np.random.randn(5, 3, 6, 3, 4, 5, 6).astype(np.float64)
x_np = np.random.randn(5, 3, 6, 3, 4, 5, 6).astype(np.float32)
dy_np = np.random.randn(5, 3, 6, 3, 4, 5, 6).astype(np.float32)
net = SoftplusNet()
grad = Grad(net)
output = grad(Tensor(x_np), Tensor(dy_np))

View File

@ -40,8 +40,8 @@ def SoftplusCompute(x):
@pytest.mark.level0
@pytest.mark.platform_x86_cpu
@pytest.mark.env_onecard
def test_softplus_0d():
x_np = np.array(1.2, np.float64)
def test_softplus_0d_fp32():
x_np = np.array(1.2, np.float32)
y_np = SoftplusCompute(x_np)
x_ms = Tensor(x_np)
@ -54,7 +54,7 @@ def test_softplus_0d():
@pytest.mark.level0
@pytest.mark.platform_x86_cpu
@pytest.mark.env_onecard
def test_softplus_1d():
def test_softplus_1d_fp32():
x_np = np.random.random((50,)).astype(np.float32)
y_np = SoftplusCompute(x_np)
@ -68,7 +68,7 @@ def test_softplus_1d():
@pytest.mark.level0
@pytest.mark.platform_x86_cpu
@pytest.mark.env_onecard
def test_softplus_2d():
def test_softplus_2d_fp32():
x_np = np.random.random((50, 40)).astype(np.float32)
y_np = SoftplusCompute(x_np)
@ -82,7 +82,7 @@ def test_softplus_2d():
@pytest.mark.level0
@pytest.mark.platform_x86_cpu
@pytest.mark.env_onecard
def test_softplus_4d():
def test_softplus_4d_fp32():
x_np = np.random.random((32, 3, 224, 224)).astype(np.float32)
y_np = SoftplusCompute(x_np)
@ -124,8 +124,8 @@ def test_softplus_4d_fp16():
@pytest.mark.level0
@pytest.mark.platform_x86_cpu
@pytest.mark.env_onecard
def test_softplus_7d_fp64():
x_np = np.random.random((32, 3, 20, 20, 20, 10, 10)).astype(np.float16)
def test_softplus_7d_fp32():
x_np = np.random.random((32, 3, 20, 20, 20, 10, 10)).astype(np.float32)
y_np = SoftplusCompute(x_np)
x_ms = Tensor(x_np)