# zltao/mgat architecture

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

- Interactive diagram: https://gitdiagram.com/zltao/mgat
- Repository: https://github.com/zltao/mgat

## Overview

1. This repository is a compact research implementation of MGAT, a recommendation model built in PyTorch. The architecture is centered on a training pipeline that loads multimodal interaction data, builds graph-based representations, runs graph attention propagation, and optimizes recommendation loss on GPU.

2. The top-level entry point is `train.py`. It is the orchestration layer: it parses training arguments, initializes data and model objects, runs the epoch/batch loop, evaluates results, and applies optimization settings such as learning rate, batch size, and weight decay.

3. `DataLoad.py` is the data boundary of the system. Its role is to ingest the recommendation dataset and prepare the structures the model needs, likely including user-item interactions and modality-specific item features or graphs. In an architecture diagram, this is the point where raw dataset files are converted into tensors and graph inputs.

4. `GraphGAT.py` contains the graph-attention core. Based on the paper and the filename, this module implements propagation over multimodal graphs and attention weighting over neighbors or modalities. It is the main representation-learning subsystem, responsible for extracting embeddings from graph structure rather than from dense feature vectors alone.

5. `Model.py` is the higher-level recommendation model that wraps the graph encoder and defines how learned embeddings are combined into final user-item preference scores. This layer usually contains the scoring function, modality fusion logic, and the objective used during training.

6. The main data flow is: dataset files -> `DataLoad.py` -> graph and tensor batches -> `Model.py` -> `GraphGAT.py` for message passing and attention -> prediction scores -> loss/optimizer in `train.py`. That is the core loop to show in a diagram.

7. The key architectural boundary is between data preparation and model computation. `DataLoad.py` is responsible for constructing the multimodal graph inputs, while `GraphGAT.py` and `Model.py` stay focused on differentiable learning. This separation matters because the model depends on graph structure and modality partitions supplied by the loader.

8. The model is multimodal by design, so modality-specific paths are important. Rather than treating all item features as a single embedding, MGAT disentangles preferences at the modality level and then uses gated attention to determine how much each modality contributes to a user’s recommendation signal.

9. The system is recommendation-oriented, not a general-purpose GNN stack. Its output is presumably a ranked relevance score for user-item pairs, and its training objective is optimized for implicit-feedback recommendation. Any architecture diagram should therefore emphasize user/item embedding flow and ranking prediction, not classification.

10. The repository depends on PyTorch for training and tensor computation, NumPy for data handling, and PyTorch Geometric for graph-related operations or graph data structures. The documented runtime is Python 3.6.5 with CUDA-enabled training, so the practical deployment target is a single-GPU research environment.

11. There are no obvious service boundaries, APIs, or external infrastructure layers in this repo. It is a self-contained offline training codebase, with the main “integration points” being the dataset on disk and the GPU runtime.

12. In short, the architecture is: offline multimodal graph data preparation, graph-attention-based embedding learning, gated fusion across modalities, and end-to-end recommendation training/evaluation. For a diagram, the important boxes are `DataLoad.py`, `GraphGAT.py`, `Model.py`, and `train.py`, with arrows showing data preprocessing into graph learning and then into scoring and optimization.

Main entry points: [`Model.py`](https://github.com/zltao/mgat/blob/master/Model.py) (Model), [`train.py`](https://github.com/zltao/mgat/blob/master/train.py) (Train), [`DataLoad.py`](https://github.com/zltao/mgat/blob/master/DataLoad.py) (Data load), [`GraphGAT.py`](https://github.com/zltao/mgat/blob/master/GraphGAT.py) (Graph GAT)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core pipeline"]
  node_train["Train<br/>orchestrator<br/>[train.py]"]
  node_data["Data load<br/>dataset prep<br/>[DataLoad.py]"]
  node_model["Model<br/>recommender<br/>[Model.py]"]
  node_gat{{"Graph GAT<br/>graph encoder<br/>[GraphGAT.py]"}}
end

node_train -->|"loads data"| node_data
node_train -->|"builds model"| node_model
node_data -->|"batches graph inputs"| node_model
node_model -->|"encodes embeddings"| node_gat
node_gat -->|"returns embeddings"| node_model
node_model -->|"loss and scores"| node_train

click node_train "https://github.com/zltao/mgat/blob/master/train.py"
click node_data "https://github.com/zltao/mgat/blob/master/DataLoad.py"
click node_model "https://github.com/zltao/mgat/blob/master/Model.py"
click node_gat "https://github.com/zltao/mgat/blob/master/GraphGAT.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_train,node_data,node_model,node_gat toneBlue
```

## Components

### Core pipeline

Offline multimodal recommendation training and graph-attention embedding learning

- [Train](https://github.com/zltao/mgat/blob/master/train.py): orchestrator · Parses args, runs epochs, evaluates, and applies optimization settings · `train.py`
- [Data load](https://github.com/zltao/mgat/blob/master/DataLoad.py): dataset prep · Builds user-item interactions and multimodal graph inputs from disk · `DataLoad.py`
- [Model](https://github.com/zltao/mgat/blob/master/Model.py): recommender · Combines learned embeddings into preference scores and training objective · `Model.py`
- [Graph GAT](https://github.com/zltao/mgat/blob/master/GraphGAT.py): graph encoder · Performs graph attention propagation and modality-aware message passing · `GraphGAT.py`

## Connections

- Train → Data load: loads data · Training starts by constructing dataset objects and graph inputs
- Train → Model: builds model · The entry point initializes the recommender and its parameters
- Data load → Model: batches graph inputs · Prepared tensors and multimodal structures feed the model
- Model → Graph GAT: encodes embeddings · The model delegates representation learning to graph attention propagation
- Graph GAT → Model: returns embeddings · Graph encoder outputs user and item representations for scoring
- Model → Train: loss and scores · Training consumes prediction scores and optimization loss
