code: def __init__(
      self,
      n_embed: int,
      embedding_dim: int,
      beta: float,
      decay: float = 0.99,
      eps: float = 1e-5,
      remap: Optional[str] = None,
      unknown_index: str = "random",
      loss_key: str = "loss/vq",
  ):
      super().__init__()
      self.codebook_dim = embedding_dim
      self.num_tokens = n_embed
      self.beta = beta
      self.loss_key = loss_key
  
      self.embedding = EmbeddingEMA(
          self.num_tokens, self.codebook_dim, decay, eps
      )
  
      self.remap = remap
      if self.remap is not None:
          self.register_buffer(
              "used", torch.tensor(np.load(self.remap))
          )
          self.re_embed = self.used.shape[0]
      else:
          self.used = None
          self.re_embed = n_embed
      if unknown_index == "extra":
          self.unknown_index = self.re_embed
          self.re_embed = self.re_embed + 1
      else:
          assert unknown_index == "random" or isinstance(
              unknown_index, int
          ), "unknown index needs to be 'random', 'extra' or any integer"
          self.unknown_index = (
              unknown_index  # "random" or "extra" or integer
          )
      if self.remap is not None:
          logpy.info(
              f"Remapping {self.n_embed} indices to {self.re_embed} indices. "
              f"Using {self.unknown_index} for unknown indices."
          )
  
imports: import logging
  from abc import abstractmethod
  from typing import Dict, Iterator, Literal, Optional, Tuple, Union
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from einops import rearrange
  from torch import einsum
  from .base import AbstractRegularizer, measure_perplexity
label_desc: Use image node_id 1 to create a new EMAVectorQuantizer object from inherited base classes: AbstractQuantizer with example: obj = EMAVectorQuantizer(n_embed, embedding_dim, beta, decay, eps, remap, unknown_index, loss_key)