Were you able to isolate this issue further or do you have a reproducible code snippet or is this issue reproducible using just the provided information regarding W_theta and W_hat?
Also, could you share the shapes of x and a?