I’m unable to reproduce this error with the code you’ve shared.
import torch
from torch import nn

class grLipNSSM(nn.Module):

  def __init__(self, input_dim = 10, hidden_dim = 15,  state_dim = 10,  output_dim = 10, init_mode = 'random'):
          super(grLipNSSM, self).__init__()

          # Number of Input neurons
          self.input_dim = input_dim

          # Number of hidden dimensions
          self.hidden_dim = hidden_dim

          # Size of the state space
          self.state_dim = state_dim

          # Number of output dimensions
          self.output_dim = output_dim

          # Activation functions
          self.actF = torch.nn.Tanh()

          # Input layer for the state W_u
          self.input_layer = nn.Linear(self.input_dim, self.hidden_dim, bias=False)

          # First state layer
          self.state_layer = nn.Linear(self.state_dim, self.hidden_dim)

          # Nonlinear part for the state
          self.NL1 = nn.Linear(self.hidden_dim, self.state_dim)

          # Residual block
          self.residualA = nn.Linear(self.state_dim, self.state_dim, bias= False)
          self.residualB = nn.Linear(self.input_dim, self.state_dim, bias= False)

        
          # Output layers

          self.input_layer2 = nn.Linear(self.input_dim, self.hidden_dim, bias= False)
          self.state_layer2 = nn.Linear(self.state_dim, self.hidden_dim)
          self.NL2 = nn.Linear(self.hidden_dim, self.output_dim)
          self.residualC = nn.Linear(self.state_dim, self.output_dim, bias= False)
          self.residualD = nn.Linear(self.input_dim, self.output_dim, bias= False) 


  def forward(self, u, state = torch.zeros(1, 10)):

          # Forward pass -- prediction of the output at time k : y_k

          x_0 = self.input_layer2(u)

          # Skip connections layers

          sc_A = self.residualA(state)
          sc_B = self.residualB(u)
          sc_C = self.residualC(state)
          sc_D = self.residualD(u)

          # Hidden layers in the non linear part
          h1 = self.state_layer(state)
          h2 = self.state_layer2(state)
          x_1 = self.actF((x_0 + h2)) #Add another activation function
          x_2 = self.NL2(x_1)
          y_k = x_2 + sc_C + sc_D

      
          # Updating the state
          x_3 = self.input_layer(u)
          x_4 = self.actF(x_3+ h1)
          x_5 = self.NL1(x_4)

          #Adding the linear part (skip connection)
          state = x_5 + sc_A + sc_B
          return y_k, state

mdl = grLipNSSM()
loss = 0
for _ in range(3):
  l,m = mdl(torch.rand(5,10))
  loss += torch.mean(torch.pow(l - torch.rand_like(l), 2))
loss.backward()

works fine for me