gigl.distributed.utils.ablp#

Utilities for remapping ABLP labels to sampled-subgraph indices.

Tensor dimensions used in this module:

  • A: anchors in one sampled batch.

  • M: padded label slots per anchor.

  • S: sampled nodes for one supervision node type.

  • K: non-padding candidate labels.

  • E: output label pairs; E == K because sampling always includes labels.

A label edge index has shape [2, E]. Row 0 indexes anchors in [0, A); row 1 indexes local nodes in the supervision node store in [0, S).

Example:

# Padded global labels: [A=3, M=2]
label_tensor = [[30, -1], [40, 10], [-1, -1]]

# Sampled supervision nodes: local id -> global id, [S=3]
local_id_to_global_id = [40, 10, 30]

# Local label edge index: [2, E=3]
label_edge_index = [[0, 1, 1], [2, 0, 1]]

# Deprecated dictionary view of the same output
labels_by_anchor = {0: [2], 1: [0, 1], 2: []}

The corresponding label relationships are shown below. Anchor 2 has no label edge because both of its input slots are padding.

digraph ablp_labels {
  rankdir=LR;
  node [fontname="Helvetica"];
  a0 [label="anchor 0", shape=box];
  a1 [label="anchor 1", shape=box];
  a2 [label="anchor 2", shape=box];
  n0 [label="local 0\nglobal 40"];
  n1 [label="local 1\nglobal 10"];
  n2 [label="local 2\nglobal 30"];
  a0 -> n2 [label="global label 30", color="forestgreen", style=dashed];
  a1 -> n0 [label="global label 40", color="forestgreen", style=dashed];
  a1 -> n1 [label="global label 10", color="forestgreen", style=dashed];
}

Functions#

label_edge_index_to_dict(label_edge_index, num_anchors)

Convert a label edge index to the deprecated per-anchor dictionary.

remap_labels_to_local_edge_indices(...)

Remap padded global ABLP labels to local label edge indices.

Module Contents#

gigl.distributed.utils.ablp.label_edge_index_to_dict(label_edge_index, num_anchors)[source]#

Convert a label edge index to the deprecated per-anchor dictionary.

The edge index must be grouped by anchor, as guaranteed by remap_labels_to_local_edge_indices().

Parameters:
  • label_edge_index (torch.Tensor) – [2, E] local label edge index. Row 0 contains anchor indices in [0, A); row 1 contains local label-node indices. Pairs must be grouped by row-0 anchor index.

  • num_anchors (int) – A, including anchors with no labels.

Returns:

Every local anchor index in [0, A) mapped to a [E_a] tensor of local label-node indices, where sum(E_a) == E.

Return type:

dict[int, torch.Tensor]

Example

>>> label_edge_index_to_dict(
...     torch.tensor([[0, 1, 1], [2, 0, 1]]), num_anchors=3
... )
{0: tensor([2]), 1: tensor([0, 1]), 2: tensor([], dtype=torch.int64)}
gigl.distributed.utils.ablp.remap_labels_to_local_edge_indices(local_id_to_global_id_by_node_type, positive_labels_by_edge_type, negative_labels_by_edge_type)[source]#

Remap padded global ABLP labels to local label edge indices.

Positive and negative labels share one sorted node lookup per supervision node type. Pair order within an anchor is unspecified; row-0 anchor indices remain grouped in ascending order.

Parameters:
  • local_id_to_global_id_by_node_type (dict[gigl.src.common.types.graph_data.NodeType, torch.Tensor]) – Per node type t, [S_t] global ids where index i is the local node id.

  • positive_labels_by_edge_type (dict[torch_geometric.typing.EdgeType, torch.Tensor]) – Per positive-label edge type et, [A_et, M_et] padded global label-node ids.

  • negative_labels_by_edge_type (dict[torch_geometric.typing.EdgeType, torch.Tensor]) – Equivalent [A_et, M_et] negative label tensors. May be empty.

Returns:

Positive and negative mappings keyed by message-passing edge type. Each value is a [2, E_et] local label edge index whose rows index the corresponding anchor batch and supervision node store.

Return type:

tuple[dict[torch_geometric.typing.EdgeType, torch.Tensor], dict[torch_geometric.typing.EdgeType, torch.Tensor]]

Example

With destination local-to-global ids [40, 10, 30], positive labels [[30, -1]] map to [[0], [2]] and negative labels [[40, 10]] map to [[0, 0], [0, 1]]. The returned positive and negative dictionaries retain these edge indices under their message-passing edge types.