MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / load

Method load

deepspeed/module_inject/auto_tp.py:162–198  ·  view source on GitHub ↗
(module, state_dict, prefix, mp_group=None)

Source from the content-addressed store, hash-verified

160 module._buffers[name].data.copy_(state_dict[prefix + name])
161
162 def load(module, state_dict, prefix, mp_group=None):
163 mp_replace = ReplaceWithTensorSlicing(mp_group=mp_group)
164 if hasattr(module, 'weight'):
165 if module.weight.data.is_meta:
166 # meta tensor cannot be casted or copied to, so we need to replace it with a normal tensor here
167 module.weight = torch.nn.parameter.Parameter(data=torch.empty_like(module.weight.data, device="cpu"),
168 requires_grad=module.weight.data.requires_grad)
169 if 'query_key_value' in prefix:
170 module.weight = mp_replace.strided_copy(module.weight.data,
171 state_dict[prefix + 'weight'],
172 num_splits=3)
173 else:
174 module.weight = mp_replace.copy(module.weight.data, state_dict[prefix + 'weight'])
175 else:
176 if hasattr(module, 'norm') and hasattr(module.norm, 'weight'):
177 if module.norm.weight.data.is_meta:
178 # meta tensor cannot be casted or copied to, so we need to replace it with a normal tensor here
179 module.norm.weight = torch.nn.parameter.Parameter(
180 data=torch.empty_like(module.norm.weight.data, device="cpu"),
181 requires_grad=module.norm.weight.data.requires_grad)
182 module.norm.weight = mp_replace.copy(module.norm.weight.data, state_dict[prefix + 'weight'])
183
184 if prefix + 'bias' in state_dict.keys():
185 if hasattr(module, 'bias'):
186 if module.bias.data.is_meta:
187 # meta tensor cannot be casted or copied to, so we need to replace it with a normal tensor here
188 module.bias = torch.nn.parameter.Parameter(data=torch.empty_like(module.bias.data, device="cpu"),
189 requires_grad=module.bias.data.requires_grad)
190 module.bias = mp_replace.copy(module.bias, state_dict[prefix + 'bias'])
191 else:
192 if hasattr(module, 'norm') and hasattr(module.norm, 'bias'):
193 if module.norm.bias.data.is_meta:
194 # meta tensor cannot be casted or copied to, so we need to replace it with a normal tensor here
195 module.norm.bias = torch.nn.parameter.Parameter(
196 data=torch.empty_like(module.norm.bias.data, device="cpu"),
197 requires_grad=module.norm.bias.data.requires_grad)
198 module.norm.bias = mp_replace.copy(module.norm.bias, state_dict[prefix + 'bias'])
199
200
201def _weight_ndim(weight):

Callers 15

init_inferenceFunction · 0.45
__init__Method · 0.45
parse_model_statesFunction · 0.45
parse_optim_statesFunction · 0.45
schedule_experimentsMethod · 0.45
parse_resultsMethod · 0.45
_get_user_configMethod · 0.45
_generate_experimentsMethod · 0.45
write_optimal_configMethod · 0.45

Calls 3

strided_copyMethod · 0.95
copyMethod · 0.95

Tested by

no test coverage detected