class_docstr: Improved version over VectorQuantizer, can be used as a drop-in replacement. Mostly
  avoids costly matrix multiplications and allows for post-hoc remapping of indices.
class_docstr_tok: ["Improved","version","over","VectorQuantizer",",","can","be","used","as","a","drop-in","replacement",".","Mostly","avoids","costly","matrix","multiplications","and","allows","for","post-hoc","remapping","of","indices","."]
code: def remap_to_used(self, inds):
      ishape = inds.shape
      assert len(ishape) > 1
      inds = inds.reshape(ishape[0], -1)
      used = self.used.to(inds)
      match = (inds[:, :, None] == used[None, None, ...]).long()
      new = match.argmax(-1)
      unknown = match.sum(2) < 1
      if self.unknown_index == "random":
          new[unknown] = torch.randint(
              0, self.re_embed, size=new[unknown].shape
          ).to(device=new.device)
      else:
          new[unknown] = self.unknown_index
      return new.reshape(ishape)
  
file_path: stable-diffusion-webui/extensions-builtin/LDSR/vqvae_quantize.py
imports: import torch
  import torch.nn
  import numpy
  from einops import rearrange
label_desc: Use image node_id 2 for calling the VectorQuantizer2 obj's underlying member method code with example usage: obj.remap_to_used(inds) and returns: new