Sleepyriizi commited on
Commit
decced4
Β·
verified Β·
1 Parent(s): 65cb2f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -8
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 # NEW
16
-
17
- # ────────────────── hot-patch torch.compile ────────────────────────────
18
- if hasattr(torch, "compile"): # NEW
19
- def _no_compile(model, *args, **kw): # NEW
20
- return model # NEW
21
- torch.compile = _no_compile # NEW
22
- os.environ["TORCHINDUCTOR_DISABLED"] = "1" # NEW
 
 
 
 
 
 
 
 
 
 
 
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")