# lamm-mit/graph-aware-transformers architecture

> Architecture diagram of the GitHub repository lamm-mit/graph-aware-transformers, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lamm-mit/graph-aware-transformers
- Repository: https://github.com/lamm-mit/graph-aware-transformers

## Overview

xgpt is a Python library for LLaMA-style language models augmented with graph-aware attention and GNN processing. The main workflow is to configure a model, pass tokenized text through the causal-LM entry point and stacked custom decoder layers, and produce language-model outputs; users can train a tokenizer separately. The README also describes sparse GIN fine-tuning and coarse-grained latent attention. Those capabilities are represented, though some implementation details are not visible in the sampled excerpts; edges without direct source evidence are omitted.

Main entry points: [`src/xgpt/llama_decoder_layer_with_gnn.py`](https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/llama_decoder_layer_with_gnn.py) (GNN decoder layer), [`src/xgpt/llama_model_with_gnn.py`](https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/llama_model_with_gnn.py) (LLaMA model), [`src/xgpt/gnn_config.py`](https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/gnn_config.py) (GNN configuration), [`src/xgpt/llama_for_causal_lm_with_gnn.py`](https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/llama_for_causal_lm_with_gnn.py) (Causal LM)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_model["Model stack"]
  node_lm["Causal LM"]
  node_llama["LLaMA model"]
  node_decoder["GNN decoder layer"]
  node_adjacency["Adjacency construction"]
end

subgraph group_reasoning["Graph reasoning"]
  node_gin_attention["GIN attention<br/>[Attention_GNN.py]"]
  node_pna_attention["PNA attention<br/>[Attention_GNN.py]"]
  node_sparse_gin["Sparse GIN attention<br/>[Attention_GNN.py]"]
  node_cg_attention["Coarse-grained attention<br/>[CG_Attention.py]"]
  node_graph_network["Causal graph network"]
  node_mlp_gnn["GNN MLP variants<br/>[MLP_GNN.py]"]
end

subgraph group_inputs["Inputs and configuration"]
  node_tokenizer["Tokenizer training"]
  node_config["GNN configuration<br/>[gnn_config.py]"]
end

subgraph group_workflow["Fine-tuning tools"]
  node_training_utils["Fine-tuning utilities<br/>[utils.py]"]
end

node_user(("Model user"))

node_user -->|"trains tokens"| node_tokenizer
node_user -->|"configures model"| node_config
node_user -->|"runs model"| node_lm
node_lm -->|"wraps model"| node_llama
node_llama -->|"creates layers"| node_decoder
node_llama -->|"reads settings"| node_config
node_decoder -->|"reads settings"| node_config
node_decoder -->|"constructs"| node_adjacency
node_decoder -.->|"applies GNN"| node_graph_network
node_decoder -.->|"selects attention"| node_gin_attention
node_decoder -.->|"selects attention"| node_pna_attention
node_decoder -.->|"supports variant"| node_cg_attention
node_decoder -.->|"supports variant"| node_mlp_gnn
node_adjacency -.->|"sparsifies attention"| node_sparse_gin
node_user -->|"fine-tunes model"| node_training_utils

click node_tokenizer "https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/custom_tokenizer.py"
click node_config "https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/gnn_config.py"
click node_lm "https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/llama_for_causal_lm_with_gnn.py"
click node_llama "https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/llama_model_with_gnn.py"
click node_decoder "https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/llama_decoder_layer_with_gnn.py"
click node_adjacency "https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/llama_decoder_layer_with_gnn.py"
click node_gin_attention "https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/Attention_GNN.py"
click node_pna_attention "https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/Attention_GNN.py"
click node_sparse_gin "https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/Attention_GNN.py"
click node_cg_attention "https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/CG_Attention.py"
click node_graph_network "https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/graph_neural_network.py"
click node_mlp_gnn "https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/MLP_GNN.py"
click node_training_utils "https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/utils.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_lm,node_llama,node_decoder,node_adjacency,node_user toneBlue
class node_gin_attention,node_pna_attention,node_sparse_gin,node_cg_attention,node_graph_network,node_mlp_gnn toneAmber
class node_tokenizer,node_config toneMint
class node_training_utils toneRose
```

## Components

### Model stack

- [Causal LM](https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/llama_for_causal_lm_with_gnn.py): `src/xgpt/llama_for_causal_lm_with_gnn.py`
- [LLaMA model](https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/llama_model_with_gnn.py): `src/xgpt/llama_model_with_gnn.py`
- [GNN decoder layer](https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/llama_decoder_layer_with_gnn.py): `src/xgpt/llama_decoder_layer_with_gnn.py`
- [Adjacency construction](https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/llama_decoder_layer_with_gnn.py): `src/xgpt/llama_decoder_layer_with_gnn.py`

### Graph reasoning

- [GIN attention](https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/Attention_GNN.py): `src/xgpt/Attention_GNN.py`
- [PNA attention](https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/Attention_GNN.py): `src/xgpt/Attention_GNN.py`
- [Sparse GIN attention](https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/Attention_GNN.py): `src/xgpt/Attention_GNN.py`
- [Coarse-grained attention](https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/CG_Attention.py): `src/xgpt/CG_Attention.py`
- [Causal graph network](https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/graph_neural_network.py): `src/xgpt/graph_neural_network.py`
- [GNN MLP variants](https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/MLP_GNN.py): `src/xgpt/MLP_GNN.py`

### Inputs and configuration

- [Tokenizer training](https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/custom_tokenizer.py): `src/xgpt/custom_tokenizer.py`
- [GNN configuration](https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/gnn_config.py): `src/xgpt/gnn_config.py`

### Fine-tuning tools

- [Fine-tuning utilities](https://github.com/lamm-mit/graph-aware-transformers/blob/main/src/xgpt/utils.py): `src/xgpt/utils.py`

### Other components

- **Model user**

## Connections

- Model user → Tokenizer training: trains tokens (evidence: `README.md`)
- Model user → GNN configuration: configures model (evidence: `README.md`)
- Model user → Causal LM: runs model (evidence: `README.md`)
- Causal LM → LLaMA model: wraps model (evidence: `src/xgpt/llama_for_causal_lm_with_gnn.py`)
- LLaMA model → GNN decoder layer: creates layers (evidence: `src/xgpt/llama_model_with_gnn.py`)
- LLaMA model → GNN configuration: reads settings (evidence: `src/xgpt/llama_model_with_gnn.py`)
- GNN decoder layer → GNN configuration: reads settings (evidence: `src/xgpt/llama_decoder_layer_with_gnn.py`)
- GNN decoder layer → Adjacency construction: constructs (evidence: `src/xgpt/llama_decoder_layer_with_gnn.py`)
- GNN decoder layer → Causal graph network: applies GNN (evidence: `src/xgpt/llama_decoder_layer_with_gnn.py`)
- GNN decoder layer → GIN attention: selects attention (evidence: `src/xgpt/llama_decoder_layer_with_gnn.py`)
- GNN decoder layer → PNA attention: selects attention (evidence: `src/xgpt/llama_decoder_layer_with_gnn.py`)
- GNN decoder layer → Coarse-grained attention: supports variant (evidence: `src/xgpt/llama_decoder_layer_with_gnn.py`)
- GNN decoder layer → GNN MLP variants: supports variant
- Adjacency construction → Sparse GIN attention: sparsifies attention (evidence: `src/xgpt/llama_decoder_layer_with_gnn.py`)
- Model user → Fine-tuning utilities: fine-tunes model (evidence: `README.md`)
