提交 b63b6bed 编写于 作者: M mindspore-ci-bot 提交者: Gitee

!4649 parameter add example

Merge pull request !4649 from yepei6/comment
......@@ -54,6 +54,33 @@ class Parameter(MetaTensor):
requires_grad (bool): True if the parameter requires gradient. Default: True.
layerwise_parallel (bool): A kind of model parallel mode. When layerwise_parallel is true in paralle mode,
broadcast and gradients communication would not be applied to parameters. Default: False.
Example:
>>> from mindspore import Parameter, Tensor
>>> from mindspore.common import initializer as init
>>> from mindspore.ops import operations as P
>>> from mindspore.nn import Cell
>>> import mindspore
>>> import numpy as np
>>> from mindspore import context
>>>
>>> class Net(Cell):
>>> def __init__(self):
>>> super(Net, self).__init__()
>>> self.matmul = P.MatMul()
>>> self.weight = Parameter(Tensor(np.ones((1,2))), name="w", requires_grad=True)
>>>
>>> def construct(self, x):
>>> out = self.matmul(self.weight, x)
>>> return out
>>> context.set_context(mode=context.GRAPH_MODE, device_target="CPU")
>>> net = Net()
>>> x = Tensor(np.ones((2,1)))
>>> net(x)
[[2.]]
>>> net.weight.set_parameter_data(Tensor(np.zeros((1,2))))
>>> net(x)
[[0.]]
"""
__base_type__ = {}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册