!49870 update ops supporting tags

Merge pull request !49870 from 李林杰/code_docs_update_supporting_tags_for_some_ops_master
This commit is contained in:
i-robot 2023-03-07 07:46:30 +00:00 committed by Gitee
commit 0b6120b2ea
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 72 additions and 31 deletions

View File

@ -0,0 +1,41 @@
mindspore.nn.MultilabelMarginLoss
======================================
.. py:class:: mindspore.nn.MultilabelMarginLoss(reduction="mean")
创建一个损失函数,用于最小化多分类任务的基于边际的损失。
它以一个2D mini-batch Tensor :math:`x` 作为输入以包含目标类索引的2D Tensor :math:`y` 作为输出。
对于每个小批量样本loss值根据如下公式计算
.. math::
\text{loss}(x, y) = \sum_{ij}\frac{\max(0, 1 - (x[y[j]] - x[i]))}{\text{x.size}(0)}
其中 :math:`x \in \left\{0, \; \cdots , \; \text{x.size}(0) - 1\right\}`, \
:math:`y \in \left\{0, \; \cdots , \; \text{y.size}(0) - 1\right\}`, \
:math:`0 \leq y[j] \leq \text{x.size}(0)-1`, \
并且 :math:`i \neq y[j]` 对于所有 :math:`i` and :math:`j`
:math:`y`:math:`x` shape必须相同。
.. note::
该算子仅考虑从前方开始的连续非负目标块。这允许不同的样本具有不同数量的目标类别。
参数:
- **reduction** (str可选) - 指定应用于输出结果的规约计算方式。取值为"mean""sum",或"none"。默认值:"mean"。
输入:
- **x** (Tensor) - 预测值。hape为 :math:`(C)`:math:`(N, C)`,其中 :math:`N`
为批量大小,:math:`C` 为类别数。数据类型必须为float16或float32。
- **target** (Tensor) - 目标值shape与 `inputs` 相同数据类型必须为int32标签目标由-1填充。
输出:
- **y** (Union[Tensor, Scalar]) - MultilabelMarginLoss损失。如果 `reduction` 的值为 "none"
那么返回shape为 :math:`(N)` 的Tensor类型数据。否则返回一个标量。
异常:
- **TypeError** - 当 `inputs` 或者 `target` 数据不是Tensor时。
- **TypeError** - 当 `inputs` 数据类型不是以下其中之一时float16、float32。
- **TypeError** - 当 `target` 数据类型不是int32时。
- **ValueError** - 当 `inputs` 的数据维度不是以下其中之一时1、2。
- **ValueError** - 当 `inputs``target` 的shape不相同时。
- **ValueError** - 当 `reduction` 的值不是以下其中之一时:'none'、 'mean'、 'sum'。

View File

@ -278,7 +278,7 @@ class MaxPool3d(Cell):
ValueError: If `padding` is less than 0.
Supported Platforms:
``GPU``
``Ascend`` ``GPU`` ``CPU``
Examples:
>>> import mindspore as ms

View File

@ -1519,12 +1519,12 @@ class CosineEmbeddingLoss(LossBase):
class MultilabelMarginLoss(LossBase):
r"""
MultilabelMarginLoss operation.
Creates a loss criterion that minimizes a margin-based loss for multi-class
classification tasks.
It takes a 2D mini-batch Tensor :math:`x` as input and a 2D
Tensor :math:`y` containing target class indices as output.
Creates a criterion that optimizes a multi-class multi-classification
hinge loss (margin-based loss) between input :math:`x` (a 2D mini-batch `Tensor`)
and output :math:`y` (which is a 2D `Tensor` of target class indices).
For each sample in the mini-batch:
Each sample in the mini-batch, the loss is computed as follows:
.. math::
\text{loss}(x, y) = \sum_{ij}\frac{\max(0, 1 - (x[y[j]] - x[i]))}{\text{x.size}(0)}
@ -1532,17 +1532,18 @@ class MultilabelMarginLoss(LossBase):
where :math:`x \in \left\{0, \; \cdots , \; \text{x.size}(0) - 1\right\}`, \
:math:`y \in \left\{0, \; \cdots , \; \text{y.size}(0) - 1\right\}`, \
:math:`0 \leq y[j] \leq \text{x.size}(0)-1`, \
and :math:`i \neq y[j]` for all :math:`i` and :math:`j`.
and for all :math:`i` and :math:`j`, :math:`i` does not equal to :math:`y[j]`.
:math:`y` and :math:`x` must have the same size.
Furthermore, both :math:`y` and :math:`x` should have identical sizes.
The criterion only considers a contiguous block of non-negative targets that
starts at the front.
This allows for different samples to have variable amounts of target classes.
.. note::
For this operator, only a contiguous sequence of non-negative targets that starts at
the beginning is taken into consideration, which means that different samples can have different
number of target classes.
Args:
reduction (str): Apply specific reduction method to the output: 'none', 'mean', 'sum'. Default: "mean".
reduction (str, optional): Apply specific reduction method to the output: 'none', 'mean', 'sum'.
Default: "mean".
Inputs:
- **x** (Tensor) - Predict data. Tensor of shape :math:`(C)` or :math:`(N, C)`, where :math:`N`
@ -1554,7 +1555,6 @@ class MultilabelMarginLoss(LossBase):
- **y** (Union[Tensor, Scalar]) - The loss of MultilabelMarginLoss. If `reduction` is "none", its shape
is :math:`(N)`. Otherwise, a scalar value will be returned.
Raises:
TypeError: If `x` or `target` is not a Tensor.
TypeError: If dtype of `x` is neither float16 nor float32.

View File

@ -1289,7 +1289,7 @@ def searchsorted(sorted_sequence, values, *, out_int32=False, right=False):
`sorted_sequence` and `values` are different.
Supported Platforms:
``CPU``
``Ascend`` ``GPU`` ``CPU``
Examples:
>>> sorted_sequence = Tensor(np.array([[0, 1, 3, 5, 7], [2, 4, 6, 8, 10]]), mindspore.float32)
@ -4232,7 +4232,7 @@ def affine_grid(theta, output_size, align_corners=False):
ValueError: If the output_size[0] is not equal to the shape[0] of theta.
Supported Platforms:
``GPU``
``Ascend`` ``GPU`` ``CPU``
Examples:
>>> import mindspore
@ -4459,7 +4459,7 @@ def unsorted_segment_prod(x, segment_ids, num_segments):
ValueError: If length of shape of `segment_ids` is not equal to 1.
Supported Platforms:
``Ascend`` ``GPU``
``Ascend`` ``GPU`` ``CPU``
Examples:
>>> from mindspore import Tensor
@ -4509,7 +4509,7 @@ def index_fill(x, axis, index, value):
RuntimeError: If the values of `index` are out the range of `[-x.shape[axis], x.shape[axis]-1]`.
Supported Platforms:
``GPU``
``Ascend`` ``GPU`` ``CPU``
Examples:
>>> import mindspore
@ -5168,7 +5168,7 @@ def tril(input_x, diagonal=0): # pylint: disable=redefined-outer-name
ValueError: If the rank of `x` is less than 2.
Supported Platforms:
``GPU`` ``CPU``
``Ascend`` ``GPU`` ``CPU``
Examples:
>>> x = Tensor(np.array([[ 1, 2, 3, 4],
@ -6214,7 +6214,7 @@ def mvlgamma(input, p):
ValueError: If not all elements of `input` are greater than :math:`(p - 1) / 2`.
Supported Platforms:
``GPU`` ``CPU``
``Ascend`` ``GPU`` ``CPU``
Examples:
>>> x = Tensor(np.array([[3, 4, 5], [4, 2, 6]]), mindspore.float32)

View File

@ -4424,7 +4424,7 @@ def orgqr(x, tau):
ValueError: If rank(x) != 2 or 3.
Supported Platforms:
``Ascend`` ``CPU``
``Ascend`` ``GPU`` ``CPU``
Examples:
>>> x = Tensor(np.array([[-114.6, 10.9, 1.1], [-0.304, 38.07, 69.38], [-0.45, -0.17, 62.]]), mindspore.float32)
@ -4502,7 +4502,7 @@ def heaviside(x, values):
ValueError: If shape of two inputs are not broadcastable.
Supported Platforms:
``GPU`` ``CPU``
``Ascend`` ``GPU`` ``CPU``
Examples:
>>> x = Tensor(np.array([-5., 1., 0., 2., 0.]))
@ -8565,7 +8565,7 @@ def roll(x, shifts, dims=None):
TypeError: If `dims` is not an int, a tuple or a list.
Supported Platforms:
``GPU``
``Ascend`` ``GPU``
Examples:
>>> import numpy as np
@ -9886,7 +9886,7 @@ def isinf(input):
TypeError: If `input` is not a Tensor.
Supported Platforms:
``GPU`` ``CPU``
``Ascend`` ``GPU`` ``CPU``
Examples:
>>> x = Tensor(np.array([np.log(-1), 1, np.log(0)]), mindspore.float32)

View File

@ -2914,7 +2914,7 @@ def prelu(x, weight):
ValueError: If the `weight` is not a 1-D Tensor.
Supported Platforms:
``Ascend`` ``GPU``
``Ascend`` ``GPU`` ``CPU``
Examples:
>>> x = Tensor(np.arange(-6, 6).reshape((2, 3, 2)), mindspore.float32)
@ -3854,7 +3854,7 @@ def max_pool3d(x, kernel_size, stride=None, padding=0, dilation=1, ceil_mode=Fal
ValueError: If `padding` is less than 0.
Supported Platforms:
``GPU``
``Ascend`` ``GPU`` ``CPU``
Examples:
>>> x = Tensor(np.arange(2 * 1 * 2 * 2 * 2).reshape((2, 1, 2, 2, 2)), mindspore.float32)
@ -5251,7 +5251,7 @@ def multilabel_margin_loss(inputs, target, reduction='mean'):
ValueError: If `reduction` is not one of 'none', 'mean', 'sum'.
Supported Platforms:
``Ascend``
``Ascend`` ``GPU``
Examples:
>>> inputs = Tensor(np.array([[0.1, 0.2, 0.4, 0.8], [0.2, 0.3, 0.5, 0.7]]), mindspore.float32)

View File

@ -1222,7 +1222,7 @@ def multinomial(inputs, num_sample, replacement=True, seed=None):
TypeError: If `seed` is neither an int nor an optional.
Supported Platforms:
``GPU``
``Ascend`` ``GPU`` ``CPU``
Examples:
>>> import mindspore

View File

@ -151,7 +151,7 @@ class AdaptiveAvgPool3D(Primitive):
Refer to :func:`mindspore.ops.adaptive_avg_pool3d` for more details.
Supported Platforms:
``GPU`` ``CPU``
``Ascend`` ``GPU`` ``CPU``
Examples:
>>> import mindspore
@ -2457,7 +2457,7 @@ class MaxPool3DWithArgmax(Primitive):
ValueError: If `argmax_type` is not mindspore.int64 or mindspore.int32.
Supported Platforms:
``GPU``
``Ascend`` ``GPU`` ``CPU``
Examples:
>>> x = Tensor(np.arange(2 * 1 * 2 * 2 * 2).reshape((2, 1, 2, 2, 2)), mindspore.float32)
@ -9413,7 +9413,7 @@ class TripletMarginLoss(Primitive):
ValueError: If `reduction` is not one of 'none', 'mean', 'sum'.
Supported Platforms:
``Ascend`` ``GPU`` ``CPU``
``GPU``
Examples:
>>> loss = ops.TripletMarginLoss()