Beginner - questions on tutorial example 1 - how forward is applied in gradient descent

Starting from 0, little knowledge of pytorch but some knowledge about key concepts thanks to deeplearning course of Andrew Ng.

Q1. Can you clarify how / when functions forward() of classes for GCNLayer and GCN model are called ?

Look at the python code dfining the classes for GCNLayer and GCN model.

A net is defined by passing the number or tensors ( corresponding to number of nodes ), size of hidden layer and final size of output, here 2 as a binary classifier.

example for a network of 34 nodes in Zachary demo:
net = GCN(34, 5, 2)

but then inputs to the model are fed like this:
logits = net(G, inputs)

Why not like by calling the forward functions, like this: logits = net**.forward**(G, inputs) ?

Q2. ** Understanding how the model works **

By reading at the description of a GCN by Kipf and Welling, I understand a message-passing model computes, at each step (layer) a convolution of vectors associated to node’s neighbours into a “resulting” node’s property.

I am reading at pytorch documentation about the Functional model

and reading code here:

    logits = net(G, inputs)
    # we save the logits for visualization later
    logp = F.log_softmax(logits, 1)
    # we only compute loss for labeled nodes
    loss = F.nll_loss(logp[labeled_nodes], labels)



I don’t understand how forward is computed in the gradient descent.

How the forward funciton are called?
Where the convolution are applied ?
(I suspect in the GCNLayer, but willing to understand better how it works, also in terms of how code structured respect to pytorch apis).

Thank you

The GCN class inherits nn.Module, which calls forward in __call__, i.e. net.forward(G, inputs) is part of net(G, inputs). In addition, __call__ also helps handling stuff like gradients.

The convolution is defined in GCN and it is applied during net(...).