RuntimeError: mat1 and mat2 shapes cannot be multiplied (1x128 and 2x128)

“”"

class ActorCritic(nn.Module):
def init(self, input_dims, n_actions, gamma=0.99):
super(ActorCritic, self).init()
self.gamma = gamma

    self.policy1 = nn.Linear(*input_dims, 128)
    self.value1 = nn.Linear(*input_dims, 128)
    self.policy = nn.Linear(n_actions,128)
    self.value = nn.Linear(128, 1)

    self.rewards = []
    self.actions = []
    self.states = []

def remember(self,reward, action, state):
    self.rewards.append(reward)
    self.actions.append(action)
    self.states.append(state)

def clear_memory(self):
    self.rewards = []
    self.actions = []
    self.states = []

def forward(self, state):
    print('forward function state value: {} '.format(state.shape))
    pi1 = F.relu(self.policy1(state))
    v1 = F.relu(self.value1(state))

    pi = self.policy(pi1)
    v = self.value(v1)
    return pi, v

“”"

I tried logging the shape of the input in forward function below
“”"
forward function state value: torch.Size([1, 4])
C:\Users\olufi\PycharmProjects\RL-A3C\actor_critic.py:68: UserWarning: Creating a tensor from a list of numpy.ndarrays is extremely slow. Please consider converting the list to a single numpy.ndarray with numpy.array() before converting to a tensor. (Triggered internally at …\torch\csrc\utils\tensor_new.cpp:201.)
state = T.tensor([observation], dtype=T.float)
C:\Users\olufi\PycharmProjects\RL-A3C\actor_critic.py:68: UserWarning: Creating a tensor from a list of numpy.ndarrays is extremely slow. Please consider converting the list to a single numpy.ndarray with numpy.array() before converting to a tensor. (Triggered internally at …\torch\csrc\utils\tensor_new.cpp:201.)
state = T.tensor([observation], dtype=T.float)
forward function state value: torch.Size([1, 4])
C:\Users\olufi\PycharmProjects\RL-A3C\actor_critic.py:68: UserWarning: Creating a tensor from a list of numpy.ndarrays is extremely slow. Please consider converting the list to a single numpy.ndarray with numpy.array() before converting to a tensor. (Triggered internally at …\torch\csrc\utils\tensor_new.cpp:201.)
state = T.tensor([observation], dtype=T.float)
forward function state value: torch.Size([1, 4])
C:\Users\olufi\PycharmProjects\RL-A3C\actor_critic.py:68: UserWarning: Creating a tensor from a list of numpy.ndarrays is extremely slow. Please consider converting the list to a single numpy.ndarray with numpy.array() before converting to a tensor. (Triggered internally at …\torch\csrc\utils\tensor_new.cpp:201.)
state = T.tensor([observation], dtype=T.float)

“”"

I don’t know how you’ve initialized the model and in particular which shapes you’ve used to initialize the layers, but the shape mismatch is most likely raised by a linear layer.
Print the shape of the input activation to each layer and make sure its feature dimension matches the expected in_features of the layer.