Federated Graph Learning Module References

federatedscope.gfl.dataset

class federatedscope.gfl.dataset.CIKMCUPDataset(root)[source]
process()[source]

Processes the dataset to the self.processed_dir folder.

property processed_file_names

The name of the files in the self.processed_dir folder that must be present in order to skip processing.

class federatedscope.gfl.dataset.DBLPNew(root, FL=0, splits=[0.5, 0.2, 0.3], transform=None, pre_transform=None)[source]
Parameters
  • root (string) – Root directory where the dataset should be saved.

  • FL (Bool) – Federated setting, 0 for DBLP, 1 for FLDBLPbyConf,

  • FLDBLPbyOrg (2 for) –

  • transform (callable, optional) – A function/transform that takes in an torch_geometric.data.Data object and returns a transformed version. The data object will be transformed before every access. (default: None)

  • pre_transform (callable, optional) – A function/transform that takes in an torch_geometric.data.Data object and returns a transformed version. The data object will be transformed before being saved to disk. (default: None)

download()[source]

Downloads the dataset to the self.raw_dir folder.

process()[source]

Processes the dataset to the self.processed_dir folder.

property processed_file_names

The name of the files in the self.processed_dir folder that must be present in order to skip processing.

property raw_file_names

The name of the files in the self.raw_dir folder that must be present in order to skip downloading.

class federatedscope.gfl.dataset.KG(root, name, transform=None, pre_transform=None)[source]
download()[source]

Downloads the dataset to the self.raw_dir folder.

process()[source]

Processes the dataset to the self.processed_dir folder.

property processed_file_names

The name of the files in the self.processed_dir folder that must be present in order to skip processing.

property raw_file_names

The name of the files in the self.raw_dir folder that must be present in order to skip downloading.

class federatedscope.gfl.dataset.RecSys(root, name, FL=False, splits=[0.8, 0.1, 0.1], transform=None, pre_transform=None)[source]
Parameters
  • root (string) – Root directory where the dataset should be saved.

  • name (string) – The name of the dataset ("epinions",

:param "ciao").: :param FL: Federated setting or centralized setting. :type FL: Bool :param transform: A function/transform that takes in an

torch_geometric.data.Data object and returns a transformed version. The data object will be transformed before every access. (default: None)

Parameters

pre_transform (callable, optional) – A function/transform that takes in an torch_geometric.data.Data object and returns a transformed version. The data object will be transformed before being saved to disk. (default: None)

download()[source]

Download raw files to self.raw_dir from FedGraphNN. Paper: https://arxiv.org/abs/2104.07145 Repo: https://github.com/FedML-AI/FedGraphNN

process()[source]

Processes the dataset to the self.processed_dir folder.

property processed_file_names

The name of the files in the self.processed_dir folder that must be present in order to skip processing.

property raw_file_names

The name of the files in the self.raw_dir folder that must be present in order to skip downloading.

class federatedscope.gfl.dataset.dataset_ContextualSBM(root, name=None, n=800, d=5, p=100, Lambda=None, mu=None, epsilon=0.1, theta=[- 0.5, - 0.25, 0.25, 0.5], train_percent=0.01, transform=None, pre_transform=None)[source]

Create synthetic dataset based on the contextual SBM from the paper: https://arxiv.org/pdf/1807.09596.pdf

Use the similar class as InMemoryDataset, but not requiring the root folder.

create_dataset.html#creating-in-memory-datasets>`__ for the accompanying tutorial.

Parameters
  • root (string) – Root directory where the dataset should be saved.

  • name (string) – The name of the dataset if not specified use time stamp.

  • {n (for) – intial/feed in argument.

  • d – intial/feed in argument.

  • p – intial/feed in argument.

  • Lambda – intial/feed in argument.

  • mu} – intial/feed in argument.

  • prefix (without '_' as) – intial/feed in argument.

  • prefix – loaded from data information

  • n – number nodes

  • d – avg degree of nodes

  • p – dimenstion of feature vector.

  • Lambda – parameters balancing the mixture of information, if not specified, use parameterized method to generate.

  • mu – parameters balancing the mixture of information, if not specified, use parameterized method to generate.

  • epsilon – gap between boundary and chosen ellipsoid. theta is angle of between the selected parameter and x-axis. choosen between [0, 1] => 0 = 0, 1 = pi/2

  • theta – gap between boundary and chosen ellipsoid. theta is angle of between the selected parameter and x-axis. choosen between [0, 1] => 0 = 0, 1 = pi/2

  • transform (callable, optional) – A function/transform that takes in an torch_geometric.data.Data object and returns a transformed version. The data object will be transformed before every access. (default: None)

  • pre_transform (callable, optional) – A function/transform that takes in an torch_geometric.data.Data object and returns a transformed version. The data object will be transformed before being saved to disk. (default: None)

download()[source]

Downloads the dataset to the self.raw_dir folder.

process()[source]

Processes the dataset to the self.processed_dir folder.

property processed_file_names

The name of the files in the self.processed_dir folder that must be present in order to skip processing.

property raw_file_names

The name of the files in the self.raw_dir folder that must be present in order to skip downloading.

federatedscope.gfl.dataloader

federatedscope.gfl.dataloader.load_graphlevel_dataset(config=None)[source]

Convert dataset to Dataloader. :returns:

data_local_dict

Return type

Dict { ‘client_id’: {

’train’: DataLoader(), ‘val’: DataLoader(), ‘test’: DataLoader()

}

}

federatedscope.gfl.dataloader.load_linklevel_dataset(config=None)[source]
Returns

data_dict

Return type

(Dict): dict{‘client_id’: Data()}

federatedscope.gfl.dataloader.load_nodelevel_dataset(config=None)[source]
Returns

data_dict

Return type

Dict: dict{‘client_id’: Data()}

federatedscope.gfl.model

class federatedscope.gfl.model.FedSage_Plus(local_graph: LocalSage_Plus)[source]
forward(data)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class federatedscope.gfl.model.GAT_Net(in_channels, out_channels, hidden=64, max_depth=2, dropout=0.0)[source]

GAT model from the “Graph Attention Networks” paper, in ICLR’18

Parameters
  • in_channels (int) – dimension of input.

  • out_channels (int) – dimension of output.

  • hidden (int) – dimension of hidden units, default=64.

  • max_depth (int) – layers of GNN, default=2.

  • dropout (float) – dropout ratio, default=.0.

forward(data)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class federatedscope.gfl.model.GCN_Net(in_channels, out_channels, hidden=64, max_depth=2, dropout=0.0)[source]

GCN model from the “Semi-supervised Classification with Graph Convolutional Networks” paper, in ICLR’17.

Parameters
  • in_channels (int) – dimension of input.

  • out_channels (int) – dimension of output.

  • hidden (int) – dimension of hidden units, default=64.

  • max_depth (int) – layers of GNN, default=2.

  • dropout (float) – dropout ratio, default=.0.

forward(data)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class federatedscope.gfl.model.GIN_Net(in_channels, out_channels, hidden=64, max_depth=2, dropout=0.0)[source]

Graph Isomorphism Network model from the “How Powerful are Graph Neural Networks?” paper, in ICLR’19

Parameters
  • in_channels (int) – dimension of input.

  • out_channels (int) – dimension of output.

  • hidden (int) – dimension of hidden units, default=64.

  • max_depth (int) – layers of GNN, default=2.

  • dropout (float) – dropout ratio, default=.0.

forward(data)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class federatedscope.gfl.model.GNN_Net_Graph(in_channels, out_channels, hidden=64, max_depth=2, dropout=0.0, gnn='gcn', pooling='add')[source]
GNN model with pre-linear layer, pooling layer

and output layer for graph classification tasks.

Parameters
  • in_channels (int) – input channels.

  • out_channels (int) – output channels.

  • hidden (int) – hidden dim for all modules.

  • max_depth (int) – number of layers for gnn.

  • dropout (float) – dropout probability.

  • gnn (str) – name of gnn type, use (“gcn” or “gin”).

  • pooling (str) – pooling method, use (“add”, “mean” or “max”).

forward(data)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

forward(data)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class federatedscope.gfl.model.GPR_Net(in_channels, out_channels, hidden=64, K=10, dropout=0.0, ppnp='GPR_prop', alpha=0.1, Init='PPR', Gamma=None)[source]

GPR-GNN model from the “Adaptive Universal Generalized PageRank Graph Neural Network” paper, in ICLR’21

Parameters
  • in_channels (int) – dimension of input.

  • out_channels (int) – dimension of output.

  • hidden (int) – dimension of hidden units, default=64.

  • K (int) – power of GPR-GNN, default=10.

  • dropout (float) – dropout ratio, default=.0.

  • ppnp (str) – propagation method in [‘PPNP’, ‘GPR_prop’]

  • Init (str) – init method in [‘SGC’, ‘PPR’, ‘NPPR’, ‘Random’, ‘WS’]

forward(data)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class federatedscope.gfl.model.LocalSage_Plus(in_channels, out_channels, hidden, gen_hidden, dropout=0.5, num_pred=5)[source]
forward(data)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class federatedscope.gfl.model.MLP(channel_list, dropout=0.0, batch_norm=True, relu_first=False)[source]

Multilayer Perceptron

forward(x)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class federatedscope.gfl.model.SAGE_Net(in_channels, out_channels, hidden=64, max_depth=2, dropout=0.0)[source]

GraphSAGE model from the “Inductive Representation Learning on Large Graphs” paper, in NeurIPS’17

Source: https://github.com/pyg-team/pytorch_geometric/ blob/master/examples/ogbn_products_sage.py

Parameters
  • in_channels (int) – dimension of input.

  • out_channels (int) – dimension of output.

  • hidden (int) – dimension of hidden units, default=64.

  • max_depth (int) – layers of GNN, default=2.

  • dropout (float) – dropout ratio, default=.0.

forward(x, edge_index=None, edge_weight=None, adjs=None)[source]

train_loader computes the k-hop neighborhood of a batch of nodes, and returns, for each layer, a bipartite graph object, holding the bipartite edges edge_index, the index e_id of the original edges, and the size/shape size of the bipartite graph. Target nodes are also included in the source nodes so that one can easily apply skip-connections or add self-loops.

Parameters
  • x (torch.Tensor or PyG.data or tuple) – node features or full-batch data

  • edge_index (torch.Tensor) – edge index.

  • edge_weight (torch.Tensor) – edge weight.

  • adjs (List[PyG.loader.neighbor_sampler.EdgeIndex]) –

    batched edge index

Returns

x: output

Return type

torch.Tensor

inference(x_all, subgraph_loader, device)[source]

Compute representations of nodes layer by layer, using all available edges. This leads to faster computation in contrast to immediately computing the final representations of each batch.

Parameters
  • x_all (torch.Tensor) – all node features

  • subgraph_loader (PyG.dataloader) – dataloader

  • device (str) – device

Returns

x_all: output

federatedscope.gfl.trainer

class federatedscope.gfl.trainer.GraphMiniBatchTrainer(model, data, device, config, only_for_eval=False, monitor=None)[source]
_hook_on_batch_forward(ctx)[source]

Note

The modified attributes and according operations are shown below:

Attribute

Operation

ctx.y_true

Move to ctx.device

ctx.y_prob

Forward propagation get y_prob

ctx.loss_batch

Calculate the loss

ctx.batch_size

Get the batch_size

_hook_on_batch_forward_flop_count(ctx)[source]

The monitoring hook to calculate the flops during the fl course

Note

For customized cases that the forward process is not only based on ctx.model, please override this function (inheritance case) or replace this hook (plug-in case)

The modified attributes and according operations are shown below:

Attribute

Operation

ctx.monitor

Track average flops

class federatedscope.gfl.trainer.LinkFullBatchTrainer(model, data, device, config, only_for_eval=False, monitor=None)[source]
_hook_on_batch_forward(ctx)[source]

Note

The modified attributes and according operations are shown below:

Attribute

Operation

ctx.y_true

Move to ctx.device

ctx.y_prob

Forward propagation get y_prob

ctx.loss_batch

Calculate the loss

ctx.batch_size

Get the batch_size

_hook_on_batch_forward_flop_count(ctx)[source]

The monitoring hook to calculate the flops during the fl course

Note

For customized cases that the forward process is not only based on ctx.model, please override this function (inheritance case) or replace this hook (plug-in case)

The modified attributes and according operations are shown below:

Attribute

Operation

ctx.monitor

Track average flops

parse_data(data)[source]

Populate “{}_data”, “{}_loader” and “num_{}_data” for different modes

class federatedscope.gfl.trainer.LinkMiniBatchTrainer(model, data, device, config, only_for_eval=False, monitor=None)[source]

# Support GraphSAGE with GraphSAINTRandomWalkSampler in train ONLY!

_hook_on_batch_forward(ctx)[source]

Note

The modified attributes and according operations are shown below:

Attribute

Operation

ctx.y_true

Move to ctx.device

ctx.y_prob

Forward propagation get y_prob

ctx.loss_batch

Calculate the loss

ctx.batch_size

Get the batch_size

parse_data(data)[source]

Populate “{}_data”, “{}_loader” and “num_{}_data” for different modes

class federatedscope.gfl.trainer.NodeFullBatchTrainer(model, data, device, config, only_for_eval=False, monitor=None)[source]
_hook_on_batch_forward(ctx)[source]

Note

The modified attributes and according operations are shown below:

Attribute

Operation

ctx.y_true

Move to ctx.device

ctx.y_prob

Forward propagation get y_prob

ctx.loss_batch

Calculate the loss

ctx.batch_size

Get the batch_size

_hook_on_batch_forward_flop_count(ctx)[source]

The monitoring hook to calculate the flops during the fl course

Note

For customized cases that the forward process is not only based on ctx.model, please override this function (inheritance case) or replace this hook (plug-in case)

The modified attributes and according operations are shown below:

Attribute

Operation

ctx.monitor

Track average flops

parse_data(data)[source]

Populate “{}_data”, “{}_loader” and “num_{}_data” for different modes

class federatedscope.gfl.trainer.NodeMiniBatchTrainer(model, data, device, config, only_for_eval=False, monitor=None)[source]
_hook_on_batch_forward(ctx)[source]

Note

The modified attributes and according operations are shown below:

Attribute

Operation

ctx.y_true

Move to ctx.device

ctx.y_prob

Forward propagation get y_prob

ctx.loss_batch

Calculate the loss

ctx.batch_size

Get the batch_size

_hook_on_epoch_start(ctx)[source]

Note

The modified attributes and according operations are shown below:

Attribute

Operation

ctx.{ctx.cur_split}_loader

Initialize DataLoader

parse_data(data)[source]

Populate “{}_data”, “{}_loader” and “num_{}_data” for different modes