Hardik commited on
Commit
48320d3
·
1 Parent(s): f4a3f22

Fix LSTM loading: try compile=False and multiple backends

Browse files
ml_service/app/services/model_loader.py CHANGED
@@ -98,13 +98,19 @@ class ModelManager:
98
  cfg_path = os.path.join(settings.DATA_DIR, "config.pkl")
99
 
100
  if os.path.exists(model_path) and os.path.exists(tok_path) and os.path.exists(cfg_path):
101
- for loader in [tf.keras.models.load_model, keras.models.load_model]:
 
 
 
 
 
102
  try:
103
- self.lstm_model = loader(model_path)
 
104
  break
105
  except Exception:
106
  continue
107
- else:
108
  raise RuntimeError("Could not load LSTM model with any backend")
109
 
110
  @tf.function(reduce_retracing=True)
 
98
  cfg_path = os.path.join(settings.DATA_DIR, "config.pkl")
99
 
100
  if os.path.exists(model_path) and os.path.exists(tok_path) and os.path.exists(cfg_path):
101
+ loaded = False
102
+ for loader_fn in [
103
+ lambda p: tf.keras.models.load_model(p, compile=False),
104
+ lambda p: keras.models.load_model(p, compile=False),
105
+ lambda p: tf.saved_model.load(p),
106
+ ]:
107
  try:
108
+ self.lstm_model = loader_fn(model_path)
109
+ loaded = True
110
  break
111
  except Exception:
112
  continue
113
+ if not loaded:
114
  raise RuntimeError("Could not load LSTM model with any backend")
115
 
116
  @tf.function(reduce_retracing=True)