Spaces:
Running
Running
Hardik commited on
Commit ·
b6b2e33
1
Parent(s): 48320d3
Fix LSTM: better loader fallbacks, verify tf-keras
Browse files- Dockerfile +2 -1
- ml_service/app/services/model_loader.py +7 -5
Dockerfile
CHANGED
|
@@ -10,7 +10,8 @@ RUN pip install --no-cache-dir fastapi==0.111.0 uvicorn==0.30.1 pydantic==2.7.4
|
|
| 10 |
scipy==1.13.1 nltk==3.8.1 tensorflow==2.16.1 keras==3.3.3 \
|
| 11 |
transformers==4.41.2 joblib==1.4.2 && \
|
| 12 |
pip install --no-cache-dir torch==2.3.1 --index-url https://download.pytorch.org/whl/cpu && \
|
| 13 |
-
pip install --no-cache-dir tf-keras
|
|
|
|
| 14 |
|
| 15 |
RUN python -c "import nltk; nltk.download('stopwords', quiet=True); nltk.download('punkt', quiet=True); nltk.download('wordnet', quiet=True)"
|
| 16 |
|
|
|
|
| 10 |
scipy==1.13.1 nltk==3.8.1 tensorflow==2.16.1 keras==3.3.3 \
|
| 11 |
transformers==4.41.2 joblib==1.4.2 && \
|
| 12 |
pip install --no-cache-dir torch==2.3.1 --index-url https://download.pytorch.org/whl/cpu && \
|
| 13 |
+
pip install --no-cache-dir tf-keras && \
|
| 14 |
+
python -c "import tf_keras; print('tf-keras OK')"
|
| 15 |
|
| 16 |
RUN python -c "import nltk; nltk.download('stopwords', quiet=True); nltk.download('punkt', quiet=True); nltk.download('wordnet', quiet=True)"
|
| 17 |
|
ml_service/app/services/model_loader.py
CHANGED
|
@@ -112,11 +112,13 @@ class ModelManager:
|
|
| 112 |
continue
|
| 113 |
if not loaded:
|
| 114 |
raise RuntimeError("Could not load LSTM model with any backend")
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
|
|
|
|
|
|
| 120 |
|
| 121 |
with open(tok_path, "rb") as f:
|
| 122 |
self.lstm_tokenizer = pickle.load(f)
|
|
|
|
| 112 |
continue
|
| 113 |
if not loaded:
|
| 114 |
raise RuntimeError("Could not load LSTM model with any backend")
|
| 115 |
+
if hasattr(self.lstm_model, "signatures") and "serving_default" in self.lstm_model.signatures:
|
| 116 |
+
self.lstm_fast_predict = self.lstm_model.signatures["serving_default"]
|
| 117 |
+
else:
|
| 118 |
+
@tf.function(reduce_retracing=True)
|
| 119 |
+
def fast_predict(x):
|
| 120 |
+
return self.lstm_model(x, training=False)
|
| 121 |
+
self.lstm_fast_predict = fast_predict
|
| 122 |
|
| 123 |
with open(tok_path, "rb") as f:
|
| 124 |
self.lstm_tokenizer = pickle.load(f)
|