pytorch model not updating
I put my training code below. I am using  torch.optim.SGD as optimizer. I thought optimizer.step() would be doing the update but the model accuracy seems to stay the same. My friend said he didn't use the optimizer.step() and his works fine.
I tried taking it out, still the same result. What can I be doing wrong? 
I don't think there's a problem with the accuracy calculation.

class FNet(nn.Module):
    def __init__(self, **kwargs): 
        super().__init__()
        self.fc1 = nn.Linear(128*256, 1024) 
        self.fc2 = nn.Linear(1024, 256)
        self.fc3 = nn.Linear(256, 2)

    def forward(self, X): 
        X = F.relu(self.fc1(X))
        X = F.relu(self.fc2(X))
        X = self.fc3(X)
        return F.softmax(X, dim=1)



def main():

    learning_rate = 0.01
    model = FNet()
    optimizer = torch.optim.SGD(model.parameters(), lr=learning_rate, momentum=0.9, weight_decay=5e-04) # you can play with momentum and weight_decay parameters as well
    accs = [0,]

    for epoch in range(max_epoch):

        train(epoch, model, optimizer, train_batch)

        acc = test(model, val_batch)
        accs.append(acc)


def train(epoch, model, optimizer, trainloader):
    model.train()
    optimizer.zero_grad()
    for batch_idx, (data, labels) in enumerate(trainloader):

        outputs = model(data)
        loss = F.nll_loss(outputs, labels)
        loss.backward()

        optimizer.step()


def test(model, testloader):
    correct = 0
    total = 0
    model.eval()

    for batch_idx, (data, labels) in enumerate(testloader):

            outputs = model(data.view(-1,128*256))

            for sample_idx,output in enumerate(outputs):

                if torch.argmax(output) == labels[sample_idx]:
                    correct = correct + 1
                total = total + 1

    accuracy = correct/total
    return accuracy


I think this line should be under your for loop
optimizer.zero_grad(). You need to clear the parameter gradients after each loop.  

try this

def train(epoch, model, optimizer, trainloader):
    model.train()
    for batch_idx, (data, labels) in enumerate(trainloader):
        optimizer.zero_grad()
        outputs = net(data)
        loss = F.nll_loss(outputs, labels)
        loss.backward()

        optimizer.step()

