def train_model(X,y,epochs=100):
    cnt=0
    model = CNN()
    #loss_fn = F.cross_entropy()
    loss_accumulated = 0
    model=model.cuda()
    #trainloader = torch.utils.data.DataLoader(X, batch_size=32, shuffle=True, num_workers=8)
    #trainloader_label=torch.utils.data.DataLoader(y, batch_size=32, shuffle=True, num_workers=8)
    optimizer = torch.optim.SGD(model.parameters(),lr=0.05,momentum=0.01)
    for i in range(epochs):
        for data,label in zip(X,y):
            data, target = Variable(torch.LongTensor([data])).cuda(), Variable(torch.LongTensor([label])).cuda()
            model.zero_grad()
            logit=model(data)
            cnt+=1
            loss=F.cross_entropy(logit,target)
            loss.backward()
            loss_accumulated+=loss.data
            #print(loss.data)
            optimizer.step()
        if i%10==0:
            print("Sleeping ...")
            time.sleep(5)
        print("Epoch is "+ str(i))
        print(loss_accumulated)
    torch.save(model.state_dict(), "CNN_params.pkl")

this is my training code