# awslabs/fmbench-orchestrator architecture

> Architecture diagram of the GitHub repository awslabs/fmbench-orchestrator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/awslabs/fmbench-orchestrator
- Repository: https://github.com/awslabs/fmbench-orchestrator

## Overview

##### Main Components and Their Roles
- Orchestrator CLI/Initialization:
– Represented by the “main.py” entry point.
– Responsible for reading command-line parameters and loading the orchestrator configuration files (config files in the “configs” folder), custom datasets (in “byo_dataset”), and prompt templates (in “custom_prompt_templates”).
– This component then triggers the other modules.

- Configuration Management:
– Shows the logical layer that handles the various YAML configuration files, including instance types, benchmark parameters, and mappings (like ami mapping and infra config).

- Instance / Cloud Resource Manager:
– Illustrate the component that “launches and manages” EC2 (and indirectly SageMaker/Bedrock) instances. This module uses AWS APIs to instantiate and later terminate compute resources.

- Benchmark Execution Module:
– Represent the FMbench execution environment that deploys benchmarking experiments (possibly on the launched instances) using configurations (from FMbench config files). This module inherits logic from both the “main.py” and scripts in the “analytics” folder.
– Also indicate that this part supports multiple experiments per instance, including sequential runs (e.g., testing different configurations on the same instance).

- Upload / File Synchronization Layer:
– Show that for each experiment run, custom files (datasets from “byo_dataset”, prompt templates, custom config modifications) are uploaded from the orchestrator to the target instance. This is essential for experiments that require custom input.

- Results Collection and Analytics:
– Represent this as a module visualized in two parts: one that collects results from the cloud instances (via the instance’s “Results Collection” process) and another that conducts analysis (leveraging the “analytics” scripts and notebooks like sagemaker_metrics_plot.py, pricing.yml, etc.).
– Demonstrate that results are stored locally on the orchestrator EC2 instance and then processed to generate reports (including heatmaps and performance tables).

##### Relationships and Data Flow
- Once instances are active, the orchestrator instructs them to run the benchmark experiments (using FMbench configuration files passed along).
- Finally, the flow moves to instance termination once processing is complete.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Use distinct sections to clearly show responsibilities for initialization/configuration, resource provisioning, experimental execution, and analytics.
- Parallel/Sequential Experiment Handling: Illustrate with grouped or iterative blocks that multiple FMbench config files can be deployed on the same instance.

##### Relevant Technologies, Frameworks, or Libraries
- Python as the primary language (main.py, utils.py, globals.py).
- YAML and JSON for configuration/data (configs, byo_dataset).
- AWS Infrastructure (EC2 instances, IAM roles, SageMaker endpoints, AWS AMI mapping).
- FMbench, which is the benchmarking tool that actually performs LLM evaluation.
- The plotting and analytics libraries which are invoked in analytics (e.g., notebooks and scripts for visualizing cost/performance and latency).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Orchestration & Configuration
    subgraph "Orchestration & Configuration"
        A["Orchestrator CLI (main.py)"]:::cli
        B["Configuration Manager"]:::config
        C["Globals & Constants"]:::config
        D["File Sync"]:::upload
    end

    %% Resource Management & Benchmark Execution
    subgraph "Resource Management & Benchmark Execution"
        E["EC2 Resource Manager"]:::manager
        F["FMbench Executor"]:::benchmark
    end

    %% Results Collection & Analytics
    subgraph "Results Collection & Analytics"
        G["Results Collector"]:::analytics
        H["Analytics Processor"]:::analytics
        I["Cost Plotter"]:::analytics
        J["Metrics Plotter"]:::analytics
    end

    %% Connections within Orchestration & Configuration
    A -->|"loads_config"| B
    B -->|"reads_constants"| C

    %% Flow from Configuration to Resource Management
    B -->|"provision_instance"| E

    %% File Sync to Benchmark Execution
    D -->|"upload_files"| F

    %% Resource Management & Benchmark Execution flow
    E -->|"launch_benchmark"| F

    %% Benchmark Execution to Results Collection
    F -->|"get_results"| G

    %% Results flow and final processing
    G -->|"process_results"| H
    H -->|"cost_report"| I
    H -->|"metrics_report"| J
    H -->|"terminate_instance"| E

    %% Click Events
    click A "https://github.com/awslabs/fmbench-orchestrator/blob/main/main.py"
    click B "https://github.com/awslabs/fmbench-orchestrator/tree/main/configs"
    click C "https://github.com/awslabs/fmbench-orchestrator/blob/main/constants.py"
    click C "https://github.com/awslabs/fmbench-orchestrator/blob/main/globals.py"
    click D "https://github.com/awslabs/fmbench-orchestrator/tree/main/byo_dataset"
    click D "https://github.com/awslabs/fmbench-orchestrator/tree/main/custom_prompt_templates"
    click E "https://github.com/awslabs/fmbench-orchestrator/blob/main/configs/ec2.yml"
    click E "https://github.com/awslabs/fmbench-orchestrator/tree/main/startup_scripts"
    click F "https://github.com/awslabs/fmbench-orchestrator/tree/main/configs/fmbench"
    click F "https://github.com/awslabs/fmbench-orchestrator/blob/main/post_startup_scripts/fmbench.txt"
    click G "https://github.com/awslabs/fmbench-orchestrator/blob/main/analytics/analytics.py"
    click H "https://github.com/awslabs/fmbench-orchestrator/blob/main/analytics/sagemaker_cost_rpm_plot.py"
    click I "https://github.com/awslabs/fmbench-orchestrator/blob/main/analytics/sagemaker_cost_rpm_plot.py"
    click J "https://github.com/awslabs/fmbench-orchestrator/blob/main/analytics/sagemaker_metrics_plot.py"

    %% Styles
    classDef cli fill:#ffcccc,stroke:#990000,stroke-width:2px;
    classDef config fill:#ccffcc,stroke:#009900,stroke-width:2px;
    classDef manager fill:#ccccff,stroke:#000099,stroke-width:2px;
    classDef benchmark fill:#ffffcc,stroke:#999900,stroke-width:2px;
    classDef upload fill:#ffe6cc,stroke:#cc6600,stroke-width:2px;
    classDef analytics fill:#e6ccff,stroke:#663399,stroke-width:2px;
```
