def to_gpu(self): super(Encoder, self).to_gpu() for i in range(self.num_layers): h = self.get_h(i) c = self.get_c(i) if h is not None: h.to_gpu() if c is not None: c.to_gpu()