MCPcopy Create free account
hub / github.com/AIS-SNU/Smart-Infinity / load

Method load

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

Source from the content-addressed store, hash-verified

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

Callers 1

_load_checkpointMethod · 0.45

Calls 4

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

Tested by

no test coverage detected