Spaces:
Running on Zero
Running on Zero
Download musubi_tuner/utils/device_utils.py from hugging-apps/streaming-code-world-model: direct link, hf CLI and curl.
- Browser
- Download file 781 Bytes
-
https://huggingface.co/spaces/hugging-apps/streaming-code-world-model/resolve/main/musubi_tuner/utils/device_utils.py
- Command line
-
hf download hf://spaces/hugging-apps/streaming-code-world-model/musubi_tuner/utils/device_utils.py
-
curl -L -o device_utils.py https://huggingface.co/spaces/hugging-apps/streaming-code-world-model/resolve/main/musubi_tuner/utils/device_utils.py
781 Bytes
| from typing import Optional, Union | |
| import torch | |
| def clean_memory_on_device(device: Optional[Union[str, torch.device]]): | |
| if device is None: | |
| return | |
| if isinstance(device, str): | |
| device = torch.device(device) | |
| if device.type == "cuda": | |
| torch.cuda.empty_cache() | |
| elif device.type == "cpu": | |
| pass | |
| elif device.type == "mps": # not tested | |
| torch.mps.empty_cache() | |
| def synchronize_device(device: Optional[Union[str, torch.device]]): | |
| if device is None: | |
| return | |
| if isinstance(device, str): | |
| device = torch.device(device) | |
| if device.type == "cuda": | |
| torch.cuda.synchronize() | |
| elif device.type == "xpu": | |
| torch.xpu.synchronize() | |
| elif device.type == "mps": | |
| torch.mps.synchronize() | |