Hi, I am still very new to PyTorch and after searching google for this doubt I could not find anything. Hopefully, someone could help me.
I have a forward() method that looks as follows:

  def forward(self, feature_vector):
      activation_function = {'tanh': torch.tanh, 'relu': F.relu}

      symbol, X = feature_vector

      X = self.backend.from_numpy(X)

      for i, l in enumerate(self.linears[symbol]):
          if i != self.out_layer_indices[symbol]:
              X = activation_function[self.activation_function](l(X))
          else:
              X = l(X)

       X = (self.slope[symbol] * X) + self.intercept[symbol]
      return X


The problem I have is with the line before the return. I also have a method called train where I defined self.slope and self.intercept using a python dictionary:
      self.slope = {}
      self.intercept = {}
      
       
      for symbol in unique_element_symbols:
          linears = []
      
          intercept = some operation
          intercept = self.backend.from_numpy(intercept)
          self.intercept[symbol] = Variable(intercept, requires_grad=True)
       
          slope = some operation
          slope = self.backend.from_numpy(slope)
          self.slope[symbol] = Variable(slope, requires_grad=True)
          # I create a neural network here with Linear() + nn.ModuleDict

      # Model is trained in this loop
      for epoch in range(self.epochs):     
          self.forward(tensor)
          #  some more code to have the outputs
          criterion = nn.MSELoss()
          loss = torch.sqrt(criterion(outputs, targets))
          self.optimizer.zero_grad()  # clear previous gradients
          loss.backward()
          self.optimizer.step()

If my understanding of the documentation is correct, the creation of Variable with requires_grad=True should make autograd aware of the existence of those tensors. I can see the weights of the layers are being updated but those variables I created inside the dictionary not. As they are part of the forward() method they have to affect the output and then they have to change according to the gradient. Are those variables not updated because they are in a python dictionary?
I would be glad if someone could help me to understand what would be the issue with my code.