# zhouhaoyi/informer2020 architecture

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

- Interactive diagram: https://gitdiagram.com/zhouhaoyi/informer2020
- Repository: https://github.com/zhouhaoyi/informer2020

## Overview

##### Project type and purpose
- This is an open-source machine-learning library implementing the Informer Transformer architecture for long-sequence time-series forecasting.
- It provides data loaders, model code (encoder, decoder, attention), utilities, experiment scripts, and a main orchestration script (`main_informer.py`) to train/test and evaluate forecasting models on ETT/ECL/Weather datasets.

##### File structure
- Top-level files:
- `Dockerfile`, `Makefile`, `environment.yml`, `requirements.txt`: environment setup & reproducibility
- `README.md`, `LICENSE`: documentation and licensing
- `main_informer.py`: entry point for training, testing, prediction
- Directories:
- `data/`: dataset loaders (`data_loader.py`)
- `models/`: core model components (`encoder.py`, `decoder.py`, `attn.py`, `embed.py`, `model.py`)
- `utils/`: helper functions (masking, metrics, time-feature encodings, generic tools)
- `exp/`: example experiment flows
- `scripts/`: shell scripts to run experiments for different datasets

##### README for additional insights
- It lists dependencies (PyTorch, numpy, pandas, etc.) and shows how to run experiments via `main_informer.py` or Docker/Make.

a. Main components
1. Data Sources: ETT, ECL, Weather CSV files in `data/ETT/`, `data/ECL/`, etc.
2. Data Loader & Preprocessor: `data/data_loader.py` + `utils/timefeatures.py`, `utils/masking.py`
3. Model Core:
- Embedding Layer (`models/embed.py`): token & positional/time encoding
- Encoder Stack (`models/encoder.py`): ProbSparseAttention (`models/attn.py`), distillation
- Decoder Stack (`models/decoder.py`): generative decoder with mix attention
- Model Orchestration (`models/model.py`): connects encoder, decoder, final linear output
4. Training & Evaluation Engine: `main_informer.py`
- Argument parsing, dataset instantiation, model instantiation
- Optimizer, loss (`utils/metrics.py`), learning-rate schedule
- Checkpointing, logging, optional AMP, multi-GPU
5. Experiment Scripts: `exp/`, `scripts/` driving reproducible workflows
6. External Dependencies: PyTorch, numpy, pandas, scikit-learn, matplotlib

b. Relationships & interactions
- Data files → Data Loader → Preprocessor → Data Batches → Model Core
- Model Core (encoder + decoder) ↔ Loss & Metrics → Training loop
- Training loop → Checkpoints + Logs + Evaluation → Prediction outputs & Figures
- Scripts & Makefile/Docker orchestrate data download, Docker build, environment setup, batch runs

c. Architectural patterns & design principles
- Modular ML pipeline: clear separation between data ingestion, preprocessing, model definition, training logic
- Encoder–decoder Transformer pattern with custom sparse attention (ProbSparse)
- Experiment reproducibility: containerization (Docker), scripted runs, parameter files (`.sh` scripts)
- Extensible: new datasets plug into `data_loader.py`; new attention/encoder variants extend base classes

d. Relevant technologies & frameworks
- PyTorch 1.x for deep learning
- Python 3.6, numpy/pandas for data manipulation
- scikit-learn for auxiliary tools
- Docker & Make for environment reproducibility
- matplotlib for plotting

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Layer
    subgraph "Data & Preprocessing"
        direction TB
        DS["Data Sources\n(ETT/ECL/Weather CSV)"]:::data
        DL["Data Loader\ndata/data_loader.py"]:::data
        PF1["Time Features\nutils/timefeatures.py"]:::pre
        PF2["Masking\nutils/masking.py"]:::pre
    end

    %% Model Core
    subgraph "Model Core" 
        direction TB
        EMB["Embedding Layer\nmodels/embed.py"]:::model
        ENC["Encoder Stack\nmodels/encoder.py"]:::model
        ATT["ProbSparse Attention\nmodels/attn.py"]:::model
        DEC["Decoder Stack\nmodels/decoder.py"]:::model
        MOD["Model Orchestration\nmodels/model.py"]:::model
    end

    %% Training & Evaluation
    subgraph "Training & Evaluation Engine"
        direction TB
        ME["main_informer.py"]:::orch
        MET["Metrics & Loss\nutils/metrics.py"]:::orch
    end

    %% Experiments
    subgraph "Experiments & Scripts"
        direction TB
        EXP1["exp_basic.py\nexp/exp_basic.py"]:::exp
        EXP2["exp_informer.py\nexp/exp_informer.py"]:::exp
        S1["ETTh1.sh\nscripts/ETTh1.sh"]:::exp
        S2["ETTh2.sh\nscripts/ETTh2.sh"]:::exp
        S3["ETTm1.sh\nscripts/ETTm1.sh"]:::exp
        S4["WTH.sh\nscripts/WTH.sh"]:::exp
    end

    %% Environment & Reproducibility
    subgraph "Environment & Docs"
        direction TB
        DO["Dockerfile"]:::ext
        MK["Makefile"]:::ext
        EY["environment.yml"]:::ext
        RQ["requirements.txt"]:::ext
        RD["README.md"]:::ext
        LI["LICENSE"]:::ext
    end

    %% External Dependencies
    DEP["External Dependencies\n(PyTorch, numpy, pandas,\nscikit-learn, matplotlib)"]:::ext

    %% Data Flow
    DS -->|"raw CSV"| DL
    DL -->|"data batches"| PF1
    DL --> PF2
    PF1 -->|"processed batches"| EMB
    PF2 --> EMB

    %% Model Flow
    EMB -->|"embeddings"| ENC
    ENC --> ATT
    ATT --> ENC
    ENC -->|"encoder output"| DEC
    DEC -->|"decoder output"| MOD

    %% Training Flow
    MOD -->|"model instance"| ME
    ME --> MET
    MET -->|"loss, metrics"| ME
    ME -->|"checkpoints & logs"| EXP1
    ME --> EXP2

    %% Experiment & Scripts Orchestration
    EXP1 --> S1
    EXP1 --> S2
    EXP2 --> S3
    EXP2 --> S4

    %% Environment integration
    DO --> ME
    MK --> ME
    EY --> ME
    RQ --> ME
    RD --> ME
    LI --> ME

    ME --> DEP

    classDef data fill:#d0e7ff,stroke:#3399ff,color:#000;
    classDef pre fill:#e6f2ff,stroke:#66b3ff,color:#000;
    classDef model fill:#d9f2d9,stroke:#33cc33,color:#000;
    classDef orch fill:#ffe6cc,stroke:#ff9933,color:#000;
    classDef exp fill:#fff2cc,stroke:#ffcc00,color:#000;
    classDef ext fill:#f2f2f2,stroke:#bfbfbf,color:#000;

    %% Click events
    click DL "https://github.com/zhouhaoyi/informer2020/blob/main/data/data_loader.py"
    click PF1 "https://github.com/zhouhaoyi/informer2020/blob/main/utils/timefeatures.py"
    click PF2 "https://github.com/zhouhaoyi/informer2020/blob/main/utils/masking.py"
    click EMB "https://github.com/zhouhaoyi/informer2020/blob/main/models/embed.py"
    click ENC "https://github.com/zhouhaoyi/informer2020/blob/main/models/encoder.py"
    click ATT "https://github.com/zhouhaoyi/informer2020/blob/main/models/attn.py"
    click DEC "https://github.com/zhouhaoyi/informer2020/blob/main/models/decoder.py"
    click MOD "https://github.com/zhouhaoyi/informer2020/blob/main/models/model.py"
    click ME "https://github.com/zhouhaoyi/informer2020/blob/main/main_informer.py"
    click MET "https://github.com/zhouhaoyi/informer2020/blob/main/utils/metrics.py"
    click EXP1 "https://github.com/zhouhaoyi/informer2020/blob/main/exp/exp_basic.py"
    click EXP2 "https://github.com/zhouhaoyi/informer2020/blob/main/exp/exp_informer.py"
    click S1 "https://github.com/zhouhaoyi/informer2020/blob/main/scripts/ETTh1.sh"
    click S2 "https://github.com/zhouhaoyi/informer2020/blob/main/scripts/ETTh2.sh"
    click S3 "https://github.com/zhouhaoyi/informer2020/blob/main/scripts/ETTm1.sh"
    click S4 "https://github.com/zhouhaoyi/informer2020/blob/main/scripts/WTH.sh"
    click DO "https://github.com/zhouhaoyi/informer2020/tree/main/Dockerfile"
    click MK "https://github.com/zhouhaoyi/informer2020/tree/main/Makefile"
    click EY "https://github.com/zhouhaoyi/informer2020/blob/main/environment.yml"
    click RQ "https://github.com/zhouhaoyi/informer2020/blob/main/requirements.txt"
    click RD "https://github.com/zhouhaoyi/informer2020/blob/main/README.md"
    click LI "https://github.com/zhouhaoyi/informer2020/tree/main/LICENSE"
```
