I had encountered this issue before and  earlier used gc.collect in my forward(). But adding gc.collect() also doesn’t seem to be helping here. I have a hunch that extra variables used here are the reason for memory error.  But not sure, how should I avoid it.
Would really appreciate if someone could suggest/comment on this issue.