What a graph layer costs
complexity▲▲△Three significant figures.
STATEMENT
Count the work and memory of one graph-convolution layer on a large sparse graph, with a dense adjacency matrix and with an edge list, and count how fast a node’s receptive field grows with depth.
GIVEN
nodes, undirected edges, width , -bit floats for the dense matrix and -bit integers for the edge list. For sampling, neighbours per node in the first layer and in the second.
FIND
Multiply-accumulates for dense and sparse, and for ; memory for the dense and for the edge list; the average degree; a bound on the nodes a three-layer prediction can depend on; the bound with sampling for two layers.
STRATEGY
Use (I.14.9). Each undirected edge is stored as two directed entries, each with two indices.
SOLUTION
Work. A dense product of an matrix with an matrix costs multiply-accumulates. With an edge list, each of the directed entries adds one -vector: . The weight product costs either way. The sparse layer totals , about times less than the dense product alone.
Memory. The dense needs bytes, four terabytes, almost all of them zeros. The edge list needs bytes, megabytes.
Receptive field. The average degree is . A node has about neighbours, each with about more, so within three hops there can be up to nodes, and a three-layer prediction for one node can depend on all of them. Computing it exactly for a batch of targets means gathering their neighbourhoods first.
Sampling. Drawing neighbours per node for the first layer and for the second bounds a two-layer neighbourhood at nodes, whatever the degrees. Hamilton, Ying and Leskovec (2017) trained on large graphs this way.
Answer
Dense : ; sparse: ; : ; sparse layer . Dense matrix bytes; edge list . Average degree ; up to nodes in three hops; with sampling over two layers.
Check — sanity
On a sparse graph the neighbour sums are cheaper than the weight product: exactly when the average degree is below , here .
Where this breaks
The counts assume the edge list is processed with gather and scatter operations whose cost is proportional to the work. On hardware tuned for dense products, irregular memory access can make the sparse layer slower per operation, though never by the four orders of magnitude separating the two counts.
Variation
At width the weight product shrinks to , and the neighbour sums, , dominate. Narrow graph networks are limited by the edges, wide ones by the weights.