# thuml/autotimes architecture

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

- Interactive diagram: https://gitdiagram.com/thuml/autotimes
- Repository: https://github.com/thuml/autotimes

## Overview

##### Main Components

a) Core Processing Pipeline:
- Data Input Layer
- Time Series Data
- Timestamps
- In-Context Prompts (for ICF mode)
- Preprocessing Layer
- Timestamp Text Embedding Generator
- Series Segmentation Module
- LLM Integration Layer
- Frozen LLM Blocks
- Trainable Input/Output Layers
- Forecasting Layer
- Autoregressive Prediction Module
- Output Generation

b) Supporting Components:
- Data Provider System
- Experiment Management
- Utility Services

**[Input Layer]**
- ↓
**[Preprocessing Layer]**
- ↓
**[LLM Integration Layer]**
- ↓
**[Forecasting Layer]**

##### Specific Implementation Details

a) Data Provider Section:
- Connection between data_provider/ and the main pipeline
- M4 dataset handler
- Data factory patterns

b) Model Architecture:
- Different LLM options (GPT2, LLaMA, OPT)
- Frozen vs. trainable components
- Demonstrate the autoregressive nature

c) Experiment Types:
- Time Series Forecasting
- Zero-Shot Forecasting
- In-Context Forecasting

##### Key Relationships to Emphasize

- How the preprocessing.py connects to the LLM integration
- Relationship between exp/ directory experiments
- Demonstrate how utils/ supports the entire pipeline

##### Technical Details

- Input/Output formats
- Model configuration flows
- Training/Inference paths
- Parameter update paths

##### Implementation Notes

- Version information
- Notes for critical components

- The autoregressive nature of the forecasting
- The frozen LLM architecture
- The flexible context length handling
- The three main operational modes

Remember to maintain consistency with the project's structure while clearly showing how all components interact to achieve the system's goals.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and Classes
    classDef input fill:#b3e0ff,stroke:#333
    classDef preprocess fill:#90EE90,stroke:#333
    classDef llm fill:#FFE5B4,stroke:#333
    classDef forecast fill:#FFA07A,stroke:#333
    classDef utility fill:#D3D3D3,stroke:#333
    classDef data fill:#87CEEB,stroke:#333

    %% Input Layer
    subgraph InputLayer["Data Input Layer"]
        DF["Data Factory"]
        M4["M4 Dataset Handler"]
        DL["Data Loader"]
        TSData["Time Series Data"]
        TS["Timestamps"]
        ICP["In-Context Prompts"]
    end

    %% Preprocessing Layer
    subgraph PreprocessLayer["Preprocessing Layer"]
        PP["Main Preprocessing"]
        LPP["LLaMA Preprocessing"]
        TSEmbed["Timestamp Text Embedding"]
        Segment["Series Segmentation"]
    end

    %% LLM Integration Layer
    subgraph LLMLayer["LLM Integration Layer"]
        GPT2["GPT2 Implementation"]
        LLAMA["LLaMA Implementation"]
        OPT["OPT Implementation"]
        FrozenLLM["Frozen LLM Blocks"]
        TrainIO["Trainable I/O Layers"]
    end

    %% Forecasting Layer
    subgraph ForecastLayer["Forecasting Layer"]
        BF["Basic Forecasting"]
        LTF["Long-term Forecasting"]
        STF["Short-term Forecasting"]
        ZSF["Zero-shot Forecasting"]
        ICF["In-context Forecasting"]
        AutoReg["Autoregressive Prediction"]
    end

    %% Utility Services
    subgraph UtilityLayer["Utility Services"]
        Metrics["Metrics"]
        Loss["Loss Functions"]
        M4Sum["M4 Summary Tools"]
        Tools["General Tools"]
        MLP["MLP Implementation"]
    end

    %% Connections
    InputLayer --> PreprocessLayer
    PreprocessLayer --> LLMLayer
    LLMLayer --> ForecastLayer
    UtilityLayer -.-> InputLayer
    UtilityLayer -.-> PreprocessLayer
    UtilityLayer -.-> LLMLayer
    UtilityLayer -.-> ForecastLayer

    %% Click Events
    click DF "https://github.com/thuml/AutoTimes/blob/main/data_provider/data_factory.py"
    click M4 "https://github.com/thuml/AutoTimes/blob/main/data_provider/m4.py"
    click DL "https://github.com/thuml/AutoTimes/blob/main/data_provider/data_loader.py"
    click PP "https://github.com/thuml/AutoTimes/blob/main/preprocess.py"
    click LPP "https://github.com/thuml/AutoTimes/blob/main/models/Preprocess_Llama.py"
    click GPT2 "https://github.com/thuml/AutoTimes/blob/main/models/AutoTimes_Gpt2.py"
    click LLAMA "https://github.com/thuml/AutoTimes/blob/main/models/AutoTimes_Llama.py"
    click OPT "https://github.com/thuml/AutoTimes/blob/main/models/AutoTimes_Opt_1b.py"
    click BF "https://github.com/thuml/AutoTimes/blob/main/exp/exp_basic.py"
    click LTF "https://github.com/thuml/AutoTimes/blob/main/exp/exp_long_term_forecasting.py"
    click STF "https://github.com/thuml/AutoTimes/blob/main/exp/exp_short_term_forecasting.py"
    click ZSF "https://github.com/thuml/AutoTimes/blob/main/exp/exp_zero_shot_forecasting.py"
    click ICF "https://github.com/thuml/AutoTimes/blob/main/exp/exp_in_context_forecasting.py"
    click Metrics "https://github.com/thuml/AutoTimes/blob/main/utils/metrics.py"
    click Loss "https://github.com/thuml/AutoTimes/blob/main/utils/losses.py"
    click M4Sum "https://github.com/thuml/AutoTimes/blob/main/utils/m4_summary.py"
    click Tools "https://github.com/thuml/AutoTimes/blob/main/utils/tools.py"
    click MLP "https://github.com/thuml/AutoTimes/blob/main/layers/mlp.py"

    %% Style Applications
    class DF,M4,DL,TSData,TS,ICP input
    class PP,LPP,TSEmbed,Segment preprocess
    class GPT2,LLAMA,OPT,FrozenLLM,TrainIO llm
    class BF,LTF,STF,ZSF,ICF,AutoReg forecast
    class Metrics,Loss,M4Sum,Tools,MLP utility
```
