Spaces:
Runtime error
Runtime error
Download lib/utils/data/mem.py from IsshikiHugh/HSMR: direct link, hf CLI and curl.
- Browser
- Download file 346 Bytes
-
https://huggingface.co/spaces/IsshikiHugh/HSMR/resolve/main/lib/utils/data/mem.py
- Command line
-
hf download hf://spaces/IsshikiHugh/HSMR/lib/utils/data/mem.py
-
curl -L -o mem.py https://huggingface.co/spaces/IsshikiHugh/HSMR/resolve/main/lib/utils/data/mem.py
346 Bytes
| import torch | |
| from typing import List, Dict, Tuple | |
| def recursive_detach(x): | |
| if isinstance(x, torch.Tensor): | |
| return x.detach() | |
| elif isinstance(x, Dict): | |
| return {k: recursive_detach(v) for k, v in x.items()} | |
| elif isinstance(x, (List, Tuple)): | |
| return [recursive_detach(v) for v in x] | |
| else: | |
| return x | |