# aws-samples/foundation-model-benchmarking-tool architecture

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

- Interactive diagram: https://gitdiagram.com/aws-samples/foundation-model-benchmarking-tool
- Repository: https://github.com/aws-samples/foundation-model-benchmarking-tool

## Overview

##### Project type and purpose
- FMBench is an open‑source, command‑line Python package for benchmarking foundation models on AWS generative AI services (SageMaker, Bedrock, EKS, EC2 or any custom endpoint).
- It is config‑driven, modular and plugin‑based, enabling flexible combinations of instance types, inference containers and evaluation protocols.

##### High‑level architecture components
a. FMBench CLI / Orchestrator
- Entry point (fmbench/main.py) that parses command‑line arguments and YAML config files
- Dispatches work to service‑specific deployer/predictor modules
b. Configuration layer
- A folder of YAML files under fmbench/configs drives which model, AWS service and inference container to use
- Defaults and globals modules supply common values
c. Service deployers & predictors (scripts/)
- Sagemaker (sagemaker_deploy.py, sagemaker_predictor.py, sagemaker_metrics.py)
- EC2 (ec2_deploy.py, ec2_predictor.py, ec2_metrics.py)
- EKS (eks_deploy.py, eks_predictor.py)
- Bedrock (bedrock_predictor.py, bedrock_predictor_converseAPI.py)
- Bring‑Your‑Own‑Endpoint (rest_predictor.py, custom_rest_predictor.py)
d. Inference container plugins (scripts/inference_containers/)
- DJL, Triton, vLLM, SGLang, Ollama, etc.
- Selectable via config to package and serve models in Docker
e. Evaluation engine
- Prompt templates under fmbench/prompt_template for performance and accuracy tests
- “Panel of LLM evaluators” modules under analytics/ or fmbench for accuracy majority voting
f. Data storage & results
- Amazon S3 read bucket (config, datasets) and write bucket (metrics, reports)
- Local results directory with report.md, CSV/JSON metrics
g. Analytics & Reporting
- Standalone analytics scripts for plotting and cost analysis (analytics/*.py)
- Jupyter notebooks and docs generate figures
h. Documentation & Website
- MkDocs (mkdocs.yml), docs/, website/ for static site generation

##### Component interactions and data flow
- CLI reads a YAML config → loads model/service/container parameters
- CLI invokes the appropriate deployer module → uses AWS SDK (boto3) to provision resources: CloudFormation, SageMaker endpoint, EC2/EKS instances or Bedrock API calls
- Deployers build or pull a Docker inference container via plugin modules, deploy model artifact
- Predictor modules send inference requests according to test payloads → collect latency, throughput, transaction/minute
- Metrics modules aggregate logs and performance data → write to S3 and local disk
- Evaluation engine loads responses and ground truth → runs prompt templates for accuracy → writes accuracy metrics
- Analytics scripts pull metrics from S3 or local → generate price/performance and accuracy plots
- Documentation generator builds static website from docs/ and mkdocs template

##### Architectural patterns and design principles
- Plugin architecture: deployers and inference container handlers are pluggable and discoverable via folder structure
- Config‑first pattern: nearly every operational parameter lives in a YAML file for reproducibility
- Separation of concerns: clear modules for orchestration, deployment, prediction, evaluation, analytics, and documentation
- Infrastructure as code: CloudFormation templates, Dockerfiles and shell scripts automate resource provisioning

##### Essential elements to capture
- Clear component labels (module names or filenames)
- Boundaries between user environment and AWS cloud
- Relationships among CLI, config, deployers, inference containers, AWS services, data storage, analytics
- Indication of pluggable extensibility points

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Environment
    subgraph "User Environment"
        direction TB
        Configs["YAML Configs"]:::config
        Defaults["Defaults & Globals"]:::config
        CLI["FMBench CLI\n(fmbench/main.py)"]:::cli
        subgraph "Service Deployers & Predictors"
            direction TB
            SMDeploy["SageMaker Deployer\n(sagemaker_deploy.py)"]:::service
            SMPredict["SageMaker Predictor\n(sagemaker_predictor.py)"]:::service
            SMMetrics["SageMaker Metrics\n(sagemaker_metrics.py)"]:::service
            EC2Deploy["EC2 Deployer\n(ec2_deploy.py)"]:::service
            EC2Predict["EC2 Predictor\n(ec2_predictor.py)"]:::service
            EC2Metrics["EC2 Metrics\n(ec2_metrics.py)"]:::service
            EKSDeploy["EKS Deployer\n(eks_deploy.py)"]:::service
            EKSPredict["EKS Predictor\n(eks_predictor.py)"]:::service
            BedrockPredict["Bedrock Predictor\n(bedrock_predictor.py)"]:::service
            BedrockConverse["Bedrock Converse API\n(bedrock_predictor_converseAPI.py)"]:::service
            RestPredict["REST Predictor\n(rest_predictor.py)"]:::service
            CustomRest["Custom REST Predictor\n(custom_rest_predictor.py)"]:::service
        end
        subgraph "Inference Container Plugins"
            direction TB
            DJL["djl.py"]:::plugin
            Triton["triton.py"]:::plugin
            VLLM["vllm.py"]:::plugin
            VLLMGPU["vllm_gpu.py"]:::plugin
            Ollama["ollama.py"]:::plugin
            SGLang["sglang.py"]:::plugin
            ICUtils["utils.py"]:::plugin
        end
        subgraph "Evaluation Engine"
            direction TB
            PromptTemplates["Prompt Templates\n(fmbench/prompt_template/)"]:::eval
            EvalCriteria["Eval Criteria\n(fmbench/prompt_template/eval_criteria/)"]:::eval
        end
    end

    %% AWS Cloud
    subgraph "AWS Cloud"
        direction TB
        SageMaker["SageMaker Endpoint"]:::aws
        EC2Inst["EC2 Instance"]:::aws
        EKSCluster["EKS Cluster"]:::aws
        BedrockAPI["Bedrock API"]:::aws
        IAM["IAM / CloudFormation"]:::awsinfra
        S3Read["S3 Read Bucket"]:::storage
        S3Write["S3 Write Bucket"]:::storage
    end

    %% Local Storage & Analytics
    LocalFS["Local Results Directory"]:::storage
    subgraph "Analytics & Reporting"
        direction TB
        AnalyticsScripts["Analytics Scripts\n(analytics/*.py)"]:::analytics
        Notebooks["Jupyter Notebooks\n(analytics/scratchpad.ipynb)"]:::analytics
    end

    %% Documentation
    subgraph "Documentation & Website"
        direction TB
        MkDocs["mkdocs.yml"]:::doc
        DocsSrc["docs/"]:::doc
        SiteGen["Website Generator\n(website/*.py, templates)"]:::doc
    end

    %% Flows
    Configs -->|loads| CLI
    Defaults -->|provides values| CLI
    CLI -->|dispatch| SMDeploy
    CLI -->|dispatch| EC2Deploy
    CLI -->|dispatch| EKSDeploy
    CLI -->|dispatch| BedrockPredict
    CLI -->|dispatch| RestPredict
    SMDeploy -->|boto3 call| SageMaker
    EC2Deploy -->|boto3 call| EC2Inst
    EKSDeploy -->|boto3 call| EKSCluster
    BedrockPredict -->|API call| BedrockAPI
    SageMaker -->|provision| IAM
    EC2Inst -->|provision| IAM
    EKSCluster -->|provision| IAM

    SMDeploy --> DJL
    SMDeploy --> Triton
    SMDeploy --> VLLM
    EC2Deploy --> VLLMGPU
    EKSDeploy --> Ollama
    RestPredict --> ICUtils

    SMPredict -->|HTTP inference| SageMaker
    EC2Predict -->|HTTP inference| EC2Inst
    EKSPredict -->|HTTP inference| EKSCluster
    BedrockConverse -->|API inference| BedrockAPI
    CustomRest -->|HTTP inference| CustomRest

    SMPredict --> SMMetrics
    EC2Predict --> EC2Metrics
    EKSPredict --> S3Write
    BedrockConverse --> S3Write
    CustomRest --> S3Write

    SMMetrics -->|write metrics| S3Write
    EC2Metrics -->|write metrics| S3Write

    PromptTemplates -->|evaluate responses| EvalCriteria
    EvalCriteria -->|write accuracy| S3Write

    S3Write -->|read metrics| AnalyticsScripts
    LocalFS -->|write report| CLI
    AnalyticsScripts -->|generate plots| LocalFS
    Notebooks -->|visualizations| LocalFS

    DocsSrc -->|source| SiteGen
    MkDocs -->|config| SiteGen
    SiteGen -->|build site| LocalFS

    %% Click Events
    click CLI "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/fmbench/main.py"
    click Configs "https://github.com/aws-samples/foundation-model-benchmarking-tool/tree/main/fmbench/configs/"
    click Defaults "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/fmbench/defaults.py"
    click Defaults "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/fmbench/globals.py"
    click SMDeploy "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/fmbench/scripts/sagemaker_deploy.py"
    click SMPredict "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/fmbench/scripts/sagemaker_predictor.py"
    click SMMetrics "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/fmbench/scripts/sagemaker_metrics.py"
    click EC2Deploy "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/fmbench/scripts/ec2_deploy.py"
    click EC2Predict "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/fmbench/scripts/ec2_predictor.py"
    click EC2Metrics "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/fmbench/scripts/ec2_metrics.py"
    click EKSDeploy "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/fmbench/scripts/eks_deploy.py"
    click EKSPredict "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/fmbench/scripts/eks_predictor.py"
    click BedrockPredict "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/fmbench/scripts/bedrock_predictor.py"
    click BedrockConverse "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/fmbench/scripts/bedrock_predictor_converseAPI.py"
    click RestPredict "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/fmbench/scripts/rest_predictor.py"
    click CustomRest "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/fmbench/scripts/custom_rest_predictor.py"
    click DJL "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/fmbench/scripts/inference_containers/djl.py"
    click Triton "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/fmbench/scripts/inference_containers/triton.py"
    click VLLM "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/fmbench/scripts/inference_containers/vllm.py"
    click VLLMGPU "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/fmbench/scripts/inference_containers/vllm_gpu.py"
    click Ollama "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/fmbench/scripts/inference_containers/ollama.py"
    click SGLang "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/fmbench/scripts/inference_containers/sglang.py"
    click ICUtils "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/fmbench/scripts/inference_containers/utils.py"
    click PromptTemplates "https://github.com/aws-samples/foundation-model-benchmarking-tool/tree/main/fmbench/prompt_template/"
    click EvalCriteria "https://github.com/aws-samples/foundation-model-benchmarking-tool/tree/main/fmbench/prompt_template/eval_criteria/"
    click AnalyticsScripts "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/analytics/analytics.py"
    click AnalyticsScripts "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/analytics/sagemaker_cost_rpm_plot.py"
    click AnalyticsScripts "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/analytics/sagemaker_metrics_plot.py"
    click Notebooks "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/analytics/scratchpad.ipynb"
    click MkDocs "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/mkdocs.yml"
    click DocsSrc "https://github.com/aws-samples/foundation-model-benchmarking-tool/tree/main/docs/"
    click SiteGen "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/website/create_fmbench_website.py"
    click SiteGen "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/website/index.md"
    click SiteGen "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/website/mkdocs_template.yml"
    click SiteGen "https://github.com/aws-samples/foundation-model-benchmarking-tool/blob/main/website/nginx.conf.template"

    %% Styles
    classDef cli fill:#FFD97D,stroke:#333,stroke-width:1px
    classDef config fill:#FFF4D9,stroke:#333,stroke-width:1px
    classDef service fill:#A7C7E7,stroke:#333,stroke-width:1px
    classDef plugin fill:#D5E8D4,stroke:#333,stroke-width:1px
    classDef eval fill:#F8CECC,stroke:#333,stroke-width:1px
    classDef aws fill:#B3E5FC,stroke:#333,stroke-width:1px
    classDef awsinfra fill:#BBDEFB,stroke:#333,stroke-width:1px
    classDef storage fill:#E1D5E7,stroke:#333,stroke-width:1px
    classDef analytics fill:#C9DAF8,stroke:#333,stroke-width:1px
    classDef doc fill:#E2F0CB,stroke:#333,stroke-width:1px
```
