# tenstorrent/tt-forge-fe architecture

> Architecture diagram of the GitHub repository tenstorrent/tt-forge-fe, 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/tenstorrent/tt-forge-fe
- Repository: https://github.com/tenstorrent/tt-forge-fe

## Overview

This project is a graph compiler for deep learning models – “TT-Forge FE” – that optimizes and transforms computational graphs to improve performance. Because the file tree shows extensive C++ source code (in directories such as forge/csrc/) as well as Python bindings (in forge/forge/ and related directories), the architecture follows a compiler pipeline with a clearly delineated front-end (IR construction), multiple optimization passes, a lowering phase (to MLIR and/or TVM), and a runtime backend.

##### Input / Frontend
- Entry point of computational graphs (possibly coming from a deep learning framework or a custom graph definition).

##### Graph Intermediate Representation (IR)
- Core IR model that represents nodes, edges, and operators. This is supported by the “forge/csrc/graph_lib” which contains the definitions for nodes, edges, and utilities.

##### Lowering / Code Generation
- Existence of MLIR and TVM integrations (directories such as “third_party/tvm” and MLIR-related scripts) as part of this process.

##### Runtime & Execution
- This component acts as the final transformation of the graph into executable operations that run on target hardware. You might also reference “tt_torch_device” as specialized device support.

##### Python Bindings & API Layer
- The project offers Python interfaces (found in “forge/forge/”, “forge/csrc/python_bindings*”, etc.) so include a pad or overlay labeled “Python API / Bindings”.
- This layer enables integration with higher-level frameworks and enables rapid prototyping/testing (it could be drawn as an edge connecting the compiler pipeline to external consumers).

##### External Services & Testing Infrastructure
- Optionally, indicate CI/CD, testing, and benchmarking components. Although these are not part of the core compiler pipeline, they ensure quality and performance (visible under “.github”, “forge/test”, “scripts/model_analysis”, etc.).

- Data flow: e.g. “Graph Input” flows into “Graph IR,” which is then transformed by “Optimization Passes” and “Lowering” before reaching the “Runtime.”
- If necessary, add notes or callouts that indicate key technologies (C++, Python, MLIR, TVM) and major directories where that functionality is implemented.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main Compiler Pipeline
    A["Graph Input / Frontend Parser"]:::compiler
    B["Graph IR"]:::compiler
    
    subgraph "Optimization & Transformation Passes"
        C["Constant Folding"]:::pass
        D["Autograd"]:::pass
        E["Pattern Fusion"]:::pass
        F["Tensor Ops Pass"]:::pass
    end
    
    G["Lowering & Code Generation"]:::compiler
    subgraph "Lowering Integrations"
        H["TVM Integration"]:::compiler
        I["MLIR Integration"]:::compiler
    end
    
    J["Runtime & Execution"]:::compiler

    %% Additional Integration Layers
    K["Python API / Bindings"]:::interface
    subgraph "Python Bindings"
        K1["Autograd Python Bindings"]:::interface
        K2["GraphLib Python Bindings"]:::interface
    end

    L["CI/CD & Testing Infrastructure"]:::external
    subgraph "External Services"
        L1["CI/CD Workflows"]:::external
        L2["Unit/Benchmark Tests"]:::external
        L3["Model Analysis Scripts"]:::external
    end

    %% Data Flow Connections
    A -->|"feeds"| B
    B -->|"builds"| C
    C --> D
    D --> E
    E --> F
    F -->|"optimizes for"| G
    G -->|"generates"| J
    G --> H
    G --> I
    B ---|"exposes"| K
    K --- K1
    K --- K2
    J -->|"validated by"| L
    L1 --> L2
    L2 --> L3

    %% Click Events
    click A "https://github.com/tenstorrent/tt-forge-fe/tree/main/forge/forge/"
    click B "https://github.com/tenstorrent/tt-forge-fe/tree/main/forge/csrc/graph_lib/"
    click C "https://github.com/tenstorrent/tt-forge-fe/tree/main/forge/csrc/passes/"
    click D "https://github.com/tenstorrent/tt-forge-fe/tree/main/forge/csrc/passes/"
    click E "https://github.com/tenstorrent/tt-forge-fe/tree/main/forge/csrc/passes/"
    click F "https://github.com/tenstorrent/tt-forge-fe/tree/main/forge/csrc/passes/"
    click G "https://github.com/tenstorrent/tt-forge-fe/tree/main/forge/csrc/lower_to_forge/"
    click H "https://github.com/tenstorrent/tt-forge-fe/tree/main/third_party/tvm"
    click I "https://github.com/tenstorrent/tt-forge-fe/tree/main/third_party/tt-mlir"
    click J "https://github.com/tenstorrent/tt-forge-fe/tree/main/forge/csrc/runtime/"
    click K "https://github.com/tenstorrent/tt-forge-fe/tree/main/forge/forge/"
    click K1 "https://github.com/tenstorrent/tt-forge-fe/blob/main/forge/csrc/autograd/python_bindings.cpp"
    click K2 "https://github.com/tenstorrent/tt-forge-fe/blob/main/forge/csrc/graph_lib/python_bindings.cpp"
    click L1 "https://github.com/tenstorrent/tt-forge-fe/tree/main/.github/"
    click L2 "https://github.com/tenstorrent/tt-forge-fe/tree/main/forge/test/"
    click L3 "https://github.com/tenstorrent/tt-forge-fe/tree/main/scripts/model_analysis/"

    %% Styles
    classDef compiler fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef pass fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef interface fill:#ABEBC6,stroke:#196F3D,stroke-width:2px;
    classDef external fill:#F5CBA7,stroke:#943126,stroke-width:2px;
```
