MCPcopy Create free account
hub / github.com/zai-org/CodeGeeX / clone_param32

Method clone_param32

codegeex/mindspore/src/adam.py:182–210  ·  view source on GitHub ↗

Clone the parameters in ParameterTuple element-wisely to generate a new ParameterTuple with float32 data type. Inputs: prefix (str): The prefix name of the parameters. init (Union[Tensor, str, numbers.Number]): Initialize the shape and dtype of the parameters

(self, prefix, init=None)

Source from the content-addressed store, hash-verified

180 return optim_result
181
182 def clone_param32(self, prefix, init=None):
183 """
184 Clone the parameters in ParameterTuple element-wisely to generate a new ParameterTuple with float32 data type.
185 Inputs:
186 prefix (str): The prefix name of the parameters.
187 init (Union[Tensor, str, numbers.Number]): Initialize the shape and dtype of the parameters.
188 The definition of `init` is the same as in `Parameter` API. If `init` is 'same', the
189 parameters in the new parameter tuple are the same as those in the original parameter tuple.
190 Default: 'same'.
191 Returns:
192 Tuple, the new Parameter tuple.
193 """
194 new = []
195 for old_param in self.parameters:
196 param_init = init
197 if init is None:
198 param_init = old_param.init
199 new_state = Parameter(initializer(param_init, shape=old_param.shape, dtype=mstype.float32))
200 new_state.param_info = old_param.param_info.clone()
201 new_state.is_init = False
202 new_state.is_param_ps = old_param.is_param_ps
203 new_state.init_in_server = old_param.init_in_server
204 new_state.cache_enable = old_param.cache_enable
205 new_state.requires_aggr = old_param.requires_aggr
206 if old_param.cache_shape:
207 new_state.cache_shape = old_param.cache_shape
208 new_state.name = prefix + '.' + new_state.name
209 new.append(new_state)
210 return ParameterTuple(new)

Callers 1

__init__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected