334 Star 1.5K Fork 864

MindSpore / docs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
assign_sub.md 2.19 KB
一键复制 编辑 原始数据 按行查看 历史
luojianing 提交于 2023-07-21 15:16 . replace target=blank

Function Differences with tf.compat.v1.assign_sub

View Source On Gitee

tf.compat.v1.assign_sub

tf.compat.v1.assign_sub(ref, value, use_locking=None, name=None) -> Tensor

For more information, see tf.compat.v1.assign_sub.

mindspore.ops.assign_sub

mindspore.ops.assign_sub(variable, value)-> Tensor

For more information, see mindspore.ops.assign_sub.

Differences

TensorFlow: Update the network parameters by subtracting a specific value from the network parameters, and return a Tensor with the same type as ref.

MindSpore: MindSpore API implements the same functions as TensorFlow, with some different parameter names.

Categories Subcategories TensorFlow MindSpore Differences
Parameters Parameter 1 ref variable Same function, different parameter names
Parameter 2 value value -
Parameter 3 use_locking - In TensorFlow, whether to use locks in update operations. Default value: False.
Parameter 4 name - Not involved

Code Example 1

The outputs of MindSpore and TensorFlow are consistent.

# TensorFlow
import tensorflow as tf
import numpy as np

variable = tf.Variable(np.array([[2.4, 1], [0.1, 6]]), dtype=tf.float32)
value = tf.constant(np.array([[-2, 3], [3.6, 1]]), dtype=tf.float32)
out = tf.compat.v1.assign_sub(variable, value)
print(out.numpy())
# [[ 4.4 -2. ]
#  [-3.5  5. ]]

# MindSpore
import mindspore
import numpy as np
from mindspore.ops import function as ops
from mindspore import Tensor

variable = Tensor(np.array([[2.4, 1], [0.1, 6]]), mindspore.float32)
value = Tensor(np.array([[-2, 3], [3.6, 1]]), mindspore.float32)
out = ops.assign_sub(variable, value)
print(out)
# [[ 4.4 -2. ]
#  [-3.5  5. ]]
1
https://gitee.com/mindspore/docs.git
git@gitee.com:mindspore/docs.git
mindspore
docs
docs
r2.0

搜索帮助