Download src/lost_found_desk/runtime/gpu.py from build-small-hackathon/lost-found-desk: direct link, hf CLI and curl.
- Browser
- Download file 946 Bytes
-
https://huggingface.co/spaces/build-small-hackathon/lost-found-desk/resolve/main/src/lost_found_desk/runtime/gpu.py
- Command line
-
hf download hf://spaces/build-small-hackathon/lost-found-desk/src/lost_found_desk/runtime/gpu.py
-
curl -L -o gpu.py https://huggingface.co/spaces/build-small-hackathon/lost-found-desk/resolve/main/src/lost_found_desk/runtime/gpu.py
946 Bytes
| from __future__ import annotations | |
| from typing import Callable, TypeVar | |
| F = TypeVar("F", bound=Callable) | |
| try: | |
| import spaces as _spaces # type: ignore | |
| except ImportError: # pragma: no cover - local installs normally include spaces | |
| _spaces = None | |
| def maybe_zerogpu(duration: int = 60, size: str | None = None): | |
| """Return the official @spaces.GPU decorator when the package is present. | |
| The `spaces` package decides whether the current runtime is ZeroGPU from | |
| Hugging Face's `SPACES_ZERO_GPU` environment variable. Outside ZeroGPU it | |
| returns the original function unchanged, so local CUDA/MPS/CPU runs keep the | |
| same call path while HF startup can still discover GPU-decorated functions. | |
| """ | |
| if _spaces is None: | |
| def identity(fn: F) -> F: | |
| return fn | |
| return identity | |
| kwargs = {"duration": duration} | |
| if size: | |
| kwargs["size"] = size | |
| return _spaces.GPU(**kwargs) | |