compositional_graph_models/models.py
def _reduce_layer(
        layer: torch.nn.Module,
    ) -> Callable[[dgl.udf.NodeBatch], Dict[str, torch.Tensor]]:
        """
        Make a DGL user-defined reduction function from a module.

        The function expects a node batch with features of shape
        [n_nodes, n_arguments, dim], and applies a module which is expected to accept
        tensors of shape n_arguments * dim to produce new features of shape dim.

        Parameters
        ----------
        layer
            The module to apply during reduction. Must be polymorphic in its first
            tensor dimension (i.e. batch-size agnostic).

        Returns
        -------
        NodeBatch -> Dict[str, Tensor]
            A user-defined reduction function which applies `layer` to the flattened
            input messages.
        """

        def layer_udf(nodes: dgl.udf.NodeBatch) -> Dict[str, torch.Tensor]:
            batch_size = nodes.mailbox["features"].size(0)
            features = nodes.mailbox["features"].view(batch_size, -1)
            outputs = layer(features)
            return {"features": outputs}

        return layer_udf

        Make a DGL user-defined reduction function from a module.

        The function expects a node batch with features of shape
        [n_nodes, n_arguments, dim], and applies a module which is expected to accept
        tensors of shape n_arguments * dim to produce new features of shape dim.

        Parameters
        ----------
        layer
            The module to apply during reduction. Must be polymorphic in its first
            tensor dimension (i.e. batch-size agnostic).

        Returns
        -------
        NodeBatch -> Dict[str, Tensor]
            A user-defined reduction function which applies `layer` to the flattened
            input messages.
        
Make a DGL user-defined reduction function from a module.
The function expects a node batch with features of shape
[n_nodes, n_arguments, dim], and applies a module which is expected to accept
tensors of shape n_arguments * dim to produce new features of shape dim.

Parameters

layer
The module to apply during reduction. Must be polymorphic in its first
tensor dimension .

Returns

> Dict[str, Tensor]
A user-defined reduction function which applies `layer` to the flattened
input messages.
Make a DGL user - defined reduction function from a module . The function expects a node batch with features of shape [ n_nodes n_arguments dim ] and applies a module which is expected to accept tensors of shape n_arguments * dim to produce new features of shape dim . Parameters layer The module to apply during reduction . Must be polymorphic in its first tensor dimension . Returns > Dict [ str Tensor ] A user - defined reduction function which applies ` layer ` to the flattened input messages .
def _reduce_layer(
        layer: torch.nn.Module,
    ) -> Callable[[dgl.udf.NodeBatch], Dict[str, torch.Tensor]]:
        def layer_udf(nodes: dgl.udf.NodeBatch) -> Dict[str, torch.Tensor]:
            batch_size = nodes.mailbox["features"].size(0)
            features = nodes.mailbox["features"].view(batch_size, -1)
            outputs = layer(features)
            return {"features": outputs}
        return layer_udf
def _reduce_layer ( layer : torch . nn . Module , ) -> Callable [ [ dgl . udf . NodeBatch ] , Dict [ str , torch . Tensor ] ] : def layer_udf ( nodes : dgl . udf . NodeBatch ) -> Dict [ str , torch . Tensor ] : batch_size = nodes . mailbox [ "features" ] . size ( 0 ) features = nodes . mailbox [ "features" ] . view ( batch_size , - 1 ) outputs = layer ( features ) return { "features" : outputs } return layer_udf
Make a DGL user-defined reduction function from a module.
Make a DGL user - defined reduction function from a module .
"""
        Make a DGL user-defined reduction function from a module.

        The function expects a node batch with features of shape
        [n_nodes, n_arguments, dim], and applies a module which is expected to accept
        tensors of shape n_arguments * dim to produce new features of shape dim.

        Parameters
        ----------
        layer
            The module to apply during reduction. Must be polymorphic in its first
            tensor dimension (i.e. batch-size agnostic).

        Returns
        -------
        NodeBatch -> Dict[str, Tensor]
            A user-defined reduction function which applies `layer` to the flattened
            input messages.
        """
layer
torch.nn.Module