Hi,
Thank you ptrblck.
I changed my model to:
class Model(nn.Module):
    def __init__(self):
        super(Model,self).__init__()
        self.conv1 = nn.Conv2d(in_channels=1, out_channels=64, kernel_size=3, padding=0, bias=True)
        self.conv2 = nn.Conv2d(in_channels=64, out_channels=64, kernel_size=3, padding=0, bias=True)
        self.dropout = nn.Dropout(0.5)
        self.fc1 = nn.Linear(12*12*64, 128)
        self.fc2 = nn.Linear(128, 10)

    def last_hidden_layer_output(self, X):
        X = F.relu(self.conv1(X))
        X = self.dropout(F.max_pool2d(F.relu(self.conv2(X)),2))
        X = X.view(-1, 12*12*64)
        X = self.dropout(F.relu(self.fc1(X)))
        return X

    def forward(self, X):
        X = self.last_hidden_layer_output(X)
        X = self.fc2(X)
        return X

I calculate loss like this:
        output = model(data)
        loss = F.nll_loss(F.log_softmax(output, dim=1), target)

I got predictions like this:
predictions = F.softmax(model(data), dim=1).data.argmax(1, keepdim=True)

I got last hidden layer output like this:
model.last_hidden_layer(data).data