Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -12,14 +12,25 @@ import re, torch, gradio as gr
|
|
12 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
13 |
from huggingface_hub import hf_hub_download
|
14 |
import spaces
|
15 |
-
import os
|
16 |
-
|
17 |
-
# ββββββββββββββββββ
|
18 |
-
if hasattr(torch, "compile"):
|
19 |
-
def _no_compile(model, *args, **
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
# (everything below is unchanged)
|
25 |
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
12 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
13 |
from huggingface_hub import hf_hub_download
|
14 |
import spaces
|
15 |
+
import os, types # add `types`
|
16 |
+
|
17 |
+
# ββββββββββββββββββ robust torch.compile shim βββββββββββββββββββββββββ
|
18 |
+
if hasattr(torch, "compile"):
|
19 |
+
def _no_compile(model: types.Any = None, *args, **kwargs):
|
20 |
+
"""
|
21 |
+
1. If called as torch.compile(model, β¦) β just return the model.
|
22 |
+
2. If called as torch.compile(**kw) β return a decorator that
|
23 |
+
immediately gives back the class / fn it decorates.
|
24 |
+
"""
|
25 |
+
if callable(model): # pattern 1
|
26 |
+
return model
|
27 |
+
# pattern 2 (used by ModernBERT via @torch.compile(...))
|
28 |
+
def decorator(fn):
|
29 |
+
return fn
|
30 |
+
return decorator
|
31 |
+
|
32 |
+
torch.compile = _no_compile # monkey-patch
|
33 |
+
os.environ["TORCHINDUCTOR_DISABLED"] = "1"
|
34 |
|
35 |
# (everything below is unchanged)
|
36 |
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|