Skip to content

GAT

GAT(
    node_features_dim: int,
    hidden_features_dim: int,
    num_layers: int,
    out_features_dim: Optional[int] = None,
    heads: int = 1,
    v2: bool = False,
    **kwargs: Any,
)

Bases: BasicGNN

Graph Attention Network from "Graph Attention Networks" (or, with v2=True, "How Attentive are Graph Attention Networks?"), a stack of GATConv / GATv2Conv layers.

Hidden layers concatenate their heads attention heads, each of size hidden_features_dim // heads. When out_features_dim is given, the last layer averages its heads instead.

Parameters:

Name Type Description Default
node_features_dim int

Size of the input node features.

required
hidden_features_dim int

Size of the hidden node embeddings (all heads together). Must be divisible by heads.

required
num_layers int

Number of message passing layers.

required
out_features_dim Optional[int]

Size of the output. Default: None

None
heads int

Number of attention heads. Default: 1

1
v2 bool

Whether to use GATv2Conv. Default: False

False
dropout

Dropout probability, applied after each hidden layer and, as in PyG, to the attention coefficients of every layer. Default: 0.0

required
act

Activation between layers. Default: "relu"

required
norm

Normalization between layers. Default: None

required
jk

Jumping Knowledge mode. Default: None

required
**kwargs Any

Additional arguments of the convolution layer (e.g. edge_features_dim).

{}
Source code in mlx_graphs/nn/models/basic_gnn.py
def __init__(
    self,
    node_features_dim: int,
    hidden_features_dim: int,
    num_layers: int,
    out_features_dim: Optional[int] = None,
    heads: int = 1,
    v2: bool = False,
    **kwargs: Any,
):
    if hidden_features_dim % heads != 0:
        raise ValueError(
            "`hidden_features_dim` must be divisible by `heads` "
            f"(got {hidden_features_dim} and {heads})"
        )
    self._heads = heads
    self._v2 = v2
    super().__init__(
        node_features_dim,
        hidden_features_dim,
        num_layers,
        out_features_dim,
        **kwargs,
    )

from mlx_graphs.nn import GAT · mlx_graphs/nn/models/basic_gnn.py