I have completely removed gap calculation and im doing a dummy mean to get the G, which i pass to the loss function now. all my variables are requires_grad True. but loss is still constant. Can you maybe try running the code as well?
def calculate_gap(output,x, Wks, s_prime):
    list_of_G = []
    Wks = torch.tensor(Wks)
    output = torch.tensor(output)
    x = torch.reshape(x, (1000, 2, 6))
    print(output)
    for i, weight in enumerate(output):
        Wk = weight * x[:,:,i]
        G = torch.mean(Wk)
   return G

def my_loss(g):
    loss = torch.square(1./g)
    return loss

in_features = 12000
out_features = 6
model = nn.Sequential(nn.Linear(in_features, out_features))
optimizer = torch.optim.SGD(model.parameters(), lr=0.000001)
print(model)
x = get_data()
for n in range(10):
    x.requires_grad_(True) 
    output = model(x)
    g = calculate_gap(output, x, Wks, s_prime)
    print(g.requires_grad)
    loss = my_loss(g)
    print(loss.requires_grad)
    loss = Variable(loss, requires_grad = True)
    print('LOSS', loss)
    loss.backward()
    optimizer.step()