From 331fc76f3a8eccebe0c6a440e1f48cc20620a7ef Mon Sep 17 00:00:00 2001 From: Peilin Wang Date: Thu, 24 Dec 2020 13:34:14 -0500 Subject: [PATCH] SequenceMask doc fix and input check, update the description and example of applyftrl operator. --- mindspore/core/abstract/prim_arrays.cc | 4 ++++ mindspore/ops/composite/array_ops.py | 2 +- mindspore/ops/operations/nn_ops.py | 25 +++++++++++++++++++++---- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/mindspore/core/abstract/prim_arrays.cc b/mindspore/core/abstract/prim_arrays.cc index 858b8dfeae..8f65d3ba5f 100644 --- a/mindspore/core/abstract/prim_arrays.cc +++ b/mindspore/core/abstract/prim_arrays.cc @@ -886,6 +886,10 @@ AbstractBasePtr InferImplSequenceMask(const AnalysisEnginePtr &, const Primitive maxlen_value = *static_cast(maxlen_tensor->data_c()); } + if (maxlen_value <= 0) { + MS_LOG(EXCEPTION) << "maxlen must be positive, but got: " << maxlen_value; + } + ShapeVector lengths_shape = lengths->shape()->shape(); ShapeVector lengths_shape_min = lengths->shape()->min_shape(); if (lengths_shape_min.empty()) { diff --git a/mindspore/ops/composite/array_ops.py b/mindspore/ops/composite/array_ops.py index 05b78278ee..51921e061e 100644 --- a/mindspore/ops/composite/array_ops.py +++ b/mindspore/ops/composite/array_ops.py @@ -114,7 +114,7 @@ def sequence_mask(lengths, maxlen): Args: length (Tensor): Tensor to calculate the mask for. All values in this tensor must be - less than `maxlen`. Must be type int32 or int64. + less than or equal to `maxlen`. Must be type int32 or int64. maxlen (int): size of the last dimension of returned tensor. Must be positive and same type as elements in `lengths`. diff --git a/mindspore/ops/operations/nn_ops.py b/mindspore/ops/operations/nn_ops.py index 63b4851995..7a22394d97 100644 --- a/mindspore/ops/operations/nn_ops.py +++ b/mindspore/ops/operations/nn_ops.py @@ -5764,7 +5764,12 @@ class ApplyFtrl(PrimitiveWithInfer): Default: -0.5. It must be a float number or a scalar tensor with float16 or float32 data type. Outputs: - Tensor, represents the updated `var`. + There are three outputs for Ascend environment. + - **var** (Tensor) - represents the updated `var`. + - **accum** (Tensor) - represents the updated `accum`. + - **linear** (Tensor) - represents the updated `linear`. + There is only one output for GPU environment. + - **var** (Tensor) - This value is alwalys zero and the input parameters has been updated in-place. Supported Platforms: ``Ascend`` ``GPU`` @@ -5773,8 +5778,8 @@ class ApplyFtrl(PrimitiveWithInfer): >>> import mindspore >>> import mindspore.nn as nn >>> import numpy as np - >>> from mindspore import Parameter - >>> from mindspore import Tensor + >>> from mindspore import Parameter, Tensor + >>> import mindspore.context as context >>> from mindspore.ops import operations as ops >>> class ApplyFtrlNet(nn.Cell): ... def __init__(self): @@ -5797,7 +5802,9 @@ class ApplyFtrl(PrimitiveWithInfer): >>> net = ApplyFtrlNet() >>> input_x = Tensor(np.random.randint(-4, 4, (2, 2)), mindspore.float32) >>> output = net(input_x) - >>> print(output) + >>> is_tbe = context.get_context("device_target") == "Ascend" + >>> if is_tbe: + ... print(output) (Tensor(shape=[2, 2], dtype=Float32, value= [[ 4.61418092e-01, 5.30964255e-01], [ 2.68715084e-01, 3.82065028e-01]]), Tensor(shape=[2, 2], dtype=Float32, value= @@ -5805,6 +5812,16 @@ class ApplyFtrl(PrimitiveWithInfer): [ 1.43758726e+00, 9.89177322e+00]]), Tensor(shape=[2, 2], dtype=Float32, value= [[-1.86994812e+03, -1.64906018e+03], [-3.22187836e+02, -1.20163989e+03]])) + >>> else: + ... print(net.var.asnumpy()) + [[0.4614181 0.5309642 ] + [0.2687151 0.38206503]] + ... print(net.accum.asnumpy()) + [[16.423655 9.645894 ] + [ 1.4375873 9.891773 ]] + ... print(net.linear.asnumpy()) + [[-1869.9479 -1649.0599] + [ -322.1879 -1201.6399]] """ @prim_attr_register