Skip to content

Conversation

@gabisponciano
Copy link
Contributor

@gabisponciano gabisponciano commented Sep 2, 2025

MLflow 3.1.0 Models-from-Code Migration for Vacation Recommendation with BERT

Overview

This migration modernizes the "Vacation Recommendation with BERT" blueprint by transitioning from MLflow's legacy serialization-based model logging (python_model) to the models-from-code approach (loader_module + data_path). This update resolves MLflow 3.1.0 compatibility issues, improves code architecture, and maintains API compatibility for vacation recommendation workflows.

Key Changes

  • Primary Goal: Eliminate MLflow 3.1.0 serialization errors and adopt the models-from-code pattern.
  • Technical Approach: Introduce a clean separation of concerns with standalone BERT model classes.
  • Universal Structure: Align with the standardized src/mlflow/ structure established in PR feat: MLflow 3.1.0 Models-from-Code Migration for Vanilla RAG Blueprint #208.
  • Scope: Comprehensive migration affecting model loading, recommendation generation, and deployment workflows.

Universal Structure Standardization

The blueprint now follows the universal AI-Blueprints structure pattern:

Standardized Architecture

src/
├── utils.py               # Common utilities (e.g., get_model_path, load_config)
└── mlflow/
    ├── __init__.py        # Dynamic imports
    ├── model.py           # Business logic for BERT recommendation
    ├── loader.py          # Canonical loader
    ├── logger.py          # Canonical logger

Universal Loader & Logger Synchronization


Technical Changes

New Architecture Components

src/mlflow/model.py

  • Purpose: Standalone BERT recommendation logic with zero MLflow dependencies.
  • Class Name: class Model (generic name, no blueprint prefixes).
  • Functionality:
    • Loads pre-trained BERT models and tokenizers.
    • Processes vacation-related input data.
    • Generates vacation recommendations based on embeddings.
    • Maintains the predict(model_input, params) API signature for backward compatibility.
  • Design Pattern: Clean separation between BERT logic and MLflow integration.

src/mlflow/loader.py

src/mlflow/logger.py

src/mlflow/__init__.py


Notebook Updates

Enhanced Signature Handling

Signature creation now occurs in the notebook:

from mlflow.models.signature import ModelSignature
from mlflow.types.schema import Schema, ColSpec

# Define model input/output schema for BERT recommendation
input_schema = Schema([
    ColSpec("string", "user_id"),  # User identifier
    ColSpec("string", "preferences")  # User preferences
])
output_schema = Schema([
    ColSpec("string", "recommendation")  # Recommended vacation
])
signature = ModelSignature(inputs=input_schema, outputs=output_schema)

# Pass signature to logger
Logger.log_model(
    signature=signature,
    artifact_path=MODEL_NAME,
    config_path=CONFIG_PATH,
    docs_path=ARTIFACTS_PATH,  # Contains BERT artifacts
    demo_folder=DEMO_FOLDER
)

Artifact Management

BERT Model Artifacts Structure

The blueprint now handles BERT-specific artifacts:

/artifacts/data/
    ├── config.yaml          # Model configuration
    ├── tokenizer/           # Tokenizer files
    ├── model/               # Pre-trained BERT model weights
    └── demo/                # UI components

Testing Strategy

Manual Testing

  • Test Scenarios:
    • BERT model registration with vacation recommendation datasets.
    • Model loading and recommendation generation.
    • Deployment validation through Streamlit UI with various user inputs.
    • Notebook execution validation in both development and MLflow deployment contexts.
    • API endpoint testing with different payload configurations.

Quality Assurance

Code Quality

  • Code Style: Consistent with repository standards, comprehensive docstrings, proper type hints.
  • Universal Structure: Follows canonical pattern from PR feat: MLflow 3.1.0 Models-from-Code Migration for Vanilla RAG Blueprint #208.
  • Documentation: Clear architectural layer responsibilities, detailed BERT recommendation documentation.
  • Error Handling: Robust exception management with informative error messages and logging.

Performance Impact

  • Model Loading: Faster initialization due to optimized artifact handling.
  • Memory Usage: Reduced memory footprint by removing unnecessary MLflow inheritance.
  • Deployment Time: Improved deployment reliability with models-from-code approach.

Review Guidelines

Critical Review Areas

  1. Universal Structure: Verify alignment with canonical structure from PR feat: MLflow 3.1.0 Models-from-Code Migration for Vanilla RAG Blueprint #208.
  2. Signature Handling: Confirm signature creation occurs in the notebook and is passed to the logger.
  3. MLflow Integration: Verify loader.py correctly implements models-from-code pattern.
  4. API Compatibility: Confirm Model.predict() maintains identical signature and behavior.
  5. Artifact Handling: Validate proper organization and cleanup of BERT artifacts.
  6. Configuration Management: Review model path resolution and environment variable handling.
  7. ONNX Support: Review if ONNX is supported

Deployment Considerations

  • Rollback Procedure: Previous python_model approach is incompatible with models-from-code.
  • Environment Setup: Ensure MODEL_ARTIFACTS_PATH environment variable is configured in deployment containers.
  • Dependencies: Verify MLflow 3.1.0 compatibility with transformers in target deployment environments.
  • Artifact Dependencies: Ensure all required BERT artifacts are present in deployment packages.

Migration Status:Complete and Ready for Review

Specialized Features:

  • BERT Models: Full support for vacation recommendation generation.
  • User Preferences Analysis: Specialized recommendation logic for user preferences.
  • Artifact Management: Optimized handling of tokenizer and model weights.
  • Streamlined Deployment: Universal structure alignment with other blueprints.

Printed page of the Streamlit web app showing evidence of successful local deployment and API testing:

Streamlit for Vacation Recommendation with BERT.pdf

@gabisponciano gabisponciano self-assigned this Sep 2, 2025
@gabisponciano gabisponciano marked this pull request as draft September 2, 2025 11:55
@github-actions github-actions bot added enhancement Improvements to existing features dependencies Pull requests that update a dependency file python Pull requests that update python code labels Sep 2, 2025
…ndation-with-bert' of https://github.com/HPInc/AI-Blueprints into feat/mlflow-models-from-code-migration-vacation-recommendation-with-bert
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Sep 8, 2025
…at/mlflow-models-from-code-migration-vacation-recommendation-with-bert
…ndation-with-bert' of https://github.com/HPInc/AI-Blueprints into feat/mlflow-models-from-code-migration-vacation-recommendation-with-bert
@gabisponciano gabisponciano marked this pull request as ready for review September 10, 2025 18:38
@ata-turhan ata-turhan force-pushed the feat/mlflow-models-from-code-migration-vacation-recommendation-with-bert branch from 539b308 to 10a794e Compare September 25, 2025 15:25
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Oct 14, 2025
Copy link
Member

@ata-turhan ata-turhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great 🚀

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

Labels

dependencies Pull requests that update a dependency file enhancement Improvements to existing features python Pull requests that update python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants