RuntimeError: shape '[10, 25]' is invalid for input of size 182

I am having an issue here i am not sure how to solve i am thinking that it might be how the input layer of the model is but i don’t see how it relates to input size of 182. I am building an a RL agent using open ai for lunar lander which inputs an observation space of 8 values and action space of 4 hence the input of 8 in the first layer

Input In [5], in test_model(agent)
      8 score = 0
     10 while not done:
---> 11     params = unpack(agent['params'])
     12     probs = model(state,params)
     13     action = torch.distributions.Categorical(probs=probs).sample()

Input In [1], in unpack(params, layers)
     21 s,e = e,
     22 print("s,e",s,e)
---> 23 weights = params[s:e].view(l)
     24 s,e= e,e+l[0]
     25 bias = params[s:e]

Here is the code with problem

def model(x,params):
    l1,b1,l2,b2,l3,b3 = params
    y = torch.nn.functional.linear(x,l1,b1)
    y = torch.nn.functional.linear(y,l2,b2)
    y = torch.nn.functional.linear(y,l3,b3)
    return y

def unpack(params,layers=[(25,8),(10,25),(4,10)]):
    unpacked = []
    for i,l in enumerate(layers):
        s,e = e,
        weights = params[s:e].view(l)
        s,e= e,e+l[0]
        bias = params[s:e]
    return unpacked

I don’t know where params is coming from but it seems slicing it via params[s:e] returns a tensor in the shape [182] which causes the view(l) operation with l=[10, 25] to fail:

x = torch.randn(182)
x.view([10, 25])
# RuntimeError: shape '[10, 25]' is invalid for input of size 182

Make sure the slicing and view operation correspond to each other as it seems the error is caused by a mismatch there.