bhardwaj08sarthak commited on
Commit
355f5f7
·
verified ·
1 Parent(s): 4dd6ca5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -7
app.py CHANGED
@@ -1,17 +1,40 @@
1
- # --- MUST be first: disable Hugging Face Spaces ZeroGPU monkey-patch ---
2
- import os
 
 
3
  os.environ["SPACES_ZERO_DISABLED"] = "1"
4
 
5
- # (optional but helpful) steer PyTorch to math attention kernels (no Flash/MemEfficient)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  try:
7
  import torch
8
  torch.backends.cuda.sdp_kernel(enable_math=True, enable_flash=False, enable_mem_efficient=False)
9
  except Exception:
10
  pass
11
-
12
- # If you truly need Spaces, import it AFTER disabling the patch.
13
- import spaces
14
-
15
  import sys
16
  from huggingface_hub import hf_hub_download
17
  import pickle
 
1
+
2
+ import os, sys, importlib
3
+
4
+ # Disable Spaces ZeroGPU by env and by calling its disable/unpatch if preloaded
5
  os.environ["SPACES_ZERO_DISABLED"] = "1"
6
 
7
+ def _hard_disable_spaces_zero():
8
+ # Hit common modules and try disable/unpatch/deactivate if present
9
+ candidates = [
10
+ "spaces.zero", "spaces.zero.torch.patching", "spaces.zero.torch",
11
+ "spaces.zero.patch", "spaces.zero.patching"
12
+ ]
13
+ for modname in candidates:
14
+ try:
15
+ m = sys.modules.get(modname) or importlib.import_module(modname)
16
+ except Exception:
17
+ continue
18
+ for attr in ("disable", "unpatch", "deactivate"):
19
+ fn = getattr(m, attr, None)
20
+ if callable(fn):
21
+ try:
22
+ fn()
23
+ except Exception:
24
+ pass
25
+
26
+ _hard_disable_spaces_zero()
27
+
28
+ # Force Transformers to use eager attention globally (affects all future loads)
29
+ os.environ["TRANSFORMERS_ATTENTION_IMPLEMENTATION"] = "eager"
30
+
31
+ # Prefer simple math SDP kernels (avoid vmap-heavy paths)
32
  try:
33
  import torch
34
  torch.backends.cuda.sdp_kernel(enable_math=True, enable_flash=False, enable_mem_efficient=False)
35
  except Exception:
36
  pass
37
+ # -------------------------------------------------------------------------------
 
 
 
38
  import sys
39
  from huggingface_hub import hf_hub_download
40
  import pickle