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