Spaces:
Runtime error
Runtime error
Missing code
Browse files- optimization_utils.py +7 -1
optimization_utils.py
CHANGED
|
@@ -135,4 +135,10 @@ def capture_component_call(
|
|
| 135 |
captured_call.kwargs = e.kwargs
|
| 136 |
|
| 137 |
|
| 138 |
-
def drain_module_parameters(module: torch.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
captured_call.kwargs = e.kwargs
|
| 136 |
|
| 137 |
|
| 138 |
+
def drain_module_parameters(module: torch.nn.Module):
|
| 139 |
+
state_dict_meta = {name: {'device': tensor.device, 'dtype': tensor.dtype} for name, tensor in module.state_dict().items()}
|
| 140 |
+
state_dict = {name: torch.nn.Parameter(torch.empty_like(tensor, device='cpu')) for name, tensor in module.state_dict().items()}
|
| 141 |
+
module.load_state_dict(state_dict, assign=True)
|
| 142 |
+
for name, param in state_dict.items():
|
| 143 |
+
meta = state_dict_meta[name]
|
| 144 |
+
param.data = torch.Tensor([]).to(**meta)
|