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

batching scales quadratically #99

Closed
tclements opened this issue Jan 12, 2022 · 0 comments · Fixed by #122
Closed

batching scales quadratically #99

tclements opened this issue Jan 12, 2022 · 0 comments · Fixed by #122

Comments

@tclements
Copy link
Contributor

GraphNeuralNetworks.batch scales quadratically in run time and memory use with the number of graphs to batch. Here is a MWE with benchmarks:

using BenchmarkTools
using GraphNeuralNetworks

g1 = rand_graph(4, 6, ndata=ones(8, 4));
g2 = rand_graph(7, 4, ndata=zeros(8, 7));
GraphNeuralNetworks.batch([g1, g2]);

for ngraphs in 2 .^ (8:10)
    gs = [rand_graph(4, 6, ndata=ones(8, 4)) for _ in 1:ngraphs]
    println("\n=======================\nBatchsize = $ngraphs graphs\n=======================\n")    
    b = @benchmark GraphNeuralNetworks.batch($gs)
    display(b)
end

=======================
Batchsize = 256 graphs
=======================

BenchmarkTools.Trial: 1532 samples with 1 evaluation.
 Range (min  max):  2.583 ms  6.482 ms  ┊ GC (min  max):  0.00%  54.02%
 Time  (median):     2.712 ms             ┊ GC (median):     0.00%
 Time  (mean ± σ):   3.260 ms ± 1.278 ms  ┊ GC (mean ± σ):  16.20% ± 19.62%

  ▄█▂▁
  ████▃▂▂▁▁▁▁▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▃▄▄▄▃ ▂
  2.58 ms        Histogram: frequency by time       6.33 ms <

 Memory estimate: 13.08 MiB, allocs estimate: 17790.

=======================
Batchsize = 512 graphs
=======================

BenchmarkTools.Trial: 510 samples with 1 evaluation.
 Range (min  max):   8.219 ms  11.230 ms  ┊ GC (min  max):  0.00%  21.96%
 Time  (median):     10.632 ms              ┊ GC (median):    20.63%
 Time  (mean ± σ):    9.790 ms ±  1.241 ms  ┊ GC (mean ± σ):  13.99% ± 10.61%

  ▁█                                                    ▁▂▁
  ███▆▄▂▂▁▁▁▁▁▁▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▂▄▆▆▄▄▆███▅▄ ▃
  8.22 ms         Histogram: frequency by time        11.1 ms <

 Memory estimate: 50.14 MiB, allocs estimate: 36053.

=======================
Batchsize = 1024 graphs
=======================

BenchmarkTools.Trial: 150 samples with 1 evaluation.
 Range (min  max):  32.179 ms  37.269 ms  ┊ GC (min  max): 11.89%  16.35%
 Time  (median):     32.532 ms              ┊ GC (median):    12.07%
 Time  (mean ± σ):   33.527 ms ±  1.463 ms  ┊ GC (mean ± σ):  12.63% ±  1.19%

  ▃█▇▆
  ████▅▄▅▃▃▃▃▁▁▁▁▃▃▁▁▁▁▁▃▃▃▁▃▃▁▃▄▃▆▃▅▃▄▃▃▄▅▃▃▁▁▄▁▃▁▁▃▁▁▁▃▃▃▁▃ ▃
  32.2 ms         Histogram: frequency by time          37 ms <

 Memory estimate: 196.20 MiB, allocs estimate: 73941.

I came up with a fix to the current implementation and will submit a PR soon.

tclements added a commit to tclements/GraphNeuralNetworks.jl that referenced this issue Jan 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant