Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional kwargs to GATConv #4210

Merged
merged 6 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions python/cugraph-dgl/cugraph_dgl/nn/conv/gatconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ def forward(
nfeat: Union[torch.Tensor, tuple[torch.Tensor, torch.Tensor]],
efeat: Optional[torch.Tensor] = None,
max_in_degree: Optional[int] = None,
deterministic_dgrad: bool = False,
deterministic_wgrad: bool = False,
high_precision_dgrad: bool = False,
high_precision_wgrad: bool = False,
) -> torch.Tensor:
r"""Forward computation.

Expand All @@ -204,6 +208,20 @@ def forward(
from a neighbor sampler, the value should be set to the corresponding
:attr:`fanout`. This option is used to invoke the MFG-variant of
cugraph-ops kernel.
deterministic_dgrad : bool, default=False
Optional flag indicating whether the feature gradients
are computed deterministically using a dedicated workspace buffer.
deterministic_wgrad: bool, default=False
Optional flag indicating whether the weight gradients
are computed deterministically using a dedicated workspace buffer.
high_precision_dgrad: bool, default=False
Optional flag indicating whether gradients for inputs in half precision
are kept in single precision as long as possible and only casted to
the corresponding input type at the very end.
high_precision_wgrad: bool, default=False
Optional flag indicating whether gradients for weights in half precision
are kept in single precision as long as possible and only casted to
the corresponding input type at the very end.

Returns
-------
Expand Down Expand Up @@ -232,6 +250,8 @@ def forward(
_graph = self.get_cugraph_ops_CSC(
g, is_bipartite=bipartite, max_in_degree=max_in_degree
)
if deterministic_dgrad:
_graph.add_reverse_graph()

if bipartite:
nfeat = (self.feat_drop(nfeat[0]), self.feat_drop(nfeat[1]))
Expand Down Expand Up @@ -273,6 +293,10 @@ def forward(
negative_slope=self.negative_slope,
concat_heads=self.concat,
edge_feat=efeat,
deterministic_dgrad=deterministic_dgrad,
deterministic_wgrad=deterministic_wgrad,
high_precision_dgrad=high_precision_dgrad,
high_precision_wgrad=high_precision_wgrad,
)[: g.num_dst_nodes()]

if self.concat:
Expand Down
12 changes: 12 additions & 0 deletions python/cugraph-dgl/cugraph_dgl/nn/conv/gatv2conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ def forward(
nfeat: Union[torch.Tensor, tuple[torch.Tensor, torch.Tensor]],
efeat: Optional[torch.Tensor] = None,
max_in_degree: Optional[int] = None,
deterministic_dgrad: bool = False,
deterministic_wgrad: bool = False,
) -> torch.Tensor:
r"""Forward computation.

Expand All @@ -166,6 +168,12 @@ def forward(
from a neighbor sampler, the value should be set to the corresponding
:attr:`fanout`. This option is used to invoke the MFG-variant of
cugraph-ops kernel.
deterministic_dgrad : bool, default=False
Optional flag indicating whether the feature gradients
are computed deterministically using a dedicated workspace buffer.
deterministic_wgrad: bool, default=False
Optional flag indicating whether the weight gradients
are computed deterministically using a dedicated workspace buffer.

Returns
-------
Expand Down Expand Up @@ -196,6 +204,8 @@ def forward(
_graph = self.get_cugraph_ops_CSC(
g, is_bipartite=graph_bipartite, max_in_degree=max_in_degree
)
if deterministic_dgrad:
_graph.add_reverse_graph()

if nfeat_bipartite:
nfeat = (self.feat_drop(nfeat[0]), self.feat_drop(nfeat[1]))
Expand Down Expand Up @@ -228,6 +238,8 @@ def forward(
negative_slope=self.negative_slope,
concat_heads=self.concat,
edge_feat=efeat,
deterministic_dgrad=deterministic_dgrad,
deterministic_wgrad=deterministic_wgrad,
)[: g.num_dst_nodes()]

if self.concat:
Expand Down
26 changes: 25 additions & 1 deletion python/cugraph-pyg/cugraph_pyg/nn/conv/gat_conv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2023-2024, NVIDIA CORPORATION.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down Expand Up @@ -162,6 +162,10 @@ def forward(
csc: Tuple[torch.Tensor, torch.Tensor, int],
edge_attr: Optional[torch.Tensor] = None,
max_num_neighbors: Optional[int] = None,
deterministic_dgrad: bool = False,
deterministic_wgrad: bool = False,
high_precision_dgrad: bool = False,
high_precision_wgrad: bool = False,
) -> torch.Tensor:
r"""Runs the forward pass of the module.

Expand All @@ -178,11 +182,27 @@ def forward(
of a destination node. When enabled, it allows models to use
the message-flow-graph primitives in cugraph-ops.
(default: :obj:`None`)
deterministic_dgrad : bool, default=False
Optional flag indicating whether the feature gradients
are computed deterministically using a dedicated workspace buffer.
deterministic_wgrad: bool, default=False
Optional flag indicating whether the weight gradients
are computed deterministically using a dedicated workspace buffer.
high_precision_dgrad: bool, default=False
Optional flag indicating whether gradients for inputs in half precision
are kept in single precision as long as possible and only casted to
the corresponding input type at the very end.
high_precision_wgrad: bool, default=False
Optional flag indicating whether gradients for weights in half precision
are kept in single precision as long as possible and only casted to
the corresponding input type at the very end.
"""
bipartite = not isinstance(x, torch.Tensor)
graph = self.get_cugraph(
csc, bipartite=bipartite, max_num_neighbors=max_num_neighbors
)
if deterministic_dgrad:
graph.add_reverse_graph()

if edge_attr is not None:
if self.lin_edge is None:
Expand Down Expand Up @@ -220,6 +240,10 @@ def forward(
negative_slope=self.negative_slope,
concat_heads=self.concat,
edge_feat=edge_attr,
deterministic_dgrad=deterministic_dgrad,
deterministic_wgrad=deterministic_wgrad,
high_precision_dgrad=high_precision_dgrad,
high_precision_wgrad=high_precision_wgrad,
)

if self.bias is not None:
Expand Down
14 changes: 13 additions & 1 deletion python/cugraph-pyg/cugraph_pyg/nn/conv/gatv2_conv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2023-2024, NVIDIA CORPORATION.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down Expand Up @@ -174,6 +174,8 @@ def forward(
x: Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]],
csc: Tuple[torch.Tensor, torch.Tensor, int],
edge_attr: Optional[torch.Tensor] = None,
deterministic_dgrad: bool = False,
deterministic_wgrad: bool = False,
) -> torch.Tensor:
r"""Runs the forward pass of the module.

Expand All @@ -186,9 +188,17 @@ def forward(
:meth:`to_csc` method to convert an :obj:`edge_index`
representation to the desired format.
edge_attr: (torch.Tensor, optional) The edge features.
deterministic_dgrad : bool, default=False
Optional flag indicating whether the feature gradients
are computed deterministically using a dedicated workspace buffer.
deterministic_wgrad: bool, default=False
Optional flag indicating whether the weight gradients
are computed deterministically using a dedicated workspace buffer.
"""
bipartite = not isinstance(x, torch.Tensor) or not self.share_weights
graph = self.get_cugraph(csc, bipartite=bipartite)
if deterministic_dgrad:
graph.add_reverse_graph()

if edge_attr is not None:
if self.lin_edge is None:
Expand Down Expand Up @@ -217,6 +227,8 @@ def forward(
negative_slope=self.negative_slope,
concat_heads=self.concat,
edge_feat=edge_attr,
deterministic_dgrad=deterministic_dgrad,
deterministic_wgrad=deterministic_wgrad,
)

if self.bias is not None:
Expand Down
Loading