G.O.D Framework

Documentation: ai_version_control.py

A robust version control system for managing AI models, data pipelines, and system environments.

Introduction

The ai_version_control.py script plays a vital role in the G.O.D Framework as a centralized version management tool. It ensures smooth operations by providing reliable control over module versions, data configurations, and AI model iterations. It forms the backbone for reproducibility and auditability within the system.

Purpose

The key objectives of the script are:

Key Features

Logic and Implementation

The script tracks and manages versions using a systematic tagging and retrieval mechanism. Below is an overview of its functionality:


import logging

class VersionControl:
    """
    A class for managing version control of AI models and pipelines in the G.O.D Framework.
    """

    def __init__(self):
        self.versions = {}
        self.logger = logging.getLogger("VersionControl")

    def add_version(self, component_name, version, metadata=None):
        """
        Add a new version of a model or pipeline component.

        Args:
            component_name (str): Name of the component (e.g., "AI Model").
            version (str): Version string, typically in 'major.minor.patch' format.
            metadata (dict): Additional metadata (e.g., release notes, dependencies).
        """
        if component_name not in self.versions:
            self.versions[component_name] = []
        self.versions[component_name].append({"version": version, "metadata": metadata})
        self.logger.info(f"Version {version} added for component {component_name}")

    def get_latest_version(self, component_name):
        """
        Retrieve the latest version of a component.

        Args:
            component_name (str): Name of the component.

        Returns:
            dict: Latest version information.
        """
        try:
            return self.versions[component_name][-1]
        except (KeyError, IndexError):
            self.logger.error(f"No versions found for component: {component_name}")
            raise ValueError(f"No versions exist for {component_name}")

    def rollback_version(self, component_name, target_version):
        """
        Rollback to a specified version of the component.

        Args:
            component_name (str): Name of the component.
            target_version (str): Target version to rollback to.
        """
        if component_name in self.versions:
            for version_info in self.versions[component_name]:
                if version_info["version"] == target_version:
                    self.logger.info(f"Rollback successful for {component_name} to version {target_version}.")
                    return version_info
        self.logger.error(f"Version {target_version} for {component_name} not found.")
        raise ValueError("Rollback failed: Target version not found.")

# Example Usage
if __name__ == "__main__":
    vc = VersionControl()

    # Add versions
    vc.add_version("AI_Model", "1.0.0")
    vc.add_version("AI_Model", "1.1.0", metadata={"notes": "Improved accuracy on dataset X."})

    # Get latest version
    print(vc.get_latest_version("AI_Model"))  # Output: {'version': '1.1.0', 'metadata': ...}

    # Rollback version
    vc.rollback_version("AI_Model", "1.0.0")
        

Dependencies

The script has minimal dependencies but leverages:

Integration with the G.O.D Framework

Future Enhancements