Skip to main content
Ctrl+K

GiGL

  • User Guide
  • API Reference
  • GitHub
  • User Guide
  • API Reference
  • GitHub

Section Navigation

  • gigl
    • gigl.analytics
      • gigl.analytics.graph_validation
        • gigl.analytics.graph_validation.bq_graph_validator
    • gigl.common
      • gigl.common.beam
        • gigl.common.beam.better_tfrecordio
        • gigl.common.beam.coders
      • gigl.common.collections
        • gigl.common.collections.frozen_dict
        • gigl.common.collections.itertools
        • gigl.common.collections.sorted_dict
      • gigl.common.constants
      • gigl.common.data
        • gigl.common.data.dataloaders
        • gigl.common.data.export
        • gigl.common.data.load_torch_tensors
      • gigl.common.env_config
      • gigl.common.logger
      • gigl.common.metrics
        • gigl.common.metrics.base_metrics
        • gigl.common.metrics.decorators
        • gigl.common.metrics.metrics_interface
      • gigl.common.services
        • gigl.common.services.dataproc
        • gigl.common.services.gcp_cloud_logging
        • gigl.common.services.vertex_ai
      • gigl.common.types
        • gigl.common.types.resource_config
        • gigl.common.types.uri
        • gigl.common.types.wrappers
      • gigl.common.utils
        • gigl.common.utils.compute
        • gigl.common.utils.dataflow
        • gigl.common.utils.decorator
        • gigl.common.utils.func_tools
        • gigl.common.utils.gcs
        • gigl.common.utils.jupyter_magics
        • gigl.common.utils.kfp
        • gigl.common.utils.local_fs
        • gigl.common.utils.os_utils
        • gigl.common.utils.proto_utils
        • gigl.common.utils.retry
        • gigl.common.utils.tensorflow_schema
        • gigl.common.utils.test_utils
        • gigl.common.utils.torch_training
        • gigl.common.utils.vertex_ai_context
    • gigl.distributed
      • gigl.distributed.constants
      • gigl.distributed.dataset_factory
      • gigl.distributed.dist_context
      • gigl.distributed.dist_link_prediction_dataset
      • gigl.distributed.dist_partitioner
      • gigl.distributed.dist_range_partitioner
      • gigl.distributed.distributed_neighborloader
      • gigl.distributed.utils
        • gigl.distributed.utils.device
        • gigl.distributed.utils.init_neighbor_loader_worker
        • gigl.distributed.utils.partition_book
        • gigl.distributed.utils.serialized_graph_metadata_translator
    • gigl.env
      • gigl.env.dep_constants
      • gigl.env.pipelines_config
    • gigl.orchestration
      • gigl.orchestration.kubeflow
        • gigl.orchestration.kubeflow.kfp_orchestrator
        • gigl.orchestration.kubeflow.kfp_pipeline
        • gigl.orchestration.kubeflow.runner
        • gigl.orchestration.kubeflow.utils
      • gigl.orchestration.local
        • gigl.orchestration.local.runner
    • gigl.src
      • gigl.src.applied_tasks
        • gigl.src.applied_tasks.test_tasks
      • gigl.src.common
        • gigl.src.common.constants
        • gigl.src.common.graph_builder
        • gigl.src.common.modeling_task_specs
        • gigl.src.common.models
        • gigl.src.common.translators
        • gigl.src.common.types
        • gigl.src.common.utils
      • gigl.src.config_populator
        • gigl.src.config_populator.config_populator
      • gigl.src.data_preprocessor
        • gigl.src.data_preprocessor.data_preprocessor
        • gigl.src.data_preprocessor.lib
      • gigl.src.inference
        • gigl.src.inference.inferencer
        • gigl.src.inference.lib
        • gigl.src.inference.v1
        • gigl.src.inference.v2
      • gigl.src.mocking
        • gigl.src.mocking.dataset_asset_mocker
        • gigl.src.mocking.dataset_asset_mocking_suite
        • gigl.src.mocking.lib
        • gigl.src.mocking.mocking_assets
        • gigl.src.mocking.toy_asset_mocker
      • gigl.src.post_process
        • gigl.src.post_process.lib
        • gigl.src.post_process.post_processor
        • gigl.src.post_process.utils
      • gigl.src.split_generator
        • gigl.src.split_generator.split_generator
      • gigl.src.subgraph_sampler
        • gigl.src.subgraph_sampler.lib
        • gigl.src.subgraph_sampler.subgraph_sampler
      • gigl.src.training
        • gigl.src.training.trainer
        • gigl.src.training.v1
        • gigl.src.training.v2
      • gigl.src.validation_check
        • gigl.src.validation_check.config_validator
        • gigl.src.validation_check.libs
    • gigl.types
      • gigl.types.graph
    • gigl.utils
      • gigl.utils.data_splitters
      • gigl.utils.share_memory
  • snapchat
    • snapchat.research
      • snapchat.research.gbml
        • snapchat.research.gbml.dataset_metadata_pb2
        • snapchat.research.gbml.flattened_graph_metadata_pb2
        • snapchat.research.gbml.gbml_config_pb2
        • snapchat.research.gbml.gigl_resource_config_pb2
        • snapchat.research.gbml.graph_schema_pb2
        • snapchat.research.gbml.inference_metadata_pb2
        • snapchat.research.gbml.postprocessed_metadata_pb2
        • snapchat.research.gbml.preprocessed_metadata_pb2
        • snapchat.research.gbml.subgraph_sampling_strategy_pb2
        • snapchat.research.gbml.trained_model_metadata_pb2
        • snapchat.research.gbml.training_samples_schema_pb2
  • API Reference
  • gigl
  • gigl.distributed
  • gigl.distributed.dist_link_prediction_dataset

gigl.distributed.dist_link_prediction_dataset#

Attributes#

logger

Classes#

DistLinkPredictionDataset

This class is inherited from GraphLearn-for-PyTorch's DistDataset class. We override the __init__ functionality to support positive and

Module Contents#

class gigl.distributed.dist_link_prediction_dataset.DistLinkPredictionDataset(rank, world_size, edge_dir, graph_partition=None, node_feature_partition=None, edge_feature_partition=None, node_partition_book=None, edge_partition_book=None, positive_edge_label=None, negative_edge_label=None, node_ids=None, num_train=None, num_val=None, num_test=None)[source]#

Bases: graphlearn_torch.distributed.dist_dataset.DistDataset

This class is inherited from GraphLearn-for-PyTorch’s DistDataset class. We override the __init__ functionality to support positive and negative edges and labels. We also override the share_ipc function to correctly serialize these new fields. We additionally introduce a build function for storing the partitioned inside of this class. We assume data in this class is only in the CPU RAM, and do not support data on GPU memory, thus simplifying the logic and tooling required compared to the base DistDataset class.

Initializes the fields of the DistLinkPredictionDataset class. This function is called upon each serialization of the DistLinkPredictionDataset instance. :param rank: Rank of the current process :type rank: int :param world_size: World size of the current process :type world_size: int :param edge_dir: Edge direction of the provied graph :type edge_dir: Literal[“in”, “out”]

The below arguments are only expected to be provided when re-serializing an instance of the DistLinkPredictionDataset class after build() has been called

graph_partition (Optional[Union[Graph, Dict[EdgeType, Graph]]]): Partitioned Graph Data node_feature_partition (Optional[Union[Feature, Dict[NodeType, Feature]]]): Partitioned Node Feature Data edge_feature_partition (Optional[Union[torch.Tensor, Dict[EdgeType, torch.Tensor]]]): Partitioned Edge Feature Data node_partition_book (Optional[Union[PartitionBook, Dict[NodeType, PartitionBook]]]): Node Partition Book edge_partition_book (Optional[Union[PartitionBook, Dict[EdgeType, PartitionBook]]]): Edge Partition Book positive_edge_label (Optional[Union[torch.Tensor, Dict[EdgeType, torch.Tensor]]]): Positive Edge Label Tensor negative_edge_label (Optional[Union[torch.Tensor, Dict[EdgeType, torch.Tensor]]]): Negative Edge Label Tensor node_ids (Optional[Union[torch.Tensor, Dict[NodeType, torch.Tensor]]]): Node IDs on the current machine num_train: (Optional[Mapping[NodeType, int]]): Number of training nodes on the current machine. Will be a dict if heterogeneous. num_val: (Optional[Mapping[NodeType, int]]): Number of validation nodes on the current machine. Will be a dict if heterogeneous. num_test: (Optional[Mapping[NodeType, int]]): Number of test nodes on the current machine. Will be a dict if heterogeneous.

Parameters:
  • rank (int)

  • world_size (int)

  • edge_dir (Literal['in', 'out'])

  • graph_partition (Optional[Union[graphlearn_torch.data.Graph, Dict[gigl.src.common.types.graph_data.EdgeType, graphlearn_torch.data.Graph]]])

  • node_feature_partition (Optional[Union[graphlearn_torch.data.Feature, Dict[gigl.src.common.types.graph_data.NodeType, graphlearn_torch.data.Feature]]])

  • edge_feature_partition (Optional[Union[graphlearn_torch.data.Feature, Dict[gigl.src.common.types.graph_data.EdgeType, graphlearn_torch.data.Feature]]])

  • node_partition_book (Optional[Union[graphlearn_torch.partition.PartitionBook, Dict[gigl.src.common.types.graph_data.NodeType, graphlearn_torch.partition.PartitionBook]]])

  • edge_partition_book (Optional[Union[graphlearn_torch.partition.PartitionBook, Dict[gigl.src.common.types.graph_data.EdgeType, graphlearn_torch.partition.PartitionBook]]])

  • positive_edge_label (Optional[Union[torch.Tensor, Dict[gigl.src.common.types.graph_data.EdgeType, torch.Tensor]]])

  • negative_edge_label (Optional[Union[torch.Tensor, Dict[gigl.src.common.types.graph_data.EdgeType, torch.Tensor]]])

  • node_ids (Optional[Union[torch.Tensor, Dict[gigl.src.common.types.graph_data.NodeType, torch.Tensor]]])

  • num_train (Optional[Union[int, Dict[gigl.src.common.types.graph_data.NodeType, int]]])

  • num_val (Optional[Union[int, Dict[gigl.src.common.types.graph_data.NodeType, int]]])

  • num_test (Optional[Union[int, Dict[gigl.src.common.types.graph_data.NodeType, int]]])

build(partition_output, splitter=None)[source]#

Provided some partition graph information, this method stores these tensors inside of the class for subsequent live subgraph sampling using a GraphLearn-for-PyTorch NeighborLoader.

Note that this method will clear the following fields from the provided partition_output:
  • partitioned_edge_index

  • partitioned_node_features

  • partitioned_edge_features

We do this to decrease the peak memory usage during the build process by removing these intermediate assets.

Parameters:
  • partition_output (PartitionOutput) – Partitioned Graph to be stored in the DistLinkPredictionDataset class

  • splitter (Optional[NodeAnchorLinkSplitter]) –

    A function that takes in an edge index and returns:
    • a tuple of train, val, and test node ids, if heterogeneous

    • a dict[NodeType, tuple[train, val, test]] of node ids, if homogeneous

    Optional as not all datasets need to be split on, e.g. if we’re doing inference.

Return type:

None

abstract load(*args, **kwargs)[source]#

Load a certain dataset partition from partitioned files and create in-memory objects (Graph, Feature or torch.Tensor).

Parameters:
  • root_dir (str) – The directory path to load the graph and feature partition data.

  • partition_idx (int) – Partition idx to load.

  • graph_mode (str) – Mode for creating graphlearn_torch’s Graph, including CPU, ZERO_COPY or CUDA. (default: ZERO_COPY)

  • input_layout (str) – layout of the input graph, including CSR, CSC or COO. (default: COO)

  • feature_with_gpu (bool) – A Boolean value indicating whether the created Feature objects of node/edge features use UnifiedTensor. If True, it means Feature consists of UnifiedTensor, otherwise Feature is a PyTorch CPU Tensor, the device_group_list and device will be invliad. (default: True)

  • graph_caching (bool) – A Boolean value indicating whether to load the full graph totoploy instead of partitioned one.

  • device_group_list (List[DeviceGroup], optional) – A list of device groups used for feature lookups, the GPU part of feature data will be replicated on each device group in this list during the initialization. GPUs with peer-to-peer access to each other should be set in the same device group properly. (default: None)

  • whole_node_label_file (str) – The path to the whole node labels which are not partitioned. (default: None)

  • device – The target cuda device rank used for graph operations when graph mode is not “CPU” and feature lookups when the GPU part is not None. (default: None)

share_ipc()[source]#

Serializes the member variables of the DistLinkPredictionDatasetClass :returns: Rank on current machine

int: World size across all machines Literal[“in”, “out”]: Graph Edge Direction Optional[Union[Graph, Dict[EdgeType, Graph]]]: Partitioned Graph Data Optional[Union[Feature, Dict[NodeType, Feature]]]: Partitioned Node Feature Data Optional[Union[Feature, Dict[EdgeType, Feature]]]: Partitioned Edge Feature Data Optional[Union[torch.Tensor, Dict[NodeType, torch.Tensor]]]: Node Partition Book Tensor Optional[Union[torch.Tensor, Dict[EdgeType, torch.Tensor]]]: Edge Partition Book Tensor Optional[Union[torch.Tensor, Dict[EdgeType, torch.Tensor]]]: Positive Edge Label Tensor Optional[Union[torch.Tensor, Dict[EdgeType, torch.Tensor]]]: Negative Edge Label Tensor Optional[Union[int, Dict[NodeType, int]]]: Number of training nodes on the current machine. Will be a dict if heterogeneous. Optional[Union[int, Dict[NodeType, int]]]: Number of validation nodes on the current machine. Will be a dict if heterogeneous. Optional[Union[int, Dict[NodeType, int]]]: Number of test nodes on the current machine. Will be a dict if heterogeneous.

Return type:

int

property edge_dir: Literal['in', 'out'][source]#
Return type:

Literal[‘in’, ‘out’]

property edge_features: graphlearn_torch.data.Feature | Dict[gigl.src.common.types.graph_data.EdgeType, graphlearn_torch.data.Feature] | None[source]#

During serializiation, the initialized Feature type does not immediately contain the feature and id2index tensors. These fields are initially set to None, and are only populated when we retrieve the size, retrieve the shape, or index into one of these tensors. This can also be done manually with the feature.lazy_init_with_ipc_handle() function.

Return type:

Optional[Union[graphlearn_torch.data.Feature, Dict[gigl.src.common.types.graph_data.EdgeType, graphlearn_torch.data.Feature]]]

property edge_pb: graphlearn_torch.partition.PartitionBook | Dict[gigl.src.common.types.graph_data.EdgeType, graphlearn_torch.partition.PartitionBook] | None[source]#
Return type:

Optional[Union[graphlearn_torch.partition.PartitionBook, Dict[gigl.src.common.types.graph_data.EdgeType, graphlearn_torch.partition.PartitionBook]]]

property graph: graphlearn_torch.data.Graph | Dict[gigl.src.common.types.graph_data.EdgeType, graphlearn_torch.data.Graph] | None[source]#
Return type:

Optional[Union[graphlearn_torch.data.Graph, Dict[gigl.src.common.types.graph_data.EdgeType, graphlearn_torch.data.Graph]]]

property negative_edge_label: torch.Tensor | Dict[gigl.src.common.types.graph_data.EdgeType, torch.Tensor] | None[source]#
Return type:

Optional[Union[torch.Tensor, Dict[gigl.src.common.types.graph_data.EdgeType, torch.Tensor]]]

property node_features: graphlearn_torch.data.Feature | Dict[gigl.src.common.types.graph_data.NodeType, graphlearn_torch.data.Feature] | None[source]#

During serializiation, the initialized Feature type does not immediately contain the feature and id2index tensors. These fields are initially set to None, and are only populated when we retrieve the size, retrieve the shape, or index into one of these tensors. This can also be done manually with the feature.lazy_init_with_ipc_handle() function.

Return type:

Optional[Union[graphlearn_torch.data.Feature, Dict[gigl.src.common.types.graph_data.NodeType, graphlearn_torch.data.Feature]]]

property node_ids: torch.Tensor | Dict[gigl.src.common.types.graph_data.NodeType, torch.Tensor] | None[source]#
Return type:

Optional[Union[torch.Tensor, Dict[gigl.src.common.types.graph_data.NodeType, torch.Tensor]]]

property node_pb: graphlearn_torch.partition.PartitionBook | Dict[gigl.src.common.types.graph_data.NodeType, graphlearn_torch.partition.PartitionBook] | None[source]#
Return type:

Optional[Union[graphlearn_torch.partition.PartitionBook, Dict[gigl.src.common.types.graph_data.NodeType, graphlearn_torch.partition.PartitionBook]]]

property num_partitions: int[source]#
Return type:

int

property partition_idx: int[source]#
Return type:

int

property positive_edge_label: torch.Tensor | Dict[gigl.src.common.types.graph_data.EdgeType, torch.Tensor] | None[source]#
Return type:

Optional[Union[torch.Tensor, Dict[gigl.src.common.types.graph_data.EdgeType, torch.Tensor]]]

property test_node_ids: torch.Tensor | collections.abc.Mapping[gigl.src.common.types.graph_data.NodeType, torch.Tensor] | None[source]#
Return type:

Optional[Union[torch.Tensor, collections.abc.Mapping[gigl.src.common.types.graph_data.NodeType, torch.Tensor]]]

property train_node_ids: torch.Tensor | collections.abc.Mapping[gigl.src.common.types.graph_data.NodeType, torch.Tensor] | None[source]#
Return type:

Optional[Union[torch.Tensor, collections.abc.Mapping[gigl.src.common.types.graph_data.NodeType, torch.Tensor]]]

property val_node_ids: torch.Tensor | collections.abc.Mapping[gigl.src.common.types.graph_data.NodeType, torch.Tensor] | None[source]#
Return type:

Optional[Union[torch.Tensor, collections.abc.Mapping[gigl.src.common.types.graph_data.NodeType, torch.Tensor]]]

gigl.distributed.dist_link_prediction_dataset.logger[source]#

previous

gigl.distributed.dist_context

next

gigl.distributed.dist_partitioner

On this page
  • Attributes
  • Classes
  • Module Contents
    • DistLinkPredictionDataset
      • DistLinkPredictionDataset.build()
      • DistLinkPredictionDataset.load()
      • DistLinkPredictionDataset.share_ipc()
      • DistLinkPredictionDataset.edge_dir
      • DistLinkPredictionDataset.edge_features
      • DistLinkPredictionDataset.edge_pb
      • DistLinkPredictionDataset.graph
      • DistLinkPredictionDataset.negative_edge_label
      • DistLinkPredictionDataset.node_features
      • DistLinkPredictionDataset.node_ids
      • DistLinkPredictionDataset.node_pb
      • DistLinkPredictionDataset.num_partitions
      • DistLinkPredictionDataset.partition_idx
      • DistLinkPredictionDataset.positive_edge_label
      • DistLinkPredictionDataset.test_node_ids
      • DistLinkPredictionDataset.train_node_ids
      • DistLinkPredictionDataset.val_node_ids
    • logger
Edit on GitHub

© Copyright 2025, Snap Inc.

Created using Sphinx 7.4.7.

Built with the PyData Sphinx Theme 0.16.1.