Layer shape computation in convolutional neural net (pyTorch)
Well, with conv layers in pyTorch, you don't need to specify the input size except the number of channels/depth. However, you need to specify it for fully connected layers.
So, when defining the input dimension of the first linear layer, you have to know what is the size of the images you feed. 

You can find information on the output size calculation of conv layers and pooling layers here and here or here

If you feed images of size 32x32, the outputs layer by layer of this model are : 


conv1 : $6$ feature maps of size $\left \lfloor{\frac{32 + 2\times0 -1\times(3-1)-1}{1}+1}\right \rfloor   = 30$  
max_pool2d: $6$ feature maps of size $\left \lfloor{\frac{30 + 2\times0 -1\times(2-1)-1}{2}+1}\right \rfloor = 15$  
conv2 : $16$ feature maps of size $\left \lfloor{\frac{15+ 2\times0 -1\times(3-1)-1}{1}+1}\right \rfloor = 13$ 
max_pool2d: $16$ feature maps of size $\left \lfloor{\frac{13+ 2\times0 -1\times(2-1)-1}{2}+1}\right \rfloor = 6$ 


Therefore, for the flattened size of the output before the first linear layer is $16\times6\times6$ :

 self.fc1 = nn.Linear(16 * 6 * 6, 120)


By doing all sizes calculations in reverse, you could have find that the input size must be $32\times32$.