Thank you for pointing this out. I have managed to fix the first error by accessing state[0].shape instead of state.shape.
However, my second error still persists. What bothers me is that the dimension of state[0].shape is torch.Size([2, 4, 16]), while the first dimension I need is 7. Since 7 is not divisible by 2, I don’t see a way to make the context variable have 7 as its first dimension.