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

Method load

deepspeed/inference/engine.py:339–376  ·  view source on GitHub ↗
(module, state_dict, prefix)

Source from the content-addressed store, hash-verified

337 error_msgs = []
338
339 def load(module, state_dict, prefix):
340 args = (state_dict, prefix, {}, True, [], [], error_msgs)
341 if hasattr(module, 'weight'):
342 if module.weight.data.is_meta:
343 # meta tensor cannot be casted or copied to, so we need to replace it with a normal tensor here
344 module.weight = torch.nn.parameter.Parameter(data=torch.empty_like(module.weight.data,
345 device="cpu"),
346 requires_grad=module.weight.data.requires_grad)
347 if 'query_key_value' in prefix:
348 module.weight = self.mp_replace.strided_copy(module.weight.data,
349 state_dict[prefix + 'weight'],
350 num_splits=3)
351 else:
352 module.weight = self.mp_replace.copy(module.weight.data, state_dict[prefix + 'weight'])
353 else:
354 if module.norm.weight.data.is_meta:
355 # meta tensor cannot be casted or copied to, so we need to replace it with a normal tensor here
356 module.norm.weight = torch.nn.parameter.Parameter(
357 data=torch.empty_like(module.norm.weight.data, device="cpu"),
358 requires_grad=module.norm.weight.data.requires_grad)
359 module.norm.weight = self.mp_replace.copy(module.norm.weight.data, state_dict[prefix + 'weight'])
360 if prefix + 'bias' in self.key_list:
361 if hasattr(module, 'norm'):
362 if module.norm.bias.data.is_meta:
363 # meta tensor cannot be casted or copied to, so we need to replace it with a normal tensor here
364 module.norm.bias = torch.nn.parameter.Parameter(
365 data=torch.empty_like(module.norm.bias.data, device="cpu"),
366 requires_grad=module.norm.bias.data.requires_grad)
367 module.norm.bias = self.mp_replace.copy(module.norm.bias, state_dict[prefix + 'bias'])
368 else:
369 if module.bias.data.is_meta:
370 # meta tensor cannot be casted or copied to, so we need to replace it with a normal tensor here
371 module.bias = torch.nn.parameter.Parameter(data=torch.empty_like(module.bias.data,
372 device="cpu"),
373 requires_grad=module.bias.data.requires_grad)
374 data = state_dict[prefix + 'bias']
375 data = data.to(get_accelerator().current_device_name())
376 module.bias = self.mp_replace.copy(module.bias, data)
377
378 layer_policies = {
379 nn.Linear: load,

Callers 15

__init__Method · 0.45
_load_checkpointMethod · 0.45
get_quantizer_moduleFunction · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45

Calls 5

get_acceleratorFunction · 0.90
strided_copyMethod · 0.80
copyMethod · 0.45
toMethod · 0.45
current_device_nameMethod · 0.45

Tested by

no test coverage detected