# pku-dair/hetu-galvatron architecture

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

- Interactive diagram: https://gitdiagram.com/pku-dair/hetu-galvatron
- Repository: https://github.com/pku-dair/hetu-galvatron

## Overview

Overview:

Step 1: Identify Main Components
- Galvatron Profiler: This module handles hardware and model profiling. It includes subcomponents that collect information on device capabilities (e.g., via the profile_hardware directory and nccl-tests) and model computation patterns (located in several “models” directories).
- Galvatron Search Engine: This is the optimization “brain” which, using sophisticated cost modeling and dynamic programming techniques, explores the space of parallel strategies. Its source files, especially within galvatron/core/search_engine, indicate the presence of cost model evaluation and strategy generation functions.
- Galvatron Runtime Framework: This module is responsible for translating high-level strategies into execution instructions. It encompasses both the parallelism execution logic and runtime configurations (found in galvatron/core/runtime and related pipeline and tensor parallel submodules).

Step 2: Capture Additional System Elements
- Model Implementations: A variety of Transformer models (T5, BERT, GPT, Llama, Swin, ViT, etc.) are provided under galvatron/models, each with their own configuration, dataloader, and profiling scripts. Represent these as a component or submodule that feeds into the profiling and runtime modules.
- Hardware Configuration and Profiling Tools: The galvatron/profile_hardware folder (and related scripts in this directory) should be shown as part of the Profiler’s input channel.
- Datasets and Checkpointing: The site_package and tools directories include additional capabilities such as distributed checkpoint strategies, dataset utilities, and inference modules. They can be shown as auxiliary services that integrate with the runtime layer when needed.
- User Interface and Integration: Command scripts (in scripts, Makefile files, etc.) and installation procedures indicate a user-friendly interface. Consider denoting an “Interface/Controller” block that receives the user-specified hardware settings and model configurations, then triggers the profiling, search, and runtime procedures.

– Data flows from the “Hardware & Model Profiling” block to the “Search Engine.”
– The optimized parallel strategy configuration then moves to the “Runtime Framework.”
– The runtime outputs feed into training execution and possibly interact with the dataloader and checkpoint modules.
- Inter-module relationships, for example:
– The Profiler gathers metrics and passes computed profiles (memory, compute, communication) to the Search Engine.
– The Search Engine applies algorithmic searches (via dynamic programming) to select an optimal hybrid parallel strategy.
– The Runtime Framework employs these strategies to orchestrate distributed training.
- Technology details (e.g., “PyTorch ≥ 2.1.0”) and mention that strategies include DP, TP, PP, SP, and activation checkpointing.
– Core modules (e.g., use rectangles with bold borders).
– Supporting libraries/tools (e.g., use rounded rectangles).

Step 4: Tailoring for This Project Type
Since Galvatron is a full-fledged distributed training framework:
1. Separation and interaction between the profiling, strategy optimization, and runtime execution. This is essential to capture the high-level architecture of automatic parallelism.
2. Subcomponents that are customized for specific Transformer models. For instance, within the “Model” component, list out variants like T5, BERT, GPT, Llama, etc., and note that each has dedicated configurations, dataloaders, and parallel strategy scripts.
3. Integration of external tools such as nccl-tests for hardware profiling and the associated scripts deployed under galvatron/scripts and galvatron/tools.

- Galvatron Profiler (including hardware profiling, model profiling)
- Galvatron Search Engine (with cost model, dynamic programming algorithm)
- Galvatron Runtime Framework (with execution engine, distributed parallel execution)
- Model Library (with sub-blocks for T5, BERT, GPT, Llama, etc.)
- External/Supporting Tools (nccl-tests, checkpointing, dataset modules)
- Flow from profiling to search engine.
- Flow from search engine to runtime framework.
- Feedback loops if any (e.g., iterative optimization adjustments).
- Labels and Annotations describing:
- The specific parallelism techniques (DP, TP, PP, SP, CKPT).
- Hardware and model configuration details.
- Integration with frameworks like PyTorch.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interface Layer"
        UI["User Interface / Command Scripts"]:::config
    end

    subgraph "Profiling Module"
        PROF["Galvatron Profiler\n(Hardware & Model Profiling)"]:::core
        HT["Hardware Profiling Tools"]:::support
    end

    subgraph "Search Engine Module"
        SE["Galvatron Search Engine\n(Cost Modeling, DP)"]:::core
    end

    subgraph "Runtime Module"
        RT["Galvatron Runtime Framework\n(Execution Engine)"]:::core
        DS["Datasets"]:::support
        CP["Checkpointing"]:::support
    end

    subgraph "Model Library"
        ML["Model Implementations\n(T5, BERT, GPT, Llama, Swin, ViT)"]:::support
    end

    subgraph "External Tools"
        ET["External Tools\n(nccl-tests)"]:::support
    end

    %% Connections
    UI -->|"triggers"| PROF
    ML -->|"supplies_model_configs"| PROF
    ET -->|"enhances_hardware_profiling"| HT
    PROF -->|"sends_profiling_data"| SE
    SE -->|"delivers_optimized_strategy"| RT
    ML -->|"supplies_model_configs"| RT
    RT -->|"integrates_with"| DS
    RT -->|"integrates_with"| CP

    %% Click Events
    click UI "https://github.com/pku-dair/hetu-galvatron/tree/main/galvatron/scripts"
    click PROF "https://github.com/pku-dair/hetu-galvatron/tree/main/galvatron/core/profiler"
    click SE "https://github.com/pku-dair/hetu-galvatron/tree/main/galvatron/core/search_engine"
    click RT "https://github.com/pku-dair/hetu-galvatron/tree/main/galvatron/core/runtime"
    click ML "https://github.com/pku-dair/hetu-galvatron/tree/main/galvatron/models"
    click HT "https://github.com/pku-dair/hetu-galvatron/tree/main/galvatron/profile_hardware"
    click ET "https://github.com/pku-dair/hetu-galvatron/tree/main/galvatron/profile_hardware"
    click DS "https://github.com/pku-dair/hetu-galvatron/tree/main/galvatron/site_package/megatron/core/datasets"
    click CP "https://github.com/pku-dair/hetu-galvatron/tree/main/galvatron/site_package/megatron/core/dist_checkpointing"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef support fill:#90EE90,stroke:#000,stroke-width:2px,rx:5,ry:5;
    classDef config fill:#FFFACD,stroke:#000,stroke-width:2px,stroke-dasharray: 5 5;
```
