TGraphX vs DGL: A Practical Comparison for Graph Learning Research
Deep Graph Library (DGL) and TGraphX are both graph learning libraries that work with PyTorch, but they were built with different goals. This page is the feature-and-API comparison: project status, data model, message passing, tensor-valued node features, and how to move a graph between the two.
What was checked, and how. The TGraphX examples were tested with TGraphX 1.5.1 on CPU. DGL statements are based on the DGL 2.4.0 source code, the project's release notes and announcements, and its package listings on PyPI and the dglteam conda channel, checked on 26 November 2026. DGL was not installed, so the DGL snippets below were not executed.
What each library is
DGL was introduced by Wang et al., Deep Graph Library: A Graph-Centric, Highly-Performant Package for Graph Neural Networks (arXiv:1909.01315, 2019). Graphs are DGLGraph objects that carry node and edge tensors in the ndata and edata dictionaries, and message passing is expressed as a message function plus a reduce function. It has a compiled C++/CUDA core, a large set of layers, and support for multi-machine training. DGL was designed to be framework-agnostic and has had MXNet and TensorFlow backends; the DGL team has announced the deprecation of both, so treat it as a PyTorch library for new work.
TGraphX is a Beta-status, MIT-licensed library for PyTorch only. Its distinctive choice is that a node feature can be a tensor such as [C, H, W] or [C, D, H, W], and it ships message-passing layers that keep those spatial axes. The same package also contains graph mining, knowledge graph embedding, graph generation, evolutionary search, graph reinforcement learning and a local dashboard; several of these areas are Experimental.
Project status and installation
DGL, as of 26 November 2026:
- The
dgl.aidomain was showing as expired. On that date it served a registrar page reading "Domain registration has expired". DGL's website, documentation, forum and data hosts under that domain, including the install page that the README links to, were not usable. A report on DGL's issue tracker describes the same thing. Use the GitHub repository for the source code and issues. - The newest release tag on GitHub is v2.4.0, from September 2024. The repository is not archived.
- The newest
dglon PyPI is older than that tag: 2.2.1, with Windows wheels only. The newest Linux x86-64 wheel on PyPI is 2.1.0. - The
dglteamconda channel does list Linux x86-64 builds of 2.4.0, under the labelsth21_*toth24_*: that is, for PyTorch 2.1 to 2.4 and no later, with Python 3.8 to 3.12. The newest Linux x86-64 build under the defaultmainlabel is 2.1.0.
Do not download datasets or wheels from any *.dgl.ai address until you can confirm that the DGL project controls the domain again. Whoever controls an expired domain decides what its hosts serve. In practice:
- Skip
pip installcommands that point athttps://data.dgl.ai/wheels/. - Do not start a download through
dgl.data. Many of its built-in datasets, including Cora, CiteSeer and PubMed, download fromdata.dgl.aiby default. In DGL 2.4.0 the citation datasets are fetched without a checksum and then read withpickle, which can run code stored in the file. - TGraphX's
dgl:cora,dgl:citeseeranddgl:pubmeddataset names construct those same DGL classes, so avoid them too. - If DGL is not installed, some TGraphX 1.5.1 error messages point to a
dgl.aiinstall page. Do not follow that link for now.
DGL's compiled libraries are tied to specific PyTorch and CUDA versions, and those 2.4.0 conda packages declare no PyTorch dependency, so match the versions yourself. This matters if you want both libraries in one environment. TGraphX only requires torch 1.13 or newer and Python 3.10 or newer, so DGL sets the ceiling: PyTorch 2.4 and Python 3.12 for the 2.4.0 builds. No DGL install command was tested for this page, so none is given.
TGraphX 1.5.1 is a pure-Python package with no compiled extensions. It requires Python 3.10 or newer, torch 1.13 or newer, torchvision 0.14 or newer and pyyaml.
# TGraphX
pip install tgraphx
If your real choice is between DGL and PyTorch Geometric, that comparison looks at release status, install limits and parity of the same layers in both.
Feature comparison
| Capability | DGL 2.4.0 | TGraphX 1.5.1 |
|---|---|---|
| Framework | PyTorch (MXNet and TensorFlow backends deprecated) | PyTorch only |
| Compiled kernels | C++/CUDA core | None |
| Graph data | DGLGraph with ndata / edata dictionaries |
Graph with named fields (features, edge weights, labels, masks) plus metadata |
| Tensor-valued node features | Stored in ndata; built-in message and reduce functions keep extra dimensions; GraphConv and GATConv act on the last axis of (N, *, in_feats); no spatial convolutions in dgl.nn |
Stored; built-in spatial layers for [N, C, H, W] and [N, C, D, H, W] |
| Vector-feature layers | Large collection (over 30 convolution modules) | Small set, for example GCNConv, GATv2Conv, APPNP |
| Heterogeneous graphs | Core feature: dgl.heterograph, HeteroGraphConv, relational and HGT layers |
HeteroGraph and heterogeneous layers, labelled Experimental |
| Temporal graphs | Temporal sampling in GraphBolt; the TGN example lives on the 0.9.x branch; no TGAT or TGN layer in dgl.nn |
TemporalGraphSequence, TGATConv, TGNMemory (Experimental) |
| Mini-batch sampling | NeighborSampler, ClusterGCNSampler, SAINTSampler with dgl.dataloading.DataLoader; GraphBolt |
NeighborLoader, LinkNeighborLoader, GraphSAINT samplers, Cluster-GCN loader (no METIS) |
| Multi-machine training | dgl.distributed: graph partitioning and DistGraph |
No distributed graph store; helpers for ranks, sharding and DDP wrapping |
| Knowledge graphs | TransE and TransR scoring modules in dgl.nn; separate DGL-KE package |
tgraphx.kg: embedding models, negative sampling, trainer, filtered ranking |
| Explainability | GNNExplainer, PGExplainer, SubgraphX modules |
Gradient and perturbation attributions in tgraphx.explain |
| Mining, generation, evolutionary search, graph RL | Not separate subsystems of the core package (helpers such as dgl.rand_graph exist) |
Included; labels differ by source: classical generation and evolutionary optimization are Beta in the README and partly experimental in the registry; neural generation and graph RL learning algorithms are Experimental |
| Seeding | dgl.seed for DGL's own generator |
set_seed, reproducible, reproducibility_report |
| Dashboard | None built in | Local, read-only dashboard |
A row that says one library has something built in is not a statement about quality or speed.
Message passing
DGL splits a layer into a message function and a reduce function. This layer averages the incoming neighbour features and applies a linear map. It is a mean-aggregation layer, not GCN: there are no self-loops and no symmetric degree normalisation.
import dgl.function as fn
import torch.nn as nn
class DGLMeanLayer(nn.Module):
def __init__(self, in_dim, out_dim):
super().__init__()
self.lin = nn.Linear(in_dim, out_dim)
def forward(self, graph, feat):
with graph.local_scope():
graph.ndata["h"] = feat
graph.update_all(fn.copy_u("h", "m"), fn.mean("m", "h_agg"))
return self.lin(graph.ndata["h_agg"])
In TGraphX you subclass TensorMessagePassingLayer and override message() and update(). This is the same layer, checked against a hand-written mean:
import torch
import torch.nn as nn
from tgraphx import TensorMessagePassingLayer
class TGXMeanLayer(TensorMessagePassingLayer):
def __init__(self, in_dim, out_dim):
super().__init__(in_shape=(in_dim,), out_shape=(out_dim,), aggr="mean")
self.lin = nn.Linear(in_dim, out_dim)
def message(self, src, dest, edge_attr):
return src # the role of fn.copy_u
def update(self, node_feature, aggregated_message):
return self.lin(aggregated_message)
torch.manual_seed(0)
x = torch.randn(5, 4)
# edges point from row 0 to row 1; nodes 1 and 4 receive nothing
edge_index = torch.tensor([[0, 1, 2, 3],
[2, 2, 3, 0]])
layer = TGXMeanLayer(4, 3)
out = layer(x, edge_index)
mean = torch.zeros(5, 4)
mean[2] = (x[0] + x[1]) / 2
mean[3] = x[2]
mean[0] = x[3]
assert torch.allclose(out, layer.lin(mean))
print(out.shape) # torch.Size([5, 3])
For a node with no incoming edges, both versions aggregate to zeros before the linear map.
Both libraries therefore allow custom per-edge computations. The difference is in reduction: a user-defined DGL reduce function receives each node's incoming messages as a "mailbox", which is convenient for order-dependent aggregators, whereas in TGraphX you override aggregate() and write the indexing yourself.
One behaviour matters when you port a GCN. DGL's GraphConv raises an error by default if any node has no incoming edge (add self-loops, or pass allow_zero_in_degree=True). TGraphX's GCNConv adds self-loops by default:
from tgraphx import GCNConv
print(GCNConv(4, 3)(x, edge_index).shape) # torch.Size([5, 3]), nodes 1 and 4 included
Tensor-valued node features
DGL does not force vectors: any tensor whose first dimension is the number of nodes can go into ndata, and the built-in message and reduce functions keep the remaining dimensions. GraphConv and GATConv also document inputs of shape (N, *, in_feats), where * is any number of extra dimensions. A channels-last [N, H, W, C] tensor can therefore go straight in: the linear map acts on the last axis only, so each position is handled separately, much like a 1x1 convolution, with no spatial mixing.
What dgl.nn does not ship is a spatial (2-D or 3-D) convolution over node feature maps. If pixels or voxels have to mix, you compose that part yourself. For example, GINConv sums neighbour features, adds the node's own and then calls apply_func, so by its implementation a 2-D convolution can be used there (the docstring describes vector input, and this snippet was not run):
import dgl
import torch
import torch.nn as nn
from dgl.nn import GINConv
graph = dgl.graph((torch.randint(0, 50, (200,)), torch.randint(0, 50, (200,))), num_nodes=50)
x = torch.randn(50, 16, 8, 8)
conv = GINConv(apply_func=nn.Conv2d(16, 32, kernel_size=3, padding=1), aggregator_type="sum")
out = conv(graph, x) # the sum keeps [C, H, W]
TGraphX ships such layers:
import torch
from tgraphx import ConvMessagePassing, Graph, TensorGINLayer
torch.manual_seed(0)
g = Graph(node_features=torch.randn(50, 16, 8, 8), # [N, C, H, W]
edge_index=torch.randint(0, 50, (2, 200))) # [2, E]
conv = ConvMessagePassing(in_shape=(16, 8, 8), out_shape=(32, 8, 8), dropout_prob=0.0)
gin = TensorGINLayer(16, 32)
print(conv(g.node_features, g.edge_index).shape) # torch.Size([50, 32, 8, 8])
print(gin(g.node_features, g.edge_index).shape) # torch.Size([50, 32, 8, 8])
The layers are not interchangeable. TensorGINLayer uses 1x1 convolutions and never mixes pixel positions, while ConvMessagePassing also applies 3x3 convolutions in its aggregator. TGraphX has no layer designed for sequence-shaped node features [N, T, D]; LinearMessagePassing and the legacy AttentionMessagePassing run on them silently, which is not sequence support.
Moving graphs between DGL and TGraphX
TGraphX ships converters in tgraphx.interop: to_dgl_graph, from_dgl_graph, to_dgl_heterograph and from_dgl_heterograph. They need DGL to be installed.
The example builds a small graph in memory, so nothing is downloaded. It uses the key names of DGL's citation datasets, which differ from the converter's defaults.
import dgl
import torch
from tgraphx import Graph
from tgraphx.interop import from_dgl_graph, to_dgl_graph
# a six-node ring with the keys "feat", "label" and the three "*_mask" entries
src = torch.tensor([0, 1, 2, 3, 4, 5])
dst = torch.tensor([1, 2, 3, 4, 5, 0])
dgl_g = dgl.graph((src, dst), num_nodes=6)
dgl_g.ndata["feat"] = torch.randn(6, 8)
dgl_g.ndata["label"] = torch.tensor([0, 1, 2, 0, 1, 2])
dgl_g.ndata["train_mask"] = torch.tensor([True, True, True, False, False, False])
dgl_g.ndata["val_mask"] = torch.tensor([False, False, False, True, False, False])
dgl_g.ndata["test_mask"] = torch.tensor([False, False, False, False, True, True])
# the converter's defaults are "x" and "y", so name the keys
g = from_dgl_graph(dgl_g, node_feature_key="feat", node_label_key="label")
# masks are not copied, so rebuild the graph with them. Pass the edge data on too,
# or it is lost (both are None here, which Graph accepts)
g = Graph(node_features=g.node_features, edge_index=g.edge_index, y=g.node_labels,
edge_weight=g.edge_weight, edge_features=g.edge_features,
train_mask=dgl_g.ndata["train_mask"],
val_mask=dgl_g.ndata["val_mask"],
test_mask=dgl_g.ndata["test_mask"])
back = to_dgl_graph(g) # writes ndata["x"], ndata["y"] and, if present, edata["w"], edata["e"]
Check these four points on your own data:
- If the feature key is wrong,
from_dgl_graphraises aValueErrorthat lists the available keys. If the label key is wrong, there is no error: the TGraphX graph simply has no labels. - Train, validation and test masks are not transferred in either direction.
- Edge weights and edge features are read from
edata["w"]andedata["e"]unless you pass other keys. A missing edge key, or an edge weight that is not 1-D (for example[E, 1]), is skipped without an error, so checkg.edge_weightandg.edge_featuresafter converting. Edge features need at least two dimensions, so a 1-Dedata["e"]raises aValueError. - The converter is written for ordinary graphs (it reads
g.ndataandg.edges()), not for the bipartite blocks that DGL's sampling data loaders produce.
For heterogeneous graphs, from_dgl_heterograph requires every node type to have the feature key you name. TGraphX's HeteroGraph does not range-check edge indices, so verify them if you build or edit the stores yourself.
If you use both libraries in one script, seed both. tgraphx.reproducibility.set_seed seeds Python, NumPy and PyTorch; DGL's generator is separate and is seeded with dgl.seed.
When DGL is the better choice
- You need multi-machine training on a partitioned graph.
dgl.distributedprovides this; TGraphX does not have a distributed graph store. - Heterogeneous graphs are central to your work. They are a core part of DGL and an Experimental part of TGraphX.
- You want many established vector-feature layers for baselines and ablations.
- You want compiled kernels for large graphs. DGL has C++/CUDA kernels and built-in message and reduce functions. This page measures nothing, so benchmark your own workload.
When TGraphX is the better fit
- Your node features are image patches or volumes and you want ready-made spatial message-passing layers.
- You want a graph library with no compiled extensions of its own. It still requires torchvision, which is compiled and has to match your PyTorch build.
- You want mining, knowledge graph or generation utilities next to the layers, and you accept their Beta or Experimental status.
Limitations of this comparison
- DGL was not installed or executed. Check anything you depend on against the DGL version you actually use.
- There are no speed or memory measurements here. Such numbers depend on graph size, batch size, layer type, hardware and library versions; see TGraphX benchmark disclaimers.
- Both projects change. Older DGL tutorials may use APIs that have since moved, for example heterogeneous graphs are now ordinary
DGLGraphobjects.
Related articles
- Porting a
[C, H, W]node classifier between DGL and TGraphX: the workflow view of the same choice - Interoperability with PyG, OGB and DGL: dataset conversion in more detail
- TGraphX vs PyTorch Geometric: the PyG comparison
- TGraphX vs PyKEEN: knowledge graph tooling
- TGraphX vs NetworkX: analytics versus learning
- What is a TGX graph: the TGraphX data model
- Neighbor sampling with TGraphX: TGraphX's sampling API