Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,11 @@
|
|
| 1 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
# Quiet TensorFlow logs (must be set before importing tensorflow)
|
| 3 |
os.environ.setdefault("TF_CPP_MIN_LOG_LEVEL", "3")
|
| 4 |
os.environ.setdefault("TF_ENABLE_ONEDNN_OPTS", "0")
|
|
@@ -36,6 +43,10 @@ def get_protbert():
|
|
| 36 |
if _protbert_model is None:
|
| 37 |
import torch
|
| 38 |
from transformers import BertTokenizer, BertModel
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
_torch = torch
|
| 40 |
_device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 41 |
_protbert_tokenizer = BertTokenizer.from_pretrained(
|
|
|
|
| 1 |
import os
|
| 2 |
+
# --- Prevent SIGSEGV (exit 139) from TensorFlow + PyTorch native lib clashes ---
|
| 3 |
+
# TF and torch each bundle their own OpenMP/MKL; loaded together they can collide
|
| 4 |
+
# and crash at the C level. These settings make them coexist and reduce memory.
|
| 5 |
+
os.environ.setdefault("KMP_DUPLICATE_LIB_OK", "TRUE")
|
| 6 |
+
os.environ.setdefault("OMP_NUM_THREADS", "1")
|
| 7 |
+
os.environ.setdefault("MKL_NUM_THREADS", "1")
|
| 8 |
+
os.environ.setdefault("OPENBLAS_NUM_THREADS", "1")
|
| 9 |
# Quiet TensorFlow logs (must be set before importing tensorflow)
|
| 10 |
os.environ.setdefault("TF_CPP_MIN_LOG_LEVEL", "3")
|
| 11 |
os.environ.setdefault("TF_ENABLE_ONEDNN_OPTS", "0")
|
|
|
|
| 43 |
if _protbert_model is None:
|
| 44 |
import torch
|
| 45 |
from transformers import BertTokenizer, BertModel
|
| 46 |
+
try:
|
| 47 |
+
torch.set_num_threads(1) # reduce native threading conflicts with TF
|
| 48 |
+
except Exception:
|
| 49 |
+
pass
|
| 50 |
_torch = torch
|
| 51 |
_device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 52 |
_protbert_tokenizer = BertTokenizer.from_pretrained(
|