Question about the order of fanouts in dgl.dataloading.MultiLayerNeighborSampler

From the doc of dgl.dataloading.MultiLayerNeighborSampler:

fanouts: List of neighbors to sample per edge type for each GNN layer, starting from the first layer.

If I train a graphSAGE model with 3 layers using dgl.dataloading.EdgeDataLoader, according to https://docs.dgl.ai/guide/minibatch.html, to my understanding, the first layer contains all the input nodes (3-hop neighbors of the output nodes). The second layer contains 2-hop neighbors and the third layer contains 1-hop neighbors.

My question is: does the fanouts parameter follows this order? If fanouts=[10, 15, 20], does this mean 20 neighbors will be sampled from 1-hop neighbors for layer-3, 15 from 2-hop neighbors for layer-2 and 10 from 3-hop neighbors for layer-1?

It samples 10 1-hop neighbors for the 1st GNN layer, 15 2-hop neighbors for the 2nd GNN layer, and 20 3-hop neighbors for the 3rd GNN layer.

I think there is a difference between sampling order and GNN layer order. From the picture of https://docs.dgl.ai/guide/minibatch.html, to my understanding, the GNN layers order is from right to left. The right most sub graph contains the nodes needed for the first GNN layer. While the sampling order is from left to right.

From the example code of graphSAGE, I’ve checked the blocks’ source node number generated by dgl.dataloading.EdgeDataLoader and it’s decreasing with block order. And the forward function is defined as:

def forward(self, blocks, x):
    h = x
    for l, (layer, block) in enumerate(zip(self.layers, blocks)):
        h = layer(block, h)
        if l != len(self.layers) - 1:
            h = self.activation(h)
            h = self.dropout(h)
    return h

This means the convolution of all 1-3 hop neighbors happens at the first layer while the last layer only does convolution for 1-hop neighbors. And this is also identical to the minibatch pseudocode from graphSAGE paper’s appendices.

Please correct me if my understanding is wrong.

I think your understanding is correct. The neighbors sampled from all hops are merged for the first block.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.