(module, state_dict, prefix)
| 306 | error_msgs = [] |
| 307 | |
| 308 | def load(module, state_dict, prefix): |
| 309 | args = (state_dict, prefix, {}, True, [], [], error_msgs) |
| 310 | if hasattr(module, 'weight'): |
| 311 | if module.weight.data.is_meta: |
| 312 | # meta tensor cannot be casted or copied to, so we need to replace it with a normal tensor here |
| 313 | module.weight = torch.nn.parameter.Parameter(data=torch.empty_like(module.weight.data, |
| 314 | device="cpu"), |
| 315 | requires_grad=module.weight.data.requires_grad) |
| 316 | if 'query_key_value' in prefix: |
| 317 | module.weight = self.mp_replace.strided_copy(module.weight.data, |
| 318 | state_dict[prefix + 'weight'], |
| 319 | num_splits=3) |
| 320 | else: |
| 321 | module.weight = self.mp_replace.copy(module.weight.data, state_dict[prefix + 'weight']) |
| 322 | else: |
| 323 | if module.norm.weight.data.is_meta: |
| 324 | # meta tensor cannot be casted or copied to, so we need to replace it with a normal tensor here |
| 325 | module.norm.weight = torch.nn.parameter.Parameter( |
| 326 | data=torch.empty_like(module.norm.weight.data, device="cpu"), |
| 327 | requires_grad=module.norm.weight.data.requires_grad) |
| 328 | module.norm.weight = self.mp_replace.copy(module.norm.weight.data, state_dict[prefix + 'weight']) |
| 329 | if prefix + 'bias' in self.key_list: |
| 330 | if hasattr(module, 'norm'): |
| 331 | if module.norm.bias.data.is_meta: |
| 332 | # meta tensor cannot be casted or copied to, so we need to replace it with a normal tensor here |
| 333 | module.norm.bias = torch.nn.parameter.Parameter( |
| 334 | data=torch.empty_like(module.norm.bias.data, device="cpu"), |
| 335 | requires_grad=module.norm.bias.data.requires_grad) |
| 336 | module.norm.bias = self.mp_replace.copy(module.norm.bias, state_dict[prefix + 'bias']) |
| 337 | else: |
| 338 | if module.bias.data.is_meta: |
| 339 | # meta tensor cannot be casted or copied to, so we need to replace it with a normal tensor here |
| 340 | module.bias = torch.nn.parameter.Parameter(data=torch.empty_like(module.bias.data, |
| 341 | device="cpu"), |
| 342 | requires_grad=module.bias.data.requires_grad) |
| 343 | data = state_dict[prefix + 'bias'] |
| 344 | data = data.to(get_accelerator().current_device_name()) |
| 345 | module.bias = self.mp_replace.copy(module.bias, data) |
| 346 | |
| 347 | layer_policies = { |
| 348 | nn.Linear: load, |
no test coverage detected