Hi,
I want to design a network estimating new step of the signal so I’ve started with a simple sin wave. While investigating network I noticed that weights are not changing. What could be the reason? I cannot find any explanation.
class Model(nn.Module):
    def __init__(self,in_dim,hidden_dim,num_classes):
        super(Model, self).__init__()
        self.layer1 = nn.Linear(in_dim,hidden_dim)
        self.layer2 = nn.Linear(hidden_dim,hidden_dim)
        self.layer3 = nn.Linear(hidden_dim,num_classes)
        self.relu = nn.ReLU()
        self.out = nn.LogSoftmax(dim=0)

    def forward(self,x):
        a = self.relu(self.layer1(x))
        a = self.relu(self.layer2(a))
        return self.relu(self.layer3(a))

def train(epoch,L,depth):
    criteria = nn.MSELoss()
    learning_rate = 1e-3
    optimizer = torch.optim.Adam(model.parameters(), lr=learning_rate)

    t = np.linspace(0,2,L+1)       
    fs = L+1
    
    trn_loss = list()
        
    for f in range(0,epoch):
        phase = f/np.pi      
        x = np.sin(2*np.pi*t*fs+phase)   
        x = torch.from_numpy(x).float()
        
        optimizer.zero_grad()
        
        x_hat = model(x[:-1])
            
        currentCost = criteria(x_hat,x[-1])
        trn_loss.append(currentCost.item())
        print(model.layer1.weight.data.clone())
        currentCost.backward()
        optimizer.step()
        print(model.layer1.weight.data.clone())

and outputs are:
tensor([[-0.1715, -0.1696,  0.0424,  ...,  0.0154,  0.1450, -0.0544],
        [ 0.0368,  0.1427, -0.1419,  ...,  0.0966,  0.0298, -0.0659],
        [-0.1641, -0.1551,  0.0570,  ..., -0.0227, -0.1426, -0.0648],
        ...,
        [-0.0684, -0.1707, -0.0711,  ...,  0.0788,  0.1386,  0.1546],
        [ 0.1401, -0.0922, -0.0104,  ..., -0.0490,  0.0404,  0.1038],
        [-0.0604, -0.0517,  0.0715,  ..., -0.1200,  0.0014,  0.0215]])
tensor([[-0.1715, -0.1696,  0.0424,  ...,  0.0154,  0.1450, -0.0544],
        [ 0.0368,  0.1427, -0.1419,  ...,  0.0966,  0.0298, -0.0659],
        [-0.1641, -0.1551,  0.0570,  ..., -0.0227, -0.1426, -0.0648],
        ...,
        [-0.0684, -0.1707, -0.0711,  ...,  0.0788,  0.1386,  0.1546],
        [ 0.1401, -0.0922, -0.0104,  ..., -0.0490,  0.0404,  0.1038],
        [-0.0604, -0.0517,  0.0715,  ..., -0.1200,  0.0014,  0.0215]])