code: def encode(
      self, x: torch.Tensor, return_reg_log: bool = False
  ) -> Union[torch.Tensor, Tuple[torch.Tensor, dict]]:
      if self.max_batch_size is None:
          z = self.encoder(x)
          z = self.quant_conv(z)
      else:
          N = x.shape[0]
          bs = self.max_batch_size
          n_batches = int(math.ceil(N / bs))
          z = list()
          for i_batch in range(n_batches):
              z_batch = self.encoder(
                  x[i_batch * bs : (i_batch + 1) * bs]
              )
              z_batch = self.quant_conv(z_batch)
              z.append(z_batch)
          z = torch.cat(z, 0)
  
      z, reg_log = self.regularization(z)
      if return_reg_log:
          return z, reg_log
      return z
  
imports: import logging
  import math
  import re
  from abc import abstractmethod
  from contextlib import contextmanager
  from typing import Any, Dict, List, Optional, Tuple, Union
  import pytorch_lightning
  import torch
  import torch.nn
  from einops import rearrange
  from packaging import version
  from ..modules.autoencoding.regularizers import AbstractRegularizer
  from ..modules.ema import LitEma
  from ..util import default, get_nested_attribute, get_obj_from_str, instantiate_from_config
label_desc: Use image node_id 3 for calling the AutoencodingEngineLegacy obj's underlying member method code with example usage: obj.encode(x, return_reg_log) and returns: z, z,  reg_log