Prathamesh Bhamare commited on
Commit
a13ee72
·
1 Parent(s): ffe2ac5

Fix MLflow deprecation error and fallback model loading

Browse files
Files changed (4) hide show
  1. Dockerfile +1 -0
  2. Dockerfile.hf +2 -0
  3. api/main.py +3 -0
  4. ml/predict.py +13 -2
Dockerfile CHANGED
@@ -41,5 +41,6 @@ EXPOSE 7860
41
 
42
  # Default model run ID
43
  ENV KRONECTOR_MODEL_RUN_ID=8d8d20f14dce44d991c5fccfdc090a68
 
44
 
45
  CMD ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "7860"]
 
41
 
42
  # Default model run ID
43
  ENV KRONECTOR_MODEL_RUN_ID=8d8d20f14dce44d991c5fccfdc090a68
44
+ ENV MLFLOW_ALLOW_FILE_STORE=true
45
 
46
  CMD ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "7860"]
Dockerfile.hf CHANGED
@@ -58,4 +58,6 @@ EOF
58
  # HF Spaces expects port 7860
59
  EXPOSE 7860
60
 
 
 
61
  CMD ["supervisord", "-c", "/etc/supervisor/supervisord.conf"]
 
58
  # HF Spaces expects port 7860
59
  EXPOSE 7860
60
 
61
+ ENV MLFLOW_ALLOW_FILE_STORE=true
62
+
63
  CMD ["supervisord", "-c", "/etc/supervisor/supervisord.conf"]
api/main.py CHANGED
@@ -103,6 +103,9 @@ async def lifespan(app: FastAPI):
103
 
104
  load_dotenv() # Load variables from .env file
105
 
 
 
 
106
  # Ensure MLFLOW_TRACKING_URI is set correctly to local mlruns if empty or unset
107
  if not os.getenv("MLFLOW_TRACKING_URI"):
108
  os.environ["MLFLOW_TRACKING_URI"] = "./mlruns"
 
103
 
104
  load_dotenv() # Load variables from .env file
105
 
106
+ # Allow MLflow to use the local filesystem store (required in MLflow 2.13+)
107
+ os.environ["MLFLOW_ALLOW_FILE_STORE"] = "true"
108
+
109
  # Ensure MLFLOW_TRACKING_URI is set correctly to local mlruns if empty or unset
110
  if not os.getenv("MLFLOW_TRACKING_URI"):
111
  os.environ["MLFLOW_TRACKING_URI"] = "./mlruns"
ml/predict.py CHANGED
@@ -19,8 +19,19 @@ def load_model_and_encoders(run_id: str):
19
  """Load a logged MLflow model and its fitted categorical encoders."""
20
  import mlflow.lightgbm
21
  from mlflow.artifacts import download_artifacts
22
-
23
- model = mlflow.lightgbm.load_model(f"runs:/{run_id}/model")
 
 
 
 
 
 
 
 
 
 
 
24
  encoder_path = download_artifacts(
25
  run_id=run_id, artifact_path="encoders/label_encoders.pkl"
26
  )
 
19
  """Load a logged MLflow model and its fitted categorical encoders."""
20
  import mlflow.lightgbm
21
  from mlflow.artifacts import download_artifacts
22
+ import logging
23
+
24
+ logger = logging.getLogger(__name__)
25
+
26
+ try:
27
+ model = mlflow.lightgbm.load_model(f"runs:/{run_id}/model")
28
+ except Exception as e:
29
+ logger.warning(f"Could not load from runs:/ URI: {e}. Trying registered model...")
30
+ try:
31
+ model = mlflow.lightgbm.load_model("models:/kronector-f1-lgbm/latest")
32
+ except Exception as e2:
33
+ logger.error(f"Failed to load registered model: {e2}")
34
+ raise
35
  encoder_path = download_artifacts(
36
  run_id=run_id, artifact_path="encoders/label_encoders.pkl"
37
  )