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

Improve inference loop on GPU devices #7896

Merged
merged 12 commits into from
Aug 28, 2023

Conversation

DamianSzwichtenberg
Copy link
Member

@DamianSzwichtenberg DamianSzwichtenberg commented Aug 17, 2023

In layer-wise inference loop, we perform computations as shown on the following pseudocode:

for layer in layers
    for batch in loader
        do inference per layer

In models that have more than one layer, we can benefit from caching batches during the
first walk through the data. This PR introduces CachedLoader, which transfers
batches to a pointed device and caches them. Additionally, an auxiliary function was provided,
make_batches_cacheable, which decorates BasicGNN instance with a custom inference
loop.

Selected performance results (gained on Intel PVC):

Speedup:
gcn[2L]+Reddit: 1.53x
gcn[3L]+Reddit: 1.69x
sage[2L]+Reddit: 1.55x
sage[3L]+Reddit: 2.02x
gcn[2L]+ogbn-products: 1.72x
gcn[3L]+ogbn-products: 2.11x
sage[2L]+ogbn-products: 1.83x
sage[3L]+ogbn-products: 2.44x

Caching mechanism did not have a significant impact on models with a single layer.

Drawbacks:

  • User should be aware that caching mechanism requires additional device memory to be allocated.
    In experiments, approximately 1GB was needed for the Reddit dataset.

@codecov
Copy link

codecov bot commented Aug 17, 2023

Codecov Report

Merging #7896 (5b81af4) into master (ecc4b76) will decrease coverage by 0.01%.
Report is 1 commits behind head on master.
The diff coverage is 81.25%.

❗ Current head 5b81af4 differs from pull request most recent head 014b2fa. Consider uploading reports for the commit 014b2fa to get more accurate results

@@            Coverage Diff             @@
##           master    #7896      +/-   ##
==========================================
- Coverage   89.42%   89.41%   -0.01%     
==========================================
  Files         458      459       +1     
  Lines       26871    26918      +47     
==========================================
+ Hits        24029    24069      +40     
- Misses       2842     2849       +7     
Files Changed Coverage Δ
torch_geometric/loader/cache.py 78.37% <78.37%> (ø)
torch_geometric/nn/models/basic_gnn.py 90.39% <90.00%> (-0.07%) ⬇️
torch_geometric/loader/__init__.py 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

torch_geometric/loader/cache.py Outdated Show resolved Hide resolved
torch_geometric/nn/models/basic_gnn.py Outdated Show resolved Hide resolved
@DamianSzwichtenberg DamianSzwichtenberg force-pushed the cached-loader branch 4 times, most recently from 933a267 to 9bb1aba Compare August 22, 2023 08:41
@DamianSzwichtenberg
Copy link
Member Author

@rusty1s Any new comments here?

@rusty1s
Copy link
Member

rusty1s commented Aug 24, 2023

Will merge ASAP.

torch_geometric/loader/cache.py Outdated Show resolved Hide resolved
torch_geometric/loader/cache.py Outdated Show resolved Hide resolved
test/loader/test_cache.py Outdated Show resolved Hide resolved
@DamianSzwichtenberg DamianSzwichtenberg force-pushed the cached-loader branch 2 times, most recently from 0da96da to 928ca79 Compare August 28, 2023 06:32
@DamianSzwichtenberg
Copy link
Member Author

@akihironitta Could you PTAL?

@rusty1s rusty1s enabled auto-merge (squash) August 28, 2023 12:45
@rusty1s rusty1s merged commit 627e0db into pyg-team:master Aug 28, 2023
rusty1s added a commit that referenced this pull request Aug 28, 2023
This PR adds `--cached-loader` option, that enables `CachedLoader` in
inference loop.

Waiting for #7896.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Matthias Fey <matthias.fey@tu-dortmund.de>
erfanloghmani pushed a commit to erfanloghmani/pytorch_geometric that referenced this pull request Aug 31, 2023
In layer-wise inference loop, we perform computations as shown on the
following pseudocode:
```
for layer in layers
    for batch in loader
        do inference per layer
```
In models that have more than one layer, we can benefit from caching
batches during the
first walk through the data. This PR introduces `CachedLoader`, which
transfers
batches to a pointed device and caches them. Additionally, an auxiliary
function was provided,
`make_batches_cacheable`, which decorates `BasicGNN` instance with a
custom inference
loop.

Selected performance results (gained on Intel PVC):
```
Speedup:
gcn[2L]+Reddit: 1.53x
gcn[3L]+Reddit: 1.69x
sage[2L]+Reddit: 1.55x
sage[3L]+Reddit: 2.02x
gcn[2L]+ogbn-products: 1.72x
gcn[3L]+ogbn-products: 2.11x
sage[2L]+ogbn-products: 1.83x
sage[3L]+ogbn-products: 2.44x
```
Caching mechanism did not have a significant impact on models with a
single layer.

Drawbacks:
- User should be aware that caching mechanism requires additional device
memory to be allocated.
In experiments, approximately 1GB was needed for the `Reddit` dataset.

---------

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>
erfanloghmani pushed a commit to erfanloghmani/pytorch_geometric that referenced this pull request Aug 31, 2023
…am#7897)

This PR adds `--cached-loader` option, that enables `CachedLoader` in
inference loop.

Waiting for pyg-team#7896.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Matthias Fey <matthias.fey@tu-dortmund.de>
JakubPietrakIntel pushed a commit that referenced this pull request Sep 27, 2023
In layer-wise inference loop, we perform computations as shown on the
following pseudocode:
```
for layer in layers
    for batch in loader
        do inference per layer
```
In models that have more than one layer, we can benefit from caching
batches during the
first walk through the data. This PR introduces `CachedLoader`, which
transfers
batches to a pointed device and caches them. Additionally, an auxiliary
function was provided,
`make_batches_cacheable`, which decorates `BasicGNN` instance with a
custom inference
loop.

Selected performance results (gained on Intel PVC):
```
Speedup:
gcn[2L]+Reddit: 1.53x
gcn[3L]+Reddit: 1.69x
sage[2L]+Reddit: 1.55x
sage[3L]+Reddit: 2.02x
gcn[2L]+ogbn-products: 1.72x
gcn[3L]+ogbn-products: 2.11x
sage[2L]+ogbn-products: 1.83x
sage[3L]+ogbn-products: 2.44x
```
Caching mechanism did not have a significant impact on models with a
single layer.

Drawbacks:
- User should be aware that caching mechanism requires additional device
memory to be allocated.
In experiments, approximately 1GB was needed for the `Reddit` dataset.

---------

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>
JakubPietrakIntel pushed a commit that referenced this pull request Sep 27, 2023
This PR adds `--cached-loader` option, that enables `CachedLoader` in
inference loop.

Waiting for #7896.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Matthias Fey <matthias.fey@tu-dortmund.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants