Md. Asif Uddin
    Problem I.14.B04

    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

    n=106n=10^6 nodes, m=107m=10^7 undirected edges, width d=128d=128, 3232-bit floats for the dense matrix and 6464-bit integers for the edge list. For sampling, 2525 neighbours per node in the first layer and 1010 in the second.

    FIND

    Multiply-accumulates for A^H\hat{\mat A}\mat H dense and sparse, and for HW\mat H\mat W; memory for the dense A^\hat{\mat A} 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 n×nn\times n matrix with an n×dn\times d matrix costs n2d=1.28×1014n^2d=1.28\times10^{14} multiply-accumulates. With an edge list, each of the 2m2m directed entries adds one dd-vector: 2md=2.56×1092md=2.56\times10^9. The weight product HW\mat H\mat W costs nd2=1.64×1010nd^2=1.64\times10^{10} either way. The sparse layer totals 1.89×10101.89\times10^{10}, about 6,8006{,}800 times less than the dense product alone.

    Memory. The dense A^\hat{\mat A} needs n2⋅4=4×1012n^2\cdot4=4\times10^{12} bytes, four terabytes, almost all of them zeros. The edge list needs 2m⋅2⋅8=3.2×1082m\cdot2\cdot8=3.2\times10^8 bytes, 320320 megabytes.

    Receptive field. The average degree is 2m/n=202m/n=20. A node has about 2020 neighbours, each with about 2020 more, so within three hops there can be up to 203=8,00020^3=8{,}000 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 2525 neighbours per node for the first layer and 1010 for the second bounds a two-layer neighbourhood at 25×10=25025\times10=250 nodes, whatever the degrees. Hamilton, Ying and Leskovec (2017) trained on large graphs this way.

    Answer

    Dense A^H\hat{\mat A}\mat H: 1.28×10141.28\times10^{14}; sparse: 2.56×1092.56\times10^9; HW\mat H\mat W: 1.64×10101.64\times10^{10}; sparse layer 1.89×10101.89\times10^{10}. Dense matrix 4×10124\times10^{12} bytes; edge list 3.2×1083.2\times10^8. Average degree 2020; up to 8,0008{,}000 nodes in three hops; 250250 with sampling over two layers.

    Check — sanity

    On a sparse graph the neighbour sums are cheaper than the weight product: 2md<nd22md<nd^2 exactly when the average degree 2m/n2m/n is below dd, here 20<12820<128.

    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 d=16d=16 the weight product shrinks to 2.56×1082.56\times10^8, and the neighbour sums, 3.2×1083.2\times10^8, dominate. Narrow graph networks are limited by the edges, wide ones by the weights.

    Draws on