Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,20 +39,39 @@ import shutil
|
|
| 39 |
|
| 40 |
import spaces
|
| 41 |
import torch
|
|
|
|
| 42 |
torch._dynamo.config.suppress_errors = True
|
| 43 |
torch._dynamo.config.disable = True
|
| 44 |
|
| 45 |
_original_tensor_to = torch.Tensor.to
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
return _original_tensor_to(self, *args, **kwargs)
|
| 54 |
|
| 55 |
-
|
|
|
|
| 56 |
|
| 57 |
import gradio as gr
|
| 58 |
import numpy as np
|
|
|
|
| 39 |
|
| 40 |
import spaces
|
| 41 |
import torch
|
| 42 |
+
|
| 43 |
torch._dynamo.config.suppress_errors = True
|
| 44 |
torch._dynamo.config.disable = True
|
| 45 |
|
| 46 |
_original_tensor_to = torch.Tensor.to
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def _is_cuda_target(x):
|
| 50 |
+
return (
|
| 51 |
+
x == "cuda"
|
| 52 |
+
or (isinstance(x, torch.device) and x.type == "cuda")
|
| 53 |
+
or (isinstance(x, str) and x.startswith("cuda"))
|
| 54 |
+
or (isinstance(x, int) and x == 0)
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def _spaces_safe_to(self, *args, **kwargs):
|
| 59 |
+
"""ZeroGPU emulates bare .to('cuda'), but LTX-2 uses non_blocking/copy."""
|
| 60 |
+
if args and _is_cuda_target(args[0]):
|
| 61 |
+
# keep dtype if it was passed positionally after the device
|
| 62 |
+
new_args = ("cuda",) + args[1:]
|
| 63 |
+
new_kwargs = {k: v for k, v in kwargs.items() if k not in ("non_blocking", "copy")}
|
| 64 |
+
return _original_tensor_to(self, *new_args, **new_kwargs)
|
| 65 |
+
|
| 66 |
+
if kwargs.get("device") is not None and _is_cuda_target(kwargs["device"]):
|
| 67 |
+
new_kwargs = {k: v for k, v in kwargs.items() if k not in ("non_blocking", "copy")}
|
| 68 |
+
new_kwargs["device"] = "cuda"
|
| 69 |
+
return _original_tensor_to(self, *args, **new_kwargs)
|
| 70 |
+
|
| 71 |
return _original_tensor_to(self, *args, **kwargs)
|
| 72 |
|
| 73 |
+
|
| 74 |
+
torch.Tensor.to = _spaces_safe_to
|
| 75 |
|
| 76 |
import gradio as gr
|
| 77 |
import numpy as np
|