Skip to content

feat: Add offline MLflow support with local artifact fallback - #5

Open
Sottim wants to merge 1 commit into
rafaelgreca:masterfrom
Sottim:feature/support-offline-mlflow
Open

feat: Add offline MLflow support with local artifact fallback#5
Sottim wants to merge 1 commit into
rafaelgreca:masterfrom
Sottim:feature/support-offline-mlflow

Conversation

@Sottim

@Sottim Sottim commented Dec 7, 2025

Copy link
Copy Markdown

Offline MLflow Support

Overview

This PR adds resilient model loading with automatic fallback to local artifacts when MLflow server is unavailable, ensuring production reliability.

Files Modified

  • src/model/inference.py - Add fallback loading logic
  • src/api/__init__.py - Update error handling
  • docker-compose.yml - Add volume mounts

Features

  • Graceful Degradation: Auto-fallback when MLflow unavailable
  • Zero Downtime: Service continues without MLflow server
  • Offline Support: Works in disconnected environments
  • Multiple Path Search: Checks several locations for artifacts
  • Full Compatibility: Existing MLflow workflow unchanged

Technical Implementation

Before:

def load(self):
    model_uri = f"runs:/{self.run_id}/{self.model_flavor}"
    self.model = mlflow.lightgbm.load_model(model_uri)
    # Fails if MLflow server is down

After:

def load(self):
    try:
        self._load_from_mlflow()  # Try MLflow first
    except Exception:
        self._load_from_local()    # Fallback to local
    # Always works now

Local Artifact Structure

notebooks/mlartifacts/
└── {EXPERIMENT_ID}/
    └── {RUN_ID}/
        └── artifacts/
            └── {model_flavor}/
                └── model.pkl

Testing

Test with MLflow:

docker compose up -d --build mlflow prod
curl http://localhost:8000/predict
# Loads from MLflow server

Test without MLflow:

docker compose stop mlflow
docker compose restart prod
curl http://localhost:8000/predict
#  Loads from local artifacts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant