-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable `index_sort` introduced in [pyg-lib](https://pyg-lib.readthedocs.io/en/latest/modules/ops.html#pyg_lib.ops.index_sort). Till now, sorting indices (1d tensor) have been working sequentially. This PR enables the `index_sort` operation, which makes such a sort work in parallel (parallelized radix sort). Related PR: [pytorch_sparse:306](rusty1s/pytorch_sparse#306) In training benchmarks, data set load time was improved on average by 3.82 times, and training time by 1.06 times. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: rusty1s <matthias.fey@tu-dortmund.de>
- Loading branch information
1 parent
af45d62
commit 46d6102
Showing
14 changed files
with
66 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from typing import Optional, Tuple | ||
|
||
import torch | ||
|
||
from torch_geometric.typing import WITH_PYG_LIB, pyg_lib | ||
|
||
WITH_INDEX_SORT = WITH_PYG_LIB and hasattr(torch.ops.pyg, 'index_sort') | ||
|
||
|
||
def index_sort( | ||
inputs: torch.Tensor, | ||
max_value: Optional[int] = None, | ||
) -> Tuple[torch.Tensor, torch.Tensor]: | ||
r"""Sorts the elements of the :obj:`inputs` tensor in ascending order. | ||
It is expected that :obj:`inputs` is one-dimensional and that it only | ||
contains positive integer values. If :obj:`max_value` is given, it can | ||
be used by the underlying algorithm for better performance. | ||
Args: | ||
inputs (torch.Tensor): A vector with positive integer values. | ||
max_value (int, optional): The maximum value stored inside | ||
:obj:`inputs`. This value can be an estimation, but needs to be | ||
greater than or equal to the real maximum. | ||
(default: :obj:`None`) | ||
""" | ||
if not WITH_INDEX_SORT: # pragma: no cover | ||
return inputs.sort() | ||
return pyg_lib.ops.index_sort(inputs, max_value=max_value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters