How paddlepaddle/pgl works
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: conv.py GNN Convolutions · dist_graph.py Distributed Graph Store · graph.py Homogeneous Graph · __init__.py PGL package
Components 22
PGL Core
Reusable graph-learning package.
- PGL package · Public framework entry point.
pgl/__init__.py - Homogeneous Graph · Topology and node/edge feature contract.
pgl/graph.py - Heterogeneous Graph · Multi-node-type and edge-type graph.
pgl/heter_graph.py - Bipartite Graph
pgl/bigraph.py - Message Passing · Builds edge messages and aggregates destinations.
pgl/message.py - Graph Ops
pgl/nn/functional/graph_op.py - GNN Convolutions
pgl/nn/conv.py - Graph Pooling
pgl/nn/pool.py - Datasets
pgl/dataset.py - DataLoader
pgl/utils/data/dataloader.py
Scale & Distributed
Sampling, partitioning, and distributed execution.
- Neighborhood & Walk Sampling · Creates minibatch neighborhoods and walks.
pgl/sampling/sage.py - Graph Partitioning · Splits graphs for large-scale processing.
pgl/partition.py - Distributed Graph Store · Coordinates graph storage and distributed access.
pgl/distributed/dist_graph.py - Distributed Launch
pgl/distributed/launch.py
Application Frameworks
Opinionated domain and production stacks.
- GNNAutoScale · Partitioned GNN training with historical embeddings.
apps/GNNAutoScale/examples/run.py - Graph4KG · Entity and relation embedding training.
apps/Graph4KG/train.py - Graph4Rec · Graph-based recommendation training and inference.
apps/Graph4Rec/env_run/src/train.py - PGLBox Control · Large-scale sharded graph training and inference.
apps/PGLBox/src/cluster_train_and_infer.py - PGLBox Graph Data
apps/PGLBox/src/graph.py - PGLBox Distributed Program
apps/PGLBox/src/distributed_program.py
Other components
- Examples & OGB Tasks · Runnable task and model implementations.
examples - PaddlePaddle / Fleet · Tensor, accelerator, and distributed-training backend.
Connections 25
- 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