Minjun Kang commited on
Commit
b90da4a
Β·
1 Parent(s): 8284daa

dockerfile edit

Browse files
Files changed (1) hide show
  1. app.py +15 -5
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
- # Pre-fetched into the HF cache at Docker build time (see Dockerfile's
118
- # snapshot_download step), so ZeroGPU calls never hit the network here β€”
119
- # a cold download would blow past the GPU-allocation time budget and
120
- # get aborted. local_files_only=True enforces that guarantee.
121
- repo_id = "Rostlab/prot_t5_xl_half_uniref50-enc"
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