INNER CODE UNIT · Python
device
lucidrains/vector-quantize-pytorch · vector_quantize_pytorch/evo_lookup_free_quantization.py:71
def device(self):
return self.zero.device
def forward(self, x, **kwargs):
latents = self.encoder(x)
is_2d = latents.ndim == 2
if is_2d:
latents = rearrange(latents, 'b d -> b 1 d')
quantized, indices, aux_loss = self.lfq(latents, **kwargs)
if is_2d:
quantized = rearrange(quantized, 'b 1 d -> b d')
indices = rearrange(indices, 'b 1 ... -> b ...')
reconstructed = self.decoder(quantized)
return Return(reconstructed, indices, aux_loss)