File size: 521 Bytes
7c19e41
 
 
 
 
 
 
e164e80
7c19e41
 
 
 
 
 
 
 
 
e164e80
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"""ZeroGPU shim. On a ZeroGPU Space `gpu` is `spaces.GPU`; anywhere else it is a no-op,
so the same code runs locally and on-prem. Import this module BEFORE torch."""
try:
    import spaces  # type: ignore

    gpu = spaces.GPU
    ON_ZERO_GPU = True
except Exception:  # not on HF, or `spaces` not installed
    ON_ZERO_GPU = False

    def gpu(*args, **kwargs):
        if len(args) == 1 and callable(args[0]) and not kwargs:
            return args[0]

        def deco(fn):
            return fn

        return deco