| 63 | self.state = 1 |
| 64 | |
| 65 | def forward(self, x, *args, **kwargs): |
| 66 | if self.onload_dtype == self.computation_dtype and self.onload_device == self.computation_device: |
| 67 | weight, bias = self.weight, self.bias |
| 68 | else: |
| 69 | weight = cast_to(self.weight, self.computation_dtype, self.computation_device) |
| 70 | bias = None if self.bias is None else cast_to(self.bias, self.computation_dtype, self.computation_device) |
| 71 | return torch.nn.functional.linear(x, weight, bias) |
| 72 | |
| 73 | |
| 74 | def enable_vram_management_recursively(model: torch.nn.Module, module_map: dict, module_config: dict, max_num_param=None, overflow_module_config: dict = None, total_num_param=0): |