# Why use Sequential or not will have different performance?

Hi,
All the other settings are the same, why these two methods will get different performance.

``````class net1(nn.Module):
def __init__(self):
super(net1, self).__init__()
self.conv1 = nn.Conv2d(1,16,5,1,2)
self.conv2 = nn.Conv2d(16,32,5,1,2)
self.pool1 = nn.MaxPool2d(2)
self.pool2 = nn.MaxPool2d(2)
self.fc1 = nn.Linear(32*7*7,10)

def forward(self, x):
out = F.relu(self.conv1(x))
out = self.pool1(out)
out = F.relu(self.conv2(out))
out = self.pool2(out)

out = out.view(-1,32*7*7)
out = F.relu(self.fc1(out))
return out

class net2(nn.Module):
def __init__(self):
super(net2, self).__init__()
self.conv1 = nn.Sequential(
nn.Conv2d(
in_channels=1,
out_channels=16,
kernel_size=5,
stride=1,
),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2),
)
self.conv2 = nn.Sequential(
nn.Conv2d(16, 32, 5, 1, 2),
nn.ReLU(),
nn.MaxPool2d(2),
)
self.out = nn.Linear(32 * 7 * 7, 10)

def forward(self, x):
x = self.conv1(x)
x = self.conv2(x)
x = x.view(x.size(0), -1)
output = self.out(x)
return output``````

Because unrolled computation is always faster than for-loops.