Skip to content

McTurington AI is the AI copilot for data-driven teams—enabling natural language control over the entire data and ML lifecycle. From raw data to production pipelines, it empowers users to build, deploy, and monitor workflows seamlessly, making data truly self-serve and intelligent.

Notifications You must be signed in to change notification settings

panthers-labs-pvt-ltd/mcturington

Repository files navigation

AI/ML Project

Overview

This project explores the integration of Generative AI, Ray, and PyTorch for distributed machine learning. It utilizes Docker for containerization to ensure portability across different computing environments.

Table of Contents

  1. Project Overview
  2. Project Structure
  3. Prerequisites
  4. Setup Instructions
  5. Using Docker
  6. Notes
  7. Troubleshooting

Project Overview

The goal of this project is to leverage Ray for distributed machine learning workloads and PyTorch for building deep learning models. Key components include:

  • Data Preprocessing: Handling and processing data for model training.
  • Model Training: Utilizing PyTorch and Ray for efficient distributed training.
  • Generative AI: Experimenting with and implementing generative AI models.

Project Structure

Below is a Mermaid diagram of the directory structure of the project:

graph TB;
    A[Project Root] --> B[Configuration]
    A --> C[Source Code]
    A --> D[Testing]
    A --> E[Data]
    A --> F[Documentation]
    A --> G[Deployment]
    A --> H[Logging]
    A --> I[Scripts]

    B --> Ba[Ray Config]
    B --> Bb[Model Config]
    B --> Bc[Logging Config]

    C --> Ca[Data Processing]
    C --> Cb[Models]
    C --> Cc[Utilities]
    C --> Cd[Ray Integrations]

    D --> Da[Data Tests]
    D --> Db[Model Tests]
    D --> Dc[Ray Workflow Tests]

    E --> Ea[Raw Data]
    E --> Eb[Processed Data]
    E --> Ec[Outputs]

    F --> Fa[README.md]
    F --> Fb[Requirements.txt]
    F --> Fc[Setup Instructions]

    G --> Ga[Dockerfile]
    G --> Gb[Docker Compose]

    H --> Ha[Debug Log]
    H --> Hb[Error Log]

    I --> Ia[Setup Ray Cluster]
    I --> Ib[Run Models]

    classDef root fill:#f4d03f,stroke:#333,stroke-width:4px;
    classDef major fill:#85c1e9,stroke:#333,stroke-width:2px;
    classDef minor fill:#bb8fce,stroke:#333,stroke-width:1px;
    class A root;
    class B,C,D,E,F,G,H,I major;
    class Ba,Bb,Bc,Ca,Cb,Cc,Cd,Da,Db,Dc,Ea,Eb,Ec,Fa,Fb,Fc,Ga,Gb,Ha,Hb,Ia,Ib minor;

Loading
### Project Structure

Below is the directory structure of the project, providing a clear layout of the project components:

graph TD;
    A[Start Project] --> B[Setup Environment];
    B --> C[Data Preprocessing];
    C --> D[AI Model Training];
    D --> E[Any AI Agent];
    B --> F[Install Dependencies];
    F --> G[Docker Setup];
    G --> H[Build Docker Image];
    H --> I[Run Docker Container];
    I --> J[Using Docker Compose];
    J --> K[Project Execution];
    K --> L[Monitor and Log];
    L --> M[Troubleshoot];
    C --> N[Data Storage];
    N --> O[Data Cleaning];
    O --> D;
    E --> P[Ray Workflow];
    P --> Q[Ray Cluster Management];
    Q --> R[Run on Ray Clusters];
    R --> S[Generate Outputs];
    S --> T[End Project];

    classDef startend fill:#f9f,stroke:#333,stroke-width:4px;
    class A,T startend;

Loading
journey
    title AI Project Development Roadmap (90 Days)
    section Project Initialization
        Create Framework: 5: A, 2023-01-01, 10d
    section Environment Setup
        Configure Ray Environment: 4: B, 2023-01-11, 10d
    section Model Development
        Design and Develop Multi-Model AI Agent: 5: C, 2023-01-21, 20d
    section Training Phase
        Prepare Specific Dataset: 3: D, 2023-02-10, 10d
        Train Model with Dataset: 5: D, 2023-02-20, 20d
    section Integration and Testing
        Integrate Model with Other Services: 4: E, 2023-03-12, 10d
        Conduct Integration Testing: 3: E, 2023-03-22, 5d
    section Deployment
        Deploy to Production: 5: F, 2023-03-27, 3d
    section Monitoring and Maintenance
        Initiate Continuous Monitoring: 5: G, 2023-03-30, 1d
        Establish Periodic Maintenance: 3: G, 2023-03-31, ongoing

Loading

Prerequisites

Before setting up the project, ensure the following tools are installed:

  • Python 3.7 or later
  • pip (Python's package installer)
  • Docker (if using Docker setup)
  • Git (to clone the repository)
  • Conda (optional, for managing environments)

Setup Instructions

1. Create and Activate Virtual Environment

Ensure a clean environment by creating and activating a virtual environment:

# Create the virtual environment
python3 -m venv venv

# Activate the virtual environment
source venv/bin/activate  # For Windows use `venv\Scripts\activate`



Table of Contents

Project Overview
Project Structure
Prerequisites

Setup Instructions

Create and Activate Virtual Environment
Install Dependencies
Run the Project


Using Docker
Notes
Troubleshooting


Project Overview
The goal of this project is to use Ray for distributed machine learning workloads and PyTorch for building deep learning models. Key tasks include:


Data Preprocessing: Handling and processing data for training.

Model Training: Using PyTorch and Ray for distributed training.

Generative AI: Implementing and experimenting with generative AI models.


Project Structure
Here is the folder structure of the project:
AI/ML_Project/ ├── README.md # Project overview and instructions ├── requirements.txt # Python dependencies ├── setup.py # Optional Python package setup script ├── environment.yml # Conda or alternative environment file (optional) ├── configs/ # Configuration files for the project │ ├── ray_config.yaml # Ray cluster configuration │ ├── model_config.yaml # Generative AI model configurations │ └── logging_config.yaml # Logging configurations ├── data/ # Data directory (input/output) │ ├── raw/ # Raw datasets │ ├── processed/ # Processed datasets │ └── outputs/ # Model outputs or logs ├── notebooks/ # Jupyter notebooks for prototyping │ ├── data_preprocessing.ipynb │ ├── model_training.ipynb │ └── ray_workflow_example.ipynb ├── src/ # Source code for the project │ ├── init.py # Makes the folder a Python package │ ├── main.py # Entry point for running the project │ ├── data_processing/ # Data-related operations │ │ ├── init.py │ │ └── preprocess.py # Data preprocessing scripts │ ├── models/ # Generative AI and machine learning models │ │ ├── init.py │ │ ├── ray_trainer.py # Ray-based distributed training │ │ └── generative_ai.py # Generative AI implementations │ ├── utils/ # Utility scripts │ │ ├── init.py │ │ └── helpers.py # Helper functions │ └── ray/ # Ray-specific workflow scripts │ ├── init.py │ └── ray_manager.py # Ray cluster and workflow manager ├── tests/ # Unit tests and integration tests │ ├── test_data_processing.py │ ├── test_models.py │ └── test_ray_workflow.py ├── logs/ # Logs directory │ ├── debug.log │ └── error.log ├── scripts/ # Auxiliary scripts for setup and execution │ ├── setup_ray_cluster.sh # Script to configure Ray cluster │ └── run_model.sh # Script to run models ├── docker/ # Docker setup for containerized deployment │ ├── Dockerfile # Dockerfile for the project │ └── docker-compose.yml # Docker Compose configuration ├── .env # Environment variables └── .gitignore # Ignored files and folders for Git.
markdown
Copy code

Prerequisites
Before setting up the project, make sure you have the following tools installed:

Python 3.7 or later

pip (Python's package installer)

Docker (if using Docker setup)

Git (to clone the repository)

Conda (optional, for managing environments)


Setup Instructions

1. Create and Activate Virtual Environment
   To ensure a clean environment, create and activate a virtual environment:

# Create the virtual environment
python3 -m venv venv

# Activate the virtual environment
source venv/bin/activate  # For Windows use `venv\Scripts\activate`
2. Install Dependencies
   Now, install all required Python dependencies from the requirements.txt file:

bash
Copy code
pip install -r requirements.txt
This will install the required packages, such as:

PyTorch: For machine learning tasks.
Ray: For distributed machine learning.
Transformers, datasets, tokenizers: For Generative AI.
3. Run the Project
   After the environment is set up, you can run the project. The entry point is main.py:

bash
Copy code
python src/main.py




Generative AI Task:

bash
Copy
python src/main.py generative_ai
LLMBA Task:

bash
Copy
python src/main.py llmba
LLMBA RAG Task:
This task requires three additional arguments:

A PDF directory
A VectorDB directory
A question (enclosed in quotes if it contains spaces)
For example:

bash
Copy
python src/main.py llmba_rag /path/to/pdf_directory /path/to/vectordb_directory "What topics are covered in the PDFs?"

This will trigger the main workflow, which includes preprocessing data, training the model, and generating outputs.

Using Docker
If you prefer to use Docker, the project provides a Docker setup to containerize the application. This ensures the project runs the same way across all environments.

1. Build the Docker Image
   In the root directory of the project, build the Docker image:

bash
Copy code
docker build -t aiml_project .
2. Run the Docker Container
   Run the project inside a Docker container:

bash
Copy code
docker run -it --rm aiml_project
This will start the project in an isolated environment with all dependencies installed.

3. Using Docker Compose (Optional)
   If you have docker-compose installed, you can use it to run the project:

bash
Copy code
docker-compose up
This will automatically start all required services defined in docker-compose.yml.

Notes
Ensure your machine meets the hardware requirements for PyTorch and Ray, especially if using GPU resources.
Modify the configuration files under configs/ if you need to adjust the model settings or Ray cluster setup.
Troubleshooting
Conflicting Dependencies: If you face issues with package versions (e.g., conflicting versions of torch and torchaudio), try loosening the version constraints or removing specific versions from requirements.txt and reinstalling the dependencies.

Example:

txt
Copy code
torch
torchvision
torchaudio
Docker Build Issues: Ensure Docker has sufficient resources (memory, CPU) and that you are using the correct version of Docker. Use docker-compose for more complex setups if needed.




/organization-development-environment
|-- /base
|   |-- Dockerfile
|
|-- /team_a
|   |-- Dockerfile
|   |-- /app
|       |-- main.py
|       |-- requirements.txt
|
|-- /team_b
|   |-- Dockerfile
|   |-- /app
|       |-- main.py
|       |-- requirements.txt
|
|-- docker-compose.yml
|-- .env


Description of Directories and Files
/base/Dockerfile: This Dockerfile sets up the base image with common dependencies used by all teams.
/team_x/Dockerfile: Each team has their own Dockerfile that builds from the base image and adds their specific dependencies.
/team_x/app: This directory contains the team's Python application.
docker-compose.yml: Defines how Docker containers should be built and run for local development.
.env: Environment variables for Docker Compose.



Python Script: Automating New Team Setup with Port Management
This script does the following:

Automatically creates the necessary directories and files for a new team.
Writes a Dockerfile based on a base image.
Checks for an available port within a specified range and updates the Docker Compose configuration.
python
Copy code
import os
import yaml
import socket

def find_available_port(start_port, end_port):
"""Check the range for the first available port by attempting to bind to it."""
for port in range(start_port, end_port):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
res = sock.bind(('', port))
if res is None:  # Port is available
return port
raise Exception("No available ports found in the specified range.")

def create_team_setup(team_name, base_image, start_port=8000, end_port=9000):
base_dir = f"./{team_name}"
app_dir = f"{base_dir}/app"
os.makedirs(app_dir, exist_ok=True)

    # Write a simple Python application
    with open(f"{app_dir}/main.py", 'w') as main_py:
        main_py.write(
            "\"\"\"Simple web application for demonstration.\"\"\"\n"
            "from flask import Flask\n"
            "app = Flask(__name__)\n\n"
            "@app.route('/')\n"
            "def home():\n"
            "    return 'Hello from Team ' + __file__\n\n"
            "if __name__ == '__main__':\n"
            "    app.run(host='0.0.0.0', port=5000, debug=True)\n"
        )

    # Create Dockerfile
    dockerfile_path = f"{base_dir}/Dockerfile"
    with open(dockerfile_path, 'w') as df:
        df.write(
            f"FROM {base_image}\n"
            "WORKDIR /app\n"
            "COPY ./app /app\n"
            "RUN pip install flask\n"
            "CMD [\"python\", \"main.py\"]\n"
        )

    # Find an available port and setup docker-compose.yml
    available_port = find_available_port(start_port, end_port)
    docker_compose_path = "docker-compose.yml"
    if not os.path.exists(docker_compose_path):
        with open(docker_compose_path, 'w') as dc_file:
            yaml.safe_dump({'version': '3.8', 'services': {}}, dc_file)

    with open(docker_compose_path, 'r+') as dc_file:
        compose_data = yaml.safe_load(dc_file)
        compose_data['services'][team_name] = {
            'build': f"./{team_name}",
            'ports': [f"{available_port}:5000"]
        }
        dc_file.seek(0)
        yaml.safe_dump(compose_data, dc_file, default_flow_style=False)

    return available_port

if __name__ == "__main__":
team_name = input("Enter the new team's name: ")
base_image = input("Enter the base image name (e.g., 'python:3.9-slim'): ")
port = create_team_setup(team_name, base_image)
print(f"Setup completed for {team_name}. Service is available on port {port}.")
Explanation:
Port Management: The script uses the socket module to find an available port in a given range. This prevents port conflicts by ensuring that the selected port is not already in use.
Team Setup: It sets up a new directory for the team, writes a basic Flask app as an example, and creates a Dockerfile that includes the Flask installation.
Docker Compose Update: The docker-compose.yml file is updated (or created if it doesn't exist) to include the new team's service, mapping the found available port to the internal port 5000 used by the Flask app.



Kubernetes
Kubernetes offers extensive support for RBAC, allowing you to control what actions a user, service, or pod can perform.

Define Roles and RoleBindings: You create roles that specify permissions within a namespace, and then role bindings to assign these roles to users or groups.

yaml
Copy code
# Example role for Team A
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: team_a
name: team_a_role
rules:
- apiGroups: [""]
  resources: ["pods"]
  verbs: ["get", "watch", "list"]




# Example RoleBinding for Team A
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: team_a_role_binding
namespace: team_a
subjects:
- kind: User
  name: team_a_user
  apiGroup: rbac.authorization.k8s.io
  roleRef:
  kind: Role
  name: team_a_role
  apiGroup: rbac.authorization.k8s.io
  Use Namespaces to Isolate Teams: Each team can operate within its own Kubernetes namespace, which acts as a virtual cluster within the cluster.```
  

About

McTurington AI is the AI copilot for data-driven teams—enabling natural language control over the entire data and ML lifecycle. From raw data to production pipelines, it empowers users to build, deploy, and monitor workflows seamlessly, making data truly self-serve and intelligent.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages