From 7b2fa2f6555edcf39723ec5710ad2424b1e6868e Mon Sep 17 00:00:00 2001 From: shaojunsong Date: Wed, 1 Mar 2023 15:13:38 +0800 Subject: [PATCH] fix soft shrink error --- .../Tensor/mindspore.Tensor.soft_shrink.rst | 6 ----- .../ops/mindspore.ops.func_soft_shrink.rst | 4 ++-- mindspore/ccsrc/pipeline/jit/resource.cc | 1 - .../_extends/parse/standard_method.py | 5 ----- mindspore/python/mindspore/common/tensor.py | 7 ------ .../python/mindspore/ops/function/__init__.py | 1 - .../python/mindspore/ops/function/nn_func.py | 5 ++--- mindspore/python/mindspore/ops/functional.py | 1 - tests/st/ops/gpu/test_soft_shrink_op.py | 22 +------------------ 9 files changed, 5 insertions(+), 47 deletions(-) delete mode 100644 docs/api/api_python/mindspore/Tensor/mindspore.Tensor.soft_shrink.rst diff --git a/docs/api/api_python/mindspore/Tensor/mindspore.Tensor.soft_shrink.rst b/docs/api/api_python/mindspore/Tensor/mindspore.Tensor.soft_shrink.rst deleted file mode 100644 index 806a5e9e0b2..00000000000 --- a/docs/api/api_python/mindspore/Tensor/mindspore.Tensor.soft_shrink.rst +++ /dev/null @@ -1,6 +0,0 @@ -mindspore.Tensor.soft_shrink -============================ - -.. py:method:: mindspore.Tensor.soft_shrink(lambd=0.5) - - 详情请参考 :func:`mindspore.ops.soft_shrink`。 diff --git a/docs/api/api_python/ops/mindspore.ops.func_soft_shrink.rst b/docs/api/api_python/ops/mindspore.ops.func_soft_shrink.rst index 9cb1c6eba73..d12f6c84018 100644 --- a/docs/api/api_python/ops/mindspore.ops.func_soft_shrink.rst +++ b/docs/api/api_python/ops/mindspore.ops.func_soft_shrink.rst @@ -1,7 +1,7 @@ -mindspore.ops.soft_shrink +mindspore.ops.softshrink ========================= -.. py:function:: mindspore.ops.soft_shrink(x, lambd=0.5) +.. py:function:: mindspore.ops.softshrink(x, lambd=0.5) Soft Shrink激活函数,按输入元素计算输出。公式定义如下: diff --git a/mindspore/ccsrc/pipeline/jit/resource.cc b/mindspore/ccsrc/pipeline/jit/resource.cc index 93d744fa808..99d35161dc3 100644 --- a/mindspore/ccsrc/pipeline/jit/resource.cc +++ b/mindspore/ccsrc/pipeline/jit/resource.cc @@ -350,7 +350,6 @@ BuiltInTypeMap &GetMethodMap() { {"hardshrink", std::string("hardshrink")}, // P.hshrink {"heaviside", std::string("heaviside")}, // F.heaviside {"hypot", std::string("hypot")}, // F.hypot - {"soft_shrink", std::string("soft_shrink")}, // P.SoftShrink {"gather_nd", std::string("gather_nd")}, // P.GatherNd() {"unique_consecutive", std::string("unique_consecutive")}, // UniqueConsecutive() {"unique_with_pad", std::string("unique_with_pad")}, // P.UniqueWithPad() diff --git a/mindspore/python/mindspore/_extends/parse/standard_method.py b/mindspore/python/mindspore/_extends/parse/standard_method.py index 4711e8aaa00..cf49d1aea8c 100644 --- a/mindspore/python/mindspore/_extends/parse/standard_method.py +++ b/mindspore/python/mindspore/_extends/parse/standard_method.py @@ -2136,11 +2136,6 @@ def hypot(x, other): return F.hypot(x, other) -def soft_shrink(x, lambd=0.5): - """Apply the soft shrink function for a tensor. Calculates the output according to the input elements.""" - return F.SoftShrink(lambd)(x) - - def getitem(data, index): """Implementation of `getitem`.""" return data.__getitem__(index) diff --git a/mindspore/python/mindspore/common/tensor.py b/mindspore/python/mindspore/common/tensor.py index 7f4a3dd84aa..554f48631d4 100644 --- a/mindspore/python/mindspore/common/tensor.py +++ b/mindspore/python/mindspore/common/tensor.py @@ -3110,13 +3110,6 @@ class Tensor(Tensor_, metaclass=_TensorMeta): self._init_check() return tensor_operator_registry.get('hypot')(self, other) - def soft_shrink(self, lambd=0.5): - r""" - For details, please refer to :func:`mindspore.ops.soft_shrink`. - """ - self._init_check() - return tensor_operator_registry.get('soft_shrink')(lambd)(self) - def to_coo(self): """ Convert a Tensor to COOTensor. diff --git a/mindspore/python/mindspore/ops/function/__init__.py b/mindspore/python/mindspore/ops/function/__init__.py index e6ba05a813f..3b13d4ea34b 100644 --- a/mindspore/python/mindspore/ops/function/__init__.py +++ b/mindspore/python/mindspore/ops/function/__init__.py @@ -439,7 +439,6 @@ from .nn_func import ( pixel_shuffle, pixel_unshuffle, hardshrink, - soft_shrink, is_floating_point, intopk, interpolate, diff --git a/mindspore/python/mindspore/ops/function/nn_func.py b/mindspore/python/mindspore/ops/function/nn_func.py index 204c34d4a4a..ac3c2d3e46d 100644 --- a/mindspore/python/mindspore/ops/function/nn_func.py +++ b/mindspore/python/mindspore/ops/function/nn_func.py @@ -2337,7 +2337,7 @@ def softmin(x, axis=-1): return softmax_(-x) -def soft_shrink(x, lambd=0.5): +def softshrink(x, lambd=0.5): r""" Applies the SoftShrink function element-wise. @@ -2370,7 +2370,7 @@ def soft_shrink(x, lambd=0.5): >>> from mindspore import ops >>> import numpy as np >>> x = Tensor(np.array([[ 0.5297, 0.7871, 1.1754], [ 0.7836, 0.6218, -1.1542]]), mindspore.float32) - >>> output = ops.soft_shrink(x) + >>> output = ops.softshrink(x) >>> print(output) [[ 0.02979 0.287 0.676 ] [ 0.2837 0.1216 -0.6543 ]] @@ -6104,7 +6104,6 @@ __all__ = [ 'pixel_shuffle', 'pixel_unshuffle', 'hardshrink', - 'soft_shrink', 'is_floating_point', 'flip', 'fliplr', diff --git a/mindspore/python/mindspore/ops/functional.py b/mindspore/python/mindspore/ops/functional.py index 096346c5766..3f83d4a2a62 100644 --- a/mindspore/python/mindspore/ops/functional.py +++ b/mindspore/python/mindspore/ops/functional.py @@ -233,7 +233,6 @@ tensor_operator_registry.register('invert', invert) tensor_operator_registry.register('hardshrink', P.HShrink) tensor_operator_registry.register('heaviside', heaviside) tensor_operator_registry.register('hypot', hypot) -tensor_operator_registry.register('soft_shrink', P.SoftShrink) tensor_operator_registry.register('svd', linalg_ops.Svd) tensor_operator_registry.register('diag', P.Diag) tensor_operator_registry.register('diagflat', diagflat) diff --git a/tests/st/ops/gpu/test_soft_shrink_op.py b/tests/st/ops/gpu/test_soft_shrink_op.py index 97c01f13c64..713eb059cea 100644 --- a/tests/st/ops/gpu/test_soft_shrink_op.py +++ b/tests/st/ops/gpu/test_soft_shrink_op.py @@ -76,26 +76,6 @@ def test_soft_shrink(dtype, data_shape, lambd): np.testing.assert_array_almost_equal(output.asnumpy(), benchmark_output) -@pytest.mark.level1 -@pytest.mark.platform_x86_gpu_training -@pytest.mark.env_onecard -def test_soft_shrink_tensor_check(): - """ - Feature: test_soft_shrink_tensor_check. - Description: test cases for tensor func - Expectation: raise TypeError. - """ - context.set_context(mode=context.PYNATIVE_MODE, device_target="GPU") - - in_np = np.random.rand(10).astype(np.float32) - in_tensor = Tensor(in_np) - - benchmark_output = soft_shrink_op_np_bencmark(in_tensor, 0.5) - output = in_tensor.soft_shrink() - - np.testing.assert_array_almost_equal(output.asnumpy(), benchmark_output) - - @pytest.mark.level1 @pytest.mark.platform_x86_gpu_training @pytest.mark.env_onecard @@ -110,7 +90,7 @@ def test_soft_shrink_functional_check(): in_np = np.random.rand(3, 5).astype(np.float32) in_tensor = Tensor(in_np) - output_ms = F.soft_shrink(in_tensor) + output_ms = F.softshrink(in_tensor) output_np = soft_shrink_op_np_bencmark(in_tensor, 0.5) np.testing.assert_allclose(output_ms.asnumpy(), output_np, rtol=1e-3)