|
|
|
@ -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__ = {}
|
|
|
|
|
|
|
|
|
|