The StackOverflow post is unfortunately missing the proper usage of the functional API and sets the training argument of F.dropout to fixed True or False values.
To properly enable/disable F.dropout during training and validation use out = F.dropout(x, training=self.training), since the self.trainng attribute will be switched by calling model.train() and model.eval(). The nn.Dropout module does indeed the same as seen here.