mindspore/docs/api/api_python/nn/mindspore.nn.TrainOneStepCe...

25 lines
1.2 KiB
ReStructuredText
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

mindspore.nn.TrainOneStepCell
=============================
.. py:class:: mindspore.nn.TrainOneStepCell(network, optimizer, sens=None, return_grad=False)
训练网络封装类。
封装 `network``optimizer` 。构建一个输入'\*inputs'的用于训练的Cell。
执行函数 `construct` 中会构建反向图以更新网络参数。支持不同的并行训练模式。
参数:
- **network** (Cell) - 训练网络。只支持单输出网络。
- **optimizer** (Union[Cell]) - 用于更新网络参数的优化器。
- **sens** (numbers.Number可选) - 反向传播的输入,缩放系数。默认值: ``None`` ,即取系数为 ``1.0``
- **return_grad** (bool可选) - 是否返回梯度。若为 ``True`` 则会在返回损失函数值loss的同时以字典的形式返回梯度字典的key为梯度对应的参数名value为梯度值。默认值 ``False``
输入:
- **\*inputs** (Tuple(Tensor)) - shape为 :math:`(N, \ldots)` 的Tensor组成的tuple。
输出:
Tensor损失函数值loss其shape通常为 :math:`()`
异常:
- **TypeError** - `sens` 不是numbers.Number。