Spaces:
Running on Zero
Running on Zero
Minjun Kang commited on
Commit Β·
b90da4a
1
Parent(s): 8284daa
dockerfile edit
Browse files
app.py
CHANGED
|
@@ -23,12 +23,22 @@ import joblib
|
|
| 23 |
import torch
|
| 24 |
import gradio as gr
|
| 25 |
import spaces
|
|
|
|
| 26 |
|
| 27 |
warnings.filterwarnings("ignore")
|
| 28 |
|
| 29 |
# ββ Paths βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 30 |
BASE_DIR = Path(__file__).parent
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
# ββ Physical constants (from preprocess/misc.py) ββββββββββββββββββββββββββββββ
|
| 33 |
MAX_TEMP = 60.0
|
| 34 |
MAX_CONC = 1000.0
|
|
@@ -114,11 +124,11 @@ def load_t5():
|
|
| 114 |
_modeling_utils.check_torch_load_is_safe = _noop
|
| 115 |
|
| 116 |
try:
|
| 117 |
-
#
|
| 118 |
-
#
|
| 119 |
-
#
|
| 120 |
-
#
|
| 121 |
-
repo_id =
|
| 122 |
dev = get_device()
|
| 123 |
dtype = torch.float16 if dev == "cuda" else torch.float32
|
| 124 |
|
|
|
|
| 23 |
import torch
|
| 24 |
import gradio as gr
|
| 25 |
import spaces
|
| 26 |
+
from huggingface_hub import snapshot_download
|
| 27 |
|
| 28 |
warnings.filterwarnings("ignore")
|
| 29 |
|
| 30 |
# ββ Paths βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 31 |
BASE_DIR = Path(__file__).parent
|
| 32 |
|
| 33 |
+
# ββ ProtT5 prefetch ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 34 |
+
# This SDK-gradio Space builds from requirements.txt, not the repo's Dockerfile,
|
| 35 |
+
# so there is no build-time prefetch step. Download the weights here instead,
|
| 36 |
+
# at module import (app startup, plain CPU context) β before any @spaces.GPU
|
| 37 |
+
# call β so extract_t5_feature() never blocks on a network download while
|
| 38 |
+
# holding a ZeroGPU allocation (which has a short time budget).
|
| 39 |
+
T5_REPO_ID = "Rostlab/prot_t5_xl_half_uniref50-enc"
|
| 40 |
+
snapshot_download(T5_REPO_ID)
|
| 41 |
+
|
| 42 |
# ββ Physical constants (from preprocess/misc.py) ββββββββββββββββββββββββββββββ
|
| 43 |
MAX_TEMP = 60.0
|
| 44 |
MAX_CONC = 1000.0
|
|
|
|
| 124 |
_modeling_utils.check_torch_load_is_safe = _noop
|
| 125 |
|
| 126 |
try:
|
| 127 |
+
# Already fetched by the module-level snapshot_download() above, so
|
| 128 |
+
# ZeroGPU calls never hit the network here β a cold download would
|
| 129 |
+
# blow past the GPU-allocation time budget and get aborted.
|
| 130 |
+
# local_files_only=True enforces that guarantee.
|
| 131 |
+
repo_id = T5_REPO_ID
|
| 132 |
dev = get_device()
|
| 133 |
dtype = torch.float16 if dev == "cuda" else torch.float32
|
| 134 |
|