# paddlepaddle/pgl architecture

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

- Interactive diagram: https://gitdiagram.com/paddlepaddle/pgl
- Repository: https://github.com/paddlepaddle/pgl

## Overview

#### Purpose and Package Boundary
Paddle Graph Learning (PGL) is a Python graph-learning framework built on PaddlePaddle. It provides graph data structures, message passing, GNN layers, sampling, partitioning, and distributed graph/training support; applications and examples sit above this reusable library. Package entry: `pgl/__init__.py`; distribution metadata: `setup.py`.

#### Core Graph Representations
`pgl/graph.py` is the primary homogeneous graph abstraction, holding topology and node/edge features and exposing graph operations. `pgl/heter_graph.py` extends this boundary to multiple node and edge types. `pgl/bigraph.py` supplies bipartite-graph representation. These objects are the central contract between data loading/sampling and model execution.

#### Message Passing and Neural Layers
The execution path for GNNs is graph → edge message construction → destination aggregation → updated node representations. Core primitives are in `pgl/message.py` and graph operations in `pgl/nn/functional/graph_op.py`. Reusable PaddlePaddle GNN layers, including convolutional operators, reside in `pgl/nn/conv.py`; pooling is in `pgl/nn/pool.py`. Models in examples and apps consume these APIs rather than implementing graph kernels directly.

#### Data, Sampling, and Partitioning
Datasets and loader-facing abstractions are provided by `pgl/dataset.py` and `pgl/utils/data/dataloader.py`. Neighborhood and walk-based sampling form the scale boundary for minibatch or embedding workloads: `pgl/sampling/sage.py` and `pgl/sampling/walk.py`. `pgl/partition.py` partitions graphs for larger-scale processing, with bundled METIS sources under `pgl/third_party/metis/`.

#### Distributed Graph Engine
Distributed execution is centered on graph storage/coordination in `pgl/distributed/dist_graph.py`, launch support in `pgl/distributed/launch.py`, and distributed helpers in `pgl/distributed/helper.py`. This layer integrates with PaddlePaddle/Fleet-style distributed training and parameter-server infrastructure; applications may use CPU/GPU workers and distributed embeddings. It is a runtime boundary separate from in-process graph operations.

#### Application Frameworks
Three substantial domain frameworks build on PGL:
- GNNAutoScale scales message-passing GNNs through partitioning and historical embeddings: `apps/GNNAutoScale/examples/run.py`, `apps/GNNAutoScale/graph_partition.py`, `apps/GNNAutoScale/history.py`.
- Graph4KG trains entity/relation embeddings for knowledge graphs, including distributed training: `apps/Graph4KG/train.py`, `apps/Graph4KG/dist_train.py`, `apps/Graph4KG/models/ke_model.py`.
- Graph4Rec provides graph-based recommendation training/inference, including distributed CPU paths: `apps/Graph4Rec/env_run/src/train.py`, `apps/Graph4Rec/env_run/src/dist_cpu_train.py`, `apps/Graph4Rec/env_run/src/models/model.py`.

#### Large-Scale Production-Oriented Toolkit
PGLBox is a separate large-scale training/inference stack oriented around sharded graph data and cluster execution. Its control entry point is `apps/PGLBox/src/cluster_train_and_infer.py`; graph/data and distributed program boundaries are `apps/PGLBox/src/graph.py` and `apps/PGLBox/src/distributed_program.py`. It includes graph sharding and Hadoop-oriented utilities at `apps/PGLBox/sharding_tool/graph_sharding.py` and `apps/PGLBox/src/util_hadoop.py`.

#### Executable Consumers and Compatibility
`examples/` and `ogb_examples/` are runnable model/task implementations, while `apps/` contains more opinionated frameworks. `legacy/` preserves an older PGL API and examples, distinct from the active `pgl/` package. Runtime requirements are Python 3, PaddlePaddle (>=2.2.0), and Cython; PyPI publishing is automated via `.github/workflows/build_and_upload_PyPI.yml`.

Main entry points: [`pgl/nn/conv.py`](https://github.com/paddlepaddle/pgl/blob/main/pgl/nn/conv.py) (GNN Convolutions), [`pgl/distributed/dist_graph.py`](https://github.com/paddlepaddle/pgl/blob/main/pgl/distributed/dist_graph.py) (Distributed Graph Store), [`pgl/graph.py`](https://github.com/paddlepaddle/pgl/blob/main/pgl/graph.py) (Homogeneous Graph), [`pgl/__init__.py`](https://github.com/paddlepaddle/pgl/blob/main/pgl/__init__.py) (PGL package)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["PGL Core"]
  node_pgl["PGL package<br/>Python package<br/>[__init__.py]"]
  node_graph{{"Homogeneous Graph<br/>graph abstraction<br/>[graph.py]"}}
  node_heter_graph{{"Heterogeneous Graph<br/>graph abstraction<br/>[heter_graph.py]"}}
  node_bigraph{{"Bipartite Graph<br/>graph abstraction<br/>[bigraph.py]"}}
  node_message["Message Passing<br/>GNN primitive<br/>[message.py]"]
  node_graph_ops["Graph Ops<br/>neural functional API<br/>[graph_op.py]"]
  node_conv["GNN Convolutions<br/>Paddle layers<br/>[conv.py]"]
  node_pool["Graph Pooling<br/>Paddle layers<br/>[pool.py]"]
  node_dataset["Datasets<br/>data API<br/>[dataset.py]"]
  node_dataloader["DataLoader<br/>loader API<br/>[dataloader.py]"]
end

subgraph group_scale["Scale &amp; Distributed"]
  node_sampling["Neighborhood &amp; Walk Sampling<br/>[sage.py]"]
  node_partition["Graph Partitioning<br/>[partition.py]"]
  node_dist_graph[("Distributed Graph Store<br/>distributed runtime<br/>[dist_graph.py]")]
  node_dist_launch["Distributed Launch<br/>runtime launcher<br/>[launch.py]"]
end

subgraph group_apps["Application Frameworks"]
  node_gnn_autoscale["GNNAutoScale<br/>scalable GNN app<br/>[run.py]"]
  node_graph4kg["Graph4KG<br/>knowledge graph app<br/>[train.py]"]
  node_graph4rec["Graph4Rec<br/>recommendation app<br/>[train.py]"]
  node_pglbox["PGLBox Control<br/>cluster application"]
  node_pglbox_graph[("PGLBox Graph Data<br/>sharded graph runtime<br/>[graph.py]")]
  node_pglbox_dist["PGLBox Distributed Program<br/>cluster runtime"]
end

node_examples["Examples &amp; OGB Tasks<br/>executable consumers"]
node_paddle["PaddlePaddle / Fleet<br/>external runtime"]

node_pgl -->|"exports"| node_graph
node_pgl -->|"exports"| node_heter_graph
node_pgl -->|"exports"| node_bigraph
node_dataset -->|"feeds"| node_dataloader
node_graph -->|"sampled by"| node_sampling
node_sampling -->|"minibatches"| node_dataloader
node_graph -->|"message flow"| node_message
node_message -->|"aggregation ops"| node_graph_ops
node_graph_ops -->|"implements"| node_conv
node_conv -->|"model layers"| node_pool
node_conv -->|"runs on"| node_paddle
node_graph -->|"partitioned for scale"| node_partition
node_partition -->|"distributed shards"| node_dist_graph
node_dist_launch -->|"starts workers"| node_dist_graph
node_dist_graph -->|"Fleet integration"| node_paddle
node_gnn_autoscale -->|"uses"| node_partition
node_gnn_autoscale -->|"scales"| node_conv
node_graph4kg -->|"uses GNN APIs"| node_conv
node_graph4kg -->|"distributed training"| node_dist_graph
node_graph4rec -->|"uses GNN APIs"| node_conv
node_graph4rec -->|"distributed CPU path"| node_dist_graph
node_pglbox -->|"orchestrates"| node_pglbox_graph
node_pglbox -->|"runs through"| node_pglbox_dist
node_pglbox_dist -->|"cluster execution"| node_paddle
node_examples -->|"consumes"| node_conv

click node_pgl "https://github.com/paddlepaddle/pgl/blob/main/pgl/__init__.py"
click node_graph "https://github.com/paddlepaddle/pgl/blob/main/pgl/graph.py"
click node_heter_graph "https://github.com/paddlepaddle/pgl/blob/main/pgl/heter_graph.py"
click node_bigraph "https://github.com/paddlepaddle/pgl/blob/main/pgl/bigraph.py"
click node_message "https://github.com/paddlepaddle/pgl/blob/main/pgl/message.py"
click node_graph_ops "https://github.com/paddlepaddle/pgl/blob/main/pgl/nn/functional/graph_op.py"
click node_conv "https://github.com/paddlepaddle/pgl/blob/main/pgl/nn/conv.py"
click node_pool "https://github.com/paddlepaddle/pgl/blob/main/pgl/nn/pool.py"
click node_dataset "https://github.com/paddlepaddle/pgl/blob/main/pgl/dataset.py"
click node_dataloader "https://github.com/paddlepaddle/pgl/blob/main/pgl/utils/data/dataloader.py"
click node_sampling "https://github.com/paddlepaddle/pgl/blob/main/pgl/sampling/sage.py"
click node_partition "https://github.com/paddlepaddle/pgl/blob/main/pgl/partition.py"
click node_dist_graph "https://github.com/paddlepaddle/pgl/blob/main/pgl/distributed/dist_graph.py"
click node_dist_launch "https://github.com/paddlepaddle/pgl/blob/main/pgl/distributed/launch.py"
click node_gnn_autoscale "https://github.com/paddlepaddle/pgl/blob/main/apps/GNNAutoScale/examples/run.py"
click node_graph4kg "https://github.com/paddlepaddle/pgl/blob/main/apps/Graph4KG/train.py"
click node_graph4rec "https://github.com/paddlepaddle/pgl/blob/main/apps/Graph4Rec/env_run/src/train.py"
click node_pglbox "https://github.com/paddlepaddle/pgl/blob/main/apps/PGLBox/src/cluster_train_and_infer.py"
click node_pglbox_graph "https://github.com/paddlepaddle/pgl/blob/main/apps/PGLBox/src/graph.py"
click node_pglbox_dist "https://github.com/paddlepaddle/pgl/blob/main/apps/PGLBox/src/distributed_program.py"
click node_examples "https://github.com/paddlepaddle/pgl/tree/main/examples"

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_pgl,node_graph,node_heter_graph,node_bigraph,node_message,node_graph_ops,node_conv,node_pool,node_dataset,node_dataloader toneBlue
class node_sampling,node_partition,node_dist_graph,node_dist_launch toneAmber
class node_gnn_autoscale,node_graph4kg,node_graph4rec,node_pglbox,node_pglbox_graph,node_pglbox_dist toneMint
class node_examples,node_paddle toneNeutral
```

## Components

### PGL Core

Reusable graph-learning package.

- [PGL package](https://github.com/paddlepaddle/pgl/blob/main/pgl/__init__.py): Python package · Public framework entry point. · `pgl/__init__.py`
- [Homogeneous Graph](https://github.com/paddlepaddle/pgl/blob/main/pgl/graph.py): graph abstraction · Topology and node/edge feature contract. · `pgl/graph.py`
- [Heterogeneous Graph](https://github.com/paddlepaddle/pgl/blob/main/pgl/heter_graph.py): graph abstraction · Multi-node-type and edge-type graph. · `pgl/heter_graph.py`
- [Bipartite Graph](https://github.com/paddlepaddle/pgl/blob/main/pgl/bigraph.py): graph abstraction · `pgl/bigraph.py`
- [Message Passing](https://github.com/paddlepaddle/pgl/blob/main/pgl/message.py): GNN primitive · Builds edge messages and aggregates destinations. · `pgl/message.py`
- [Graph Ops](https://github.com/paddlepaddle/pgl/blob/main/pgl/nn/functional/graph_op.py): neural functional API · `pgl/nn/functional/graph_op.py`
- [GNN Convolutions](https://github.com/paddlepaddle/pgl/blob/main/pgl/nn/conv.py): Paddle layers · `pgl/nn/conv.py`
- [Graph Pooling](https://github.com/paddlepaddle/pgl/blob/main/pgl/nn/pool.py): Paddle layers · `pgl/nn/pool.py`
- [Datasets](https://github.com/paddlepaddle/pgl/blob/main/pgl/dataset.py): data API · `pgl/dataset.py`
- [DataLoader](https://github.com/paddlepaddle/pgl/blob/main/pgl/utils/data/dataloader.py): loader API · `pgl/utils/data/dataloader.py`

### Scale & Distributed

Sampling, partitioning, and distributed execution.

- [Neighborhood & Walk Sampling](https://github.com/paddlepaddle/pgl/blob/main/pgl/sampling/sage.py): sampling · Creates minibatch neighborhoods and walks. · `pgl/sampling/sage.py`
- [Graph Partitioning](https://github.com/paddlepaddle/pgl/blob/main/pgl/partition.py): partitioning · Splits graphs for large-scale processing. · `pgl/partition.py`
- [Distributed Graph Store](https://github.com/paddlepaddle/pgl/blob/main/pgl/distributed/dist_graph.py): distributed runtime · Coordinates graph storage and distributed access. · `pgl/distributed/dist_graph.py`
- [Distributed Launch](https://github.com/paddlepaddle/pgl/blob/main/pgl/distributed/launch.py): runtime launcher · `pgl/distributed/launch.py`

### Application Frameworks

Opinionated domain and production stacks.

- [GNNAutoScale](https://github.com/paddlepaddle/pgl/blob/main/apps/GNNAutoScale/examples/run.py): scalable GNN app · Partitioned GNN training with historical embeddings. · `apps/GNNAutoScale/examples/run.py`
- [Graph4KG](https://github.com/paddlepaddle/pgl/blob/main/apps/Graph4KG/train.py): knowledge graph app · Entity and relation embedding training. · `apps/Graph4KG/train.py`
- [Graph4Rec](https://github.com/paddlepaddle/pgl/blob/main/apps/Graph4Rec/env_run/src/train.py): recommendation app · Graph-based recommendation training and inference. · `apps/Graph4Rec/env_run/src/train.py`
- [PGLBox Control](https://github.com/paddlepaddle/pgl/blob/main/apps/PGLBox/src/cluster_train_and_infer.py): cluster application · Large-scale sharded graph training and inference. · `apps/PGLBox/src/cluster_train_and_infer.py`
- [PGLBox Graph Data](https://github.com/paddlepaddle/pgl/blob/main/apps/PGLBox/src/graph.py): sharded graph runtime · `apps/PGLBox/src/graph.py`
- [PGLBox Distributed Program](https://github.com/paddlepaddle/pgl/blob/main/apps/PGLBox/src/distributed_program.py): cluster runtime · `apps/PGLBox/src/distributed_program.py`

### Other components

- [Examples & OGB Tasks](https://github.com/paddlepaddle/pgl/tree/main/examples): executable consumers · Runnable task and model implementations. · `examples`
- **PaddlePaddle / Fleet**: external runtime · Tensor, accelerator, and distributed-training backend.

## Connections

- PGL package → Homogeneous Graph: exports
- PGL package → Heterogeneous Graph: exports
- PGL package → Bipartite Graph: exports
- Datasets → DataLoader: feeds
- Homogeneous Graph → Neighborhood & Walk Sampling: sampled by
- Neighborhood & Walk Sampling → DataLoader: minibatches
- Homogeneous Graph → Message Passing: message flow
- Message Passing → Graph Ops: aggregation ops
- Graph Ops → GNN Convolutions: implements
- GNN Convolutions → Graph Pooling: model layers
- GNN Convolutions → PaddlePaddle / Fleet: runs on
- Homogeneous Graph → Graph Partitioning: partitioned for scale
- Graph Partitioning → Distributed Graph Store: distributed shards
- Distributed Launch → Distributed Graph Store: starts workers
- Distributed Graph Store → PaddlePaddle / Fleet: Fleet integration
- GNNAutoScale → Graph Partitioning: uses
- GNNAutoScale → GNN Convolutions: scales
- Graph4KG → GNN Convolutions: uses GNN APIs
- Graph4KG → Distributed Graph Store: distributed training
- Graph4Rec → GNN Convolutions: uses GNN APIs
- Graph4Rec → Distributed Graph Store: distributed CPU path
- PGLBox Control → PGLBox Graph Data: orchestrates
- PGLBox Control → PGLBox Distributed Program: runs through
- PGLBox Distributed Program → PaddlePaddle / Fleet: cluster execution
- Examples & OGB Tasks → GNN Convolutions: consumes
