gigl.distributed.utils.degree#

Utility functions for computing node degrees in distributed graph settings.

This module provides functions to compute node out-degrees from graph partitions and aggregate them across distributed machines. Degrees are computed from the CSR (Compressed Sparse Row) topology stored in GraphLearn-Torch Graph objects.

Note: Degree tensors are not moved to shared memory and may be duplicated across processes on the same machine.

Requirements#

torch.distributed must be initialized before calling these functions.

Usage#

Access dataset.degree_tensor to lazily compute and cache the degree tensor.

Over-counting correction is handled automatically in _all_reduce_degrees by detecting how many processes share the same machine (and thus the same data).

Attributes#

Functions#

compute_and_broadcast_degree_tensor(graph)

Compute node degrees from a graph and aggregate across all machines.

Module Contents#

gigl.distributed.utils.degree.compute_and_broadcast_degree_tensor(graph)[source]#

Compute node degrees from a graph and aggregate across all machines.

Computes degrees from the CSR row pointers (indptr) and performs all-reduce to aggregate across ranks.

Over-counting correction (for processes sharing the same data) is handled automatically by detecting the distributed topology.

Parameters:

graph (Union[graphlearn_torch.data.Graph, dict[torch_geometric.typing.EdgeType, graphlearn_torch.data.Graph]]) – A Graph (homogeneous) or dict[EdgeType, Graph] (heterogeneous).

Returns:

The aggregated degree tensors.
  • For homogeneous graphs: A tensor of shape [num_nodes].

  • For heterogeneous graphs: A dict mapping EdgeType to degree tensors.

Return type:

Union[torch.Tensor, dict[EdgeType, torch.Tensor]]

Raises:
  • RuntimeError – If torch.distributed is not initialized.

  • ValueError – If topology is unavailable.

gigl.distributed.utils.degree.logger[source]#