Ah I now see that you’re storing the Variables in the tree, because you need to read them from the higher parts. In this case you can’t unpack the .data, because you need the backprop to include the lower parts of the tree too.
The problem I see is that you’re not clearing the Variables/tensors stored in the trees after you finish the iteration. You could try writing a simple function that traverses the tree and dels all outputs after computing output = self.model(p_tree, h_tree) (you need to clean both trees). This should reduce the memory usage.