RandomNodeLoader
¶
Splits the nodes of a graph into num_parts random partitions and
yields the subgraph induced by each partition, following PyG's
RandomNodeLoader.
Useful to train on large graphs that do not fit in memory, when the loss of
the edges between partitions is acceptable. With shuffle=True new
random partitions are drawn at each epoch, otherwise the partitions are
contiguous ranges of node ids.
Each batch is a GraphData with node- and edge-level attributes
sliced to the subgraph, plus n_id (global id of every node) and
e_id (original id of every edge).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
GraphData
|
The full graph. |
required |
num_parts
|
int
|
Number of partitions (batches per epoch). |
required |
shuffle
|
bool
|
Whether to draw new random partitions at each epoch. Defaults to False |
False
|
Example:
from mlx_graphs.loaders import RandomNodeLoader
loader = RandomNodeLoader(data, num_parts=10, shuffle=True)
for batch in loader:
out = model(batch.node_features, batch.edge_index)
Source code in mlx_graphs/loaders/random_node_loader.py
from mlx_graphs.loaders import RandomNodeLoader · mlx_graphs/loaders/random_node_loader.py