# aws-samples/ai-ml-sagemaker-multi-model-pipeline architecture

> Architecture diagram of the GitHub repository aws-samples/ai-ml-sagemaker-multi-model-pipeline, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aws-samples/ai-ml-sagemaker-multi-model-pipeline
- Repository: https://github.com/aws-samples/ai-ml-sagemaker-multi-model-pipeline

## Overview

1. A custom Docker container (in the “container” directory) that implements a Decision Tree algorithm using scikit-learn – complete with training, prediction, serving, and local testing scripts.
2. A SageMaker pipeline (in the “sagemaker-pipeline” directory) that orchestrates a multi-model training strategy. This pipeline supports both the custom Decision Tree (via your custom container) and an XGBoost model (using SageMaker’s built-in container). It brings together preprocessing (using Data Wrangler transformations), hyperparameter tuning, evaluation, and finally registers the winning model for inference deployment.

##### Main Components
- Container Component (Custom Docker):
- Custom container that includes scripts like “predictor.py”, “train”, “serve”, “wsgi.py”, along with configuration files (e.g., nginx.conf, app-image-config-input.json).
- Local testing space under “local_test” that assists in validating the container functionality.
- SageMaker Pipeline Component:
- Pipeline orchestration that manages both the Decision Tree (custom container) and the XGBoost training.
- Components for preprocessing, hyperparameter tuning, and final evaluation.
- Model registry where the best performing model is stored.
- External Services:
- Connections to AWS services (S3 for data, ECR for container storage, SageMaker for training, and model deployment).

##### Relationships and Interactions
- Pipeline Flow: After preprocessing, branch the flow into two parallel model training paths:
- One path goes to the custom container (Decision Tree) – indicating that before running, the custom container must be pushed to ECR.
- The other uses the built-in XGBoost container from SageMaker.
- Post-training, both paths converge into an evaluation stage (for hyperparameter tuning and performance comparison) and then move into a model registration component.
- Orchestration: The pipeline scripts (like “run_pipeline.py”, “pipeline.py”, “preprocess.py”, etc.) control the flow.

##### Architectural Patterns and Technologies
- Containerization is a key element – emphasize Docker usage, Dockerfile structure, and container orchestration.
- The pipeline design follows a modular, microservice-like pattern: distinct encapsulation of preprocessing, training (for two models), evaluation, and registration.

##### Additional Notes
- That the custom container must first be built and pushed to ECR before being invoked by the pipeline.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Ingestion Layer
    subgraph "Data Ingestion"
        A["AWS S3 Data Bucket"]:::aws
        B["SageMaker Data Wrangler"]:::aws
    end
    A --> B

    %% SageMaker Pipeline Layer
    subgraph "SageMaker Pipeline"
        C["Pipeline Orchestrator"]:::pipeline
        D["Preprocessing"]:::pipeline
        E["Pipeline Execution Script"]:::pipeline
        C --> D
        C --> E
    end
    B --> C

    %% Custom Docker Container Setup
    subgraph "Custom Docker Setup"
        F["Custom Docker Container"]:::container
        G["Decision Tree Module"]:::container
        H["Local Testing Scripts"]:::container
        F --> G
        F --> H
    end
    F -->|"build/push"| I["AWS ECR"]:::aws

    %% Model Training Layer
    subgraph "Model Training"
        J["Custom Decision Tree Training"]:::container
        K["XGBoost Training"]:::sagemaker
        D --> J
        D --> K
        I --> J
        K --> L["AWS SageMaker"]:::aws
    end

    %% Model Evaluation & Deployment Layer
    subgraph "Model Evaluation & Deployment"
        M["Decision Tree Evaluation"]:::pipeline
        N["XGBoost Evaluation"]:::pipeline
        O["Model Registry"]:::pipeline
        J --> M
        K --> N
        M --> O
        N --> O
    end

    %% Click Events
    click F "https://github.com/aws-samples/ai-ml-sagemaker-multi-model-pipeline/tree/main/container/"
    click G "https://github.com/aws-samples/ai-ml-sagemaker-multi-model-pipeline/tree/main/container/decision_trees/"
    click H "https://github.com/aws-samples/ai-ml-sagemaker-multi-model-pipeline/tree/main/container/local_test/"
    click C "https://github.com/aws-samples/ai-ml-sagemaker-multi-model-pipeline/tree/main/sagemaker-pipeline/"
    click D "https://github.com/aws-samples/ai-ml-sagemaker-multi-model-pipeline/blob/main/sagemaker-pipeline/pipelines/diabetes/preprocess.py"
    click M "https://github.com/aws-samples/ai-ml-sagemaker-multi-model-pipeline/blob/main/sagemaker-pipeline/pipelines/diabetes/dtree_evaluate.py"
    click N "https://github.com/aws-samples/ai-ml-sagemaker-multi-model-pipeline/blob/main/sagemaker-pipeline/pipelines/diabetes/xgb_evaluate.py"
    click E "https://github.com/aws-samples/ai-ml-sagemaker-multi-model-pipeline/blob/main/sagemaker-pipeline/pipelines/run_pipeline.py"

    %% Styles
    classDef aws fill:#9fdf9f,stroke:#333,stroke-width:2px;
    classDef pipeline fill:#ffd699,stroke:#333,stroke-width:2px;
    classDef container fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef sagemaker fill:#ffcccb,stroke:#333,stroke-width:2px;
```
