Difference between functional interface and Modules list interface?

Hi, when we define a network architecture, we might happened to see the following case which seems have the same effect:

class Net(nn.Module):
	def __init__(self):
		super(Net, self).__init__()
		self.block = nn.Sequential(
			nn.Conv2d(3, 16, kernel_size=3, padding=1),
			nn.BatchNorm2d(16),
			nn.ReLU(),
			nn.MaxPool2d(kernel_size=4, stride=4)
		)
		self.fc = nn.Linear(64 * 16, 10)

	def forward(self, x):
		x = self.block(x)
		x = x.view(x.size(0), -1)
		x = self.fc(x)

		return x


class NewNet(nn.Module):
	def __init__(self):
		super(Net, self).__init__()
		
		self.conv = nn.Conv2d(3, 16, kernel_size=3, padding=1)
		self.bn = nn.BatchNorm2d(16)
		self.fc = nn.Linear(64 * 16, 10)

	def forward(self, x):
		x = self.bn(self.conv(x))
		x = F.max_pool2d(F.relu(x), 4, stride=4)

		x = x.view(x.size(0), -1)

		x = self.fc(x)

		return x

My question is: what is the difference between the functional interface and the module sequential list interface? How will we choose between them and in what situation should we choose the functionality case?

1 Like

Search first before you ask. A simple search lead to, e.g., this post.

1 Like

Thanks for the post link.

Not. A any no matter what.