Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -42,6 +42,18 @@ import torch
|
|
| 42 |
torch._dynamo.config.suppress_errors = True
|
| 43 |
torch._dynamo.config.disable = True
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
import gradio as gr
|
| 46 |
import numpy as np
|
| 47 |
from huggingface_hub import hf_hub_download, snapshot_download
|
|
|
|
| 42 |
torch._dynamo.config.suppress_errors = True
|
| 43 |
torch._dynamo.config.disable = True
|
| 44 |
|
| 45 |
+
_original_tensor_to = torch.Tensor.to
|
| 46 |
+
def _coerce_cuda_str(self, *args, **kwargs):
|
| 47 |
+
if args and isinstance(args[0], torch.device) and args[0].type == "cuda":
|
| 48 |
+
args = ("cuda", *args[1:])
|
| 49 |
+
if kwargs.get("device") is not None:
|
| 50 |
+
dev = kwargs["device"]
|
| 51 |
+
if isinstance(dev, torch.device) and dev.type == "cuda":
|
| 52 |
+
kwargs = {**kwargs, "device": "cuda"}
|
| 53 |
+
return _original_tensor_to(self, *args, **kwargs)
|
| 54 |
+
|
| 55 |
+
torch.Tensor.to = _coerce_cuda_str
|
| 56 |
+
|
| 57 |
import gradio as gr
|
| 58 |
import numpy as np
|
| 59 |
from huggingface_hub import hf_hub_download, snapshot_download
|