TGraphX vs PyTorch Geometric: Choosing the Right Framework
PyTorch Geometric (PyG) is the most widely deployed GNN framework in the Python ecosystem. TGraphX is a newer, specialized research-engineering library. Comparing them requires being honest about what each is designed for — and what each is not.
This article is intended to help you make a practical choice. It does not claim TGraphX is better than PyG. The honest answer is: for most tasks, PyG is the better choice. This article explains the specific cases where TGraphX's design might be useful.
Quick Summary
| PyTorch Geometric (PyG) | TGraphX | |
|---|---|---|
| Primary focus | General GNN research and production | Tensor-native graph learning + research tooling |
| Node features | Flat vectors [N, D] |
Flat [N, D] and tensors [N, C, H, W], [N, C, D, H, W] |
| Ecosystem | Very large (1000+ papers, production deployments) | Smaller, research-oriented |
| Stability | Production-tested | Beta / Experimental |
| Version | 2.x | 1.4.2 |
| License | MIT | MIT |
| Install | pip install torch-geometric |
pip install tgraphx |
| Paper | Multiple PyG papers | arXiv:2504.03953 |
What PyTorch Geometric Does Well
PyG is the reference implementation for a large fraction of published GNN research. It should be your default choice for:
Standard benchmark tasks: Node classification on Cora, Citeseer, Pubmed, OGB. Link prediction. Graph classification. These benchmarks are built around PyG and most published results use it.
Wide layer selection: GCN, GAT, GATv2, GraphSAGE, GIN, PNA, GCII, and dozens more, all with well-tested implementations.
Production deployment: PyG is used in production recommendation systems, drug discovery pipelines, and other deployed applications. TGraphX is not.
Community and resources: The PyG community is large. StackOverflow answers, tutorials, pre-trained models, integration with OGB, and a dedicated team maintaining it.
Heterogeneous graphs: PyG has mature support for heterogeneous graphs (HeteroData). TGraphX's heterogeneous graph support is labeled Experimental.
If your workflow fits into standard GNN benchmarks, or you are deploying a graph learning model in a production system, start with PyG. There is no compelling reason to switch frameworks for standard tasks.
What TGraphX Offers Differently
TGraphX was designed with a different assumption: that not all graph nodes should be described by flat vectors, and that research workflows benefit from explicit tooling for reproducibility and experiment management.
Tensor-valued nodes without manual shape management
In PyG, the standard node feature matrix is [N, D]. If you have image patches as nodes, you flatten them before building the graph:
# PyG approach — flatten first
x_patches = patches.view(N, -1) # [N, C*H*W]
data = Data(x=x_patches, edge_index=edge_index, y=labels)
In TGraphX, the shape is preserved natively:
# TGraphX approach — no flatten needed
import tgraphx as tgx
g = tgx.Graph(x=patches, edge_index=edge_index, labels=labels)
# patches shape: [N, C, H, W] — preserved through the graph container
Whether preserving shape is better depends on whether your model architecture benefits from spatial awareness in message passing. For many tasks, flattening is fine. But when you want to apply convolutional operations inside message passing, preserving shape is cleaner.
One-call reproducible workflows
TGraphX provides a context manager and one-call workflows designed to make experiments reproducible with minimal boilerplate:
with tgx.reproducible(seed=42, deterministic=True):
result = tgx.classify_nodes(
x=x, edge_index=edge_index, labels=y,
model="tensor_gcn",
)
PyG does not have an equivalent one-liner; reproducibility requires manual setup of seeds and determinism flags. TGraphX generates a reproducibility_report.json automatically alongside results.
Native .tgx format for tensor-valued graphs
Standard graph interchange formats (GraphML, GexF) were not designed for rank-4+ tensors. TGraphX's .tgx format (a torch.save() bundle) preserves full tensor metadata:
g.save("experiment.tgx")
g_loaded = tgx.Graph.load("experiment.tgx")
print(g_loaded.node_features.shape) # [N, C, H, W] — intact
Local experiment dashboard
TGraphX includes a local HTTP dashboard for viewing run artifacts, validation reports, and training history — accessible via tgraphx-dashboard --logdir runs/ without any cloud service or account.
Breadth of research modules
TGraphX ships knowledge graph learning (TransE, DistMult, ComplEx, RotatE), 13 graph RL algorithms, classical and experimental neural graph generation, evolutionary optimization, graph mining (motifs, centrality, WL features), and explainability utilities — all within a single pip install tgraphx. PyG focuses on its core GNN functionality; these adjacent capabilities require separate libraries in the PyG ecosystem.
Side-by-Side Code Comparison
Node classification — basic setup
PyG:
import torch
from torch_geometric.data import Data
from torch_geometric.nn import GCNConv
import torch.nn.functional as F
x = torch.randn(100, 32) # flat vectors
edge_index = torch.randint(0, 100, (2, 300))
y = torch.randint(0, 5, (100,))
data = Data(x=x, edge_index=edge_index, y=y)
class GCN(torch.nn.Module):
def __init__(self):
super().__init__()
self.conv1 = GCNConv(32, 64)
self.conv2 = GCNConv(64, 5)
def forward(self, x, edge_index):
x = F.relu(self.conv1(x, edge_index))
return self.conv2(x, edge_index)
TGraphX (one-call):
import torch
import tgraphx as tgx
x = torch.randn(100, 32)
edge_index = torch.randint(0, 100, (2, 300))
y = torch.randint(0, 5, (100,))
result = tgx.classify_nodes(
x=x, edge_index=edge_index, labels=y,
model="gcn", # or "tensor_gcn" for spatial inputs
seed=42,
)
TGraphX (explicit control):
from tgraphx import Graph, build_model, fit, NeighborLoader
g = tgx.Graph(x=x, edge_index=edge_index, labels=y)
model = build_model("node_classification", layer="gcn", in_shape=(32,), out_dim=5)
loader = NeighborLoader(g, num_neighbors=[10, 5], batch_size=32)
fit(model, graph=g, loader=loader, epochs=20)
When to Choose Each
Choose PyTorch Geometric if:
- Your task appears in standard GNN benchmarks (Cora, OGB, etc.)
- You need the widest selection of GNN layer architectures
- You are deploying a model in production
- You need extensive community support and pre-existing solutions
- Your node features are flat vectors
- You need heterogeneous graph support (mature in PyG, Experimental in TGraphX)
Consider TGraphX if:
- Your node features are naturally multi-dimensional (image patches, volumetric blocks, sequences)
- You want a framework that preserves tensor shapes through message passing without manual flattening
- You need integrated knowledge graph learning, graph RL, or evolutionary optimization alongside graph learning
- Experiment reproducibility tooling (seeding, artifact logging, dashboard) is a priority
- You are in a research context where explicitness and auditability matter more than ecosystem breadth
Both may be appropriate if:
- You need PyG's layer variety but also want TGraphX's reproducibility utilities — both can coexist in the same project. TGraphX includes adapters for PyG datasets, and a
tgx.Graphcan be converted to a PyGDataobject when needed.
Honest Limitations of TGraphX
TGraphX is an honest project that labels its subsystems accurately:
- Core graph containers, GNN layers, and sampling: Beta
- Neural graph generation, heterogeneous GNNs, temporal GNNs: Experimental
- It has not been benchmarked on billion-edge graphs
- Dense graph builders (kNN, radius) are O(N²)
- The spectral partitioner is limited to ≤ 4096 nodes
- There are no production deployment case studies documented
TGraphX does not claim to be faster, more accurate, or more mature than PyG. Those claims would be unsupported.
Conclusion
PyTorch Geometric is the right choice for most GNN tasks. It has a larger ecosystem, broader layer selection, production deployments, and more community resources.
TGraphX is a specialized framework for tensor-native graph research workflows — cases where node features are multi-dimensional, where explicit tensor-shape preservation through message passing is useful, and where integrated experiment management and reproducibility tooling matter.
Choosing between them is not an either/or for most users. Learn PyG for the standard GNN toolkit. Consider TGraphX when your specific research problem involves tensor-valued nodes or when reproducibility and explicit APIs are design priorities.
FAQ
Q: Can I use PyG layers inside TGraphX?
A: There is limited interoperability. TGraphX has PyG dataset adapters (pip install "tgraphx[pyg]"), so you can load PyG datasets into TGraphX's data structures. Direct layer-level mixing requires manual bridging.
Q: Does TGraphX replicate all PyG functionality?
A: No. PyG has a much broader selection of layer architectures, a larger benchmark-oriented codebase, and better production tooling. TGraphX does not try to replicate PyG — it targets a narrower design space.
Q: Is TGraphX slower than PyG?
A: There are no published throughput comparisons between TGraphX and PyG. The frameworks have different designs and different target use cases. Benchmarking them head-to-head would require careful experimental design to be fair.
Q: Should I switch from PyG to TGraphX?
A: Probably not, unless your specific use case is tensor-valued nodes and you find the TGraphX API cleaner for that use case. For standard GNN research, stay with PyG.
Q: Is TGraphX production-ready?
A: Not in the same sense as PyG. TGraphX labels most of its core as Beta and several subsystems as Experimental. It is a research-engineering framework, not a production deployment library.