TGraphX › Insights › Where Tensor-Native Graph Learning Fits in the GNN Ecosystem
← Back to Insights

Where Tensor-Native Graph Learning Fits in the GNN Ecosystem

Topic: Framework comparisons and interoperability

The useful way to position a research framework is by what it adds to the tools you already have. This article explains what "tensor-native" graph learning means in code, what general GNN libraries can already do with tensor-valued features, and where TGraphX fits beside them.

It builds on the comparisons in TGraphX vs PyTorch Geometric and the tool-selection matrix. For task-by-task tool choices, use the matrix; this page is about the underlying distinction.

What "tensor-native" means

In many graph benchmarks each node has a feature vector, so node features are [N, F]. In other problems each node is itself a structured array: an image patch or region as [C, H, W], a volumetric block as [C, D, H, W]. Tensor-native message passing keeps that layout, which allows messages to be computed with convolutions instead of on a flattened vector. The question is also the subject of the TGraphX arXiv preprint, "Tensor-Aware Graph Neural Network for Multi-Dimensional Feature Learning" (Sajjadi and Eramian, 2025).

TGraphX ships layers that take these shapes directly, but they differ in what they do with the spatial axes:

  • TensorGraphSAGELayer, TensorGATLayer and TensorGINLayer use 1×1 convolutions by default (1×1×1 for volumes). They mix channels at each position and do not mix neighbouring pixels or voxels. TensorGATLayer also averages each projected map over its spatial axes to compute one attention weight per edge and head, which rescales the whole message.
  • ConvMessagePassing is the shipped message-passing layer that adds 3×3 convolutions (3×3×3 for volumes), applied to the aggregated messages, so each output position draws on a neighbourhood of positions.

For [N, C, D, H, W] nodes, construct the three Tensor* layers with spatial_rank=3; with the default of 2 they raise ValueError on a volume. ConvMessagePassing takes the rank from the shape you give it. Examples tested with TGraphX 1.5.1 and PyTorch Geometric 2.8.1 on CPU.

python
import torch
from torch import nn
from tgraphx import ConvMessagePassing, TensorGraphSAGELayer

torch.manual_seed(0)
x = torch.randn(5, 3, 8, 8)                      # 5 nodes, each a [3, 8, 8] feature map
edge_index = torch.tensor([[0, 1, 2, 3], [1, 2, 3, 4]])

sage = TensorGraphSAGELayer(3, 16)               # 1x1 convolutions only
print(sage(x, edge_index).shape)                 # torch.Size([5, 16, 8, 8])

conv = ConvMessagePassing((3, 8, 8), (16, 8, 8), dropout_prob=0.0)   # adds 3x3
print(conv(x, edge_index).shape)                 # torch.Size([5, 16, 8, 8])

volumes = torch.randn(5, 3, 4, 4, 4)             # [N, C, D, H, W]
sage3d = TensorGraphSAGELayer(3, 16, spatial_rank=3)
print(sage3d(volumes, edge_index).shape)         # torch.Size([5, 16, 4, 4, 4])

The two image-valued outputs have the same shape, so the shape alone does not tell you whether a layer used spatial context.

General libraries can hold tensors too

It would be wrong to say that PyTorch Geometric only supports flat vectors. A Data object stores node tensors of any trailing shape, and MessagePassing has a node_dim argument that says which axis indexes the nodes. With node_dim=0 and a convolutional update network, PyG's GINConv processes image-valued nodes (this block needs torch_geometric, which TGraphX does not depend on):

python
from torch_geometric.data import Data
from torch_geometric.nn import GCNConv, GINConv

data = Data(x=x, edge_index=edge_index)          # stored as [N, C, H, W]
gin = GINConv(nn.Conv2d(3, 16, kernel_size=3, padding=1), node_dim=0)
print(gin(data.x, data.edge_index).shape)        # torch.Size([5, 16, 8, 8])

# Silent mistake: a vector layer applied to the same tensor
print(GCNConv(8, 16)(data.x, data.edge_index).shape)   # torch.Size([5, 3, 8, 16])

The last line raises no error, but it is not doing graph learning on your nodes. GCNConv takes the second-to-last axis as the node axis and the last as features, so here it passes messages between rows of each feature map and the five nodes never exchange information. You can write your own MessagePassing subclass with node_dim=0 for other designs. DGL likewise stores node features of any trailing shape in ndata; check each built-in module's documented input shapes before using one.

So the difference is not what can be stored. It is what comes ready-made: the common convolution layers in general libraries are written for feature vectors, while TGraphX provides TensorGraphSAGELayer, TensorGATLayer, TensorGINLayer and ConvMessagePassing for [N, C, H, W] and [N, C, D, H, W] nodes (the latter with spatial_rank=3 on the Tensor* layers), plus vector layers such as GCNConv and GATv2Conv. It has no layer designed for sequence-valued [N, T, D] nodes; some vector layers accept them silently, without modelling time.

The ecosystem, by focus

Tool Primary focus Typical node data
PyTorch Geometric general-purpose GNN library: many layers, datasets, samplers vectors in most built-in layers; other shapes with node_dim and custom modules
DGL general-purpose GNN library, including distributed tooling vectors in most built-in modules; any trailing shape can be stored
NetworkX graph algorithms and analysis, no neural layers arbitrary Python objects as attributes
PyKEEN knowledge-graph embedding models and evaluation learned entity and relation representations
Stable-Baselines3, RLlib general reinforcement learning environment observations, not graph-specific
TGraphX (Beta) tensor-aware message passing plus research utilities [N, D], [N, C, H, W], [N, C, D, H, W]

TGraphX's README states its own position this way: "TGraphX focuses on a different integration point: tensor-aware graph learning, graph mining, reproducible experiments, and dashboard-ready research workflows in one package."

Complementary, not competitive

TGraphX is designed to sit alongside these tools:

  • It converts to and from PyG and DGL objects with tgraphx.interop and has adapters for PyG, OGB and DGL datasets (covered in the interop article). The PyG converters carry train, validation and test masks in neither direction: from_pyg_data drops data.train_mask and its companions, and to_pyg_data does not create them (TGraphX masks only travel inside data.metadata). The DGL converters map no masks either, going by their source (DGL was not run here). Set the masks again yourself after converting.
  • Its knowledge-graph module implements standard scoring models such as TransE, DistMult and ComplEx. PyKEEN is dedicated to that area and has a much larger catalogue.
  • Its reinforcement-learning module works on graph environments and is marked Experimental. For general reinforcement learning, Stable-Baselines3 and RLlib are the usual tools.

The README says TGraphX is "built to complement and interoperate with mature graph ecosystems", and that its converters do not make it a drop-in replacement for PyG or DGL. The general argument is made in why small GNN frameworks coexist with PyG and DGL.

How to describe this in a paper

A conservative framing:

TGraphX is a tensor-aware graph learning library for PyTorch research workflows. It provides message-passing layers for graph data in which nodes carry structured tensor representations (for example [C, H, W] feature maps), and it can be used alongside general GNN libraries such as PyTorch Geometric and DGL.

State the version you ran, and do not turn the framing into a performance claim. For the BibTeX entry and a methods-section paragraph, see how to cite and describe TGraphX.

When not to use it

TGraphX is Beta, with a smaller ecosystem and community than PyG or DGL, which matters for long-lived or production code. Whether keeping tensor structure helps is task-dependent and has to be measured against a flattened or pooled-vector baseline. And for vector-feature problems, an established general library is usually the simpler choice.

A two-question check

  1. Do my nodes have internal structure that matters, such as image regions or volumes, rather than flat embeddings or scalar attributes? If not, you do not need tensor-native layers.
  2. Do I need large-scale or distributed training now? If so, start from the libraries built around it, and use node_dim or custom modules if your features are tensors.

If the answers are "yes" and "no", TGraphX's ready-made tensor layers are worth trying.

Related guides