class_docstr: Lossless compression for Herarchical latent variable models.
  
  Based on the Craystack (https://github.com/j-towns/craystack)
  implementation of Bits-Back coding.
  
  Args:
      model: The hierarchical latent variable model.
      data_shape: The shape [batch-size, channels, height, width]
          of the data and each latent.
      latent_prec: Coding precision.
      prior_prec: Precision for the discretization.
      obs_prec: Precision for the observation codec.
      data_prec: Precision of the discrete data.
      initial_len: Length of the random initial bitstring.
      data_min: Minimum value of the data to be fed into the model.
      data_max: Maximum value of the data to be fed into the model.
      clip_stdd: Minimum value for the stdd of the observation codec.
      track: Whether to track the message sizes at each step.
class_docstr_tok: ["Lossless","compression","for","Herarchical","latent","variable","models",".","Based","on","the","Craystack","(","https",":","\/\/github.com\/j-towns\/craystack",")","implementation","of","Bits-Back","coding",".","Args",":","model",":","The","hierarchical","latent","variable","model",".","data_shape",":","The","shape","[","batch-size",",","channels",",","height",",","width","]","of","the","data","and","each","latent",".","latent_prec",":","Coding","precision",".","prior_prec",":","Precision","for","the","discretization",".","obs_prec",":","Precision","for","the","observation","codec",".","data_prec",":","Precision","of","the","discrete","data",".","initial_len",":","Length","of","the","random","initial","bitstring",".","data_min",":","Minimum","value","of","the","data","to","be","fed","into","the","model",".","data_max",":","Maximum","value","of","the","data","to","be","fed","into","the","model",".","clip_stdd",":","Minimum","value","for","the","stdd","of","the","observation","codec",".","track",":","Whether","to","track","the","message","sizes","at","each","step","."]
code: def __init__(
      self,
      model: BaseHLVModel,
      data_shape: Tuple[int, int, int, int],
      latent_prec: int = 18,
      prior_prec: int = 10,
      obs_prec: int = 24,
      data_prec: int = 8,
      initial_len: Optional[int] = None,
      data_min: float = -1.0,
      data_max: float = 1.0,
      clip_stdd: float = 1e-6,
      track: bool = False,
  ):
      # model and diffusion
      self.model = model
      if not len(data_shape) == 4:
          raise ValueError(
              f"`data_shape` is {data_shape} but should be [b, c, h, w]."
          )
      self.data_shape = data_shape
      self.data_size = np.prod(data_shape).item()
      self.data_min = data_min
      self.data_max = data_max
      self.clip_stdd = clip_stdd
  
      # codec
      self.latent_prec = latent_prec
      self.prior_prec = prior_prec
      self.obs_prec = obs_prec
      self.data_prec = data_prec
      self.track = track
      self.prior_codec = cs.Uniform(self.prior_prec)
  
      # initialize
      self.extra_bytes = 0
      self.data_count = 0
      self.push_bytes = np.zeros(self.model.steps + 1, dtype=np.uint64)
      self.pop_bytes = np.zeros(self.model.steps + 1, dtype=np.uint64)
      if initial_len is None:
          # sensible initial value to prevent popping from an empty message
          initial_len = (
              self.data_size
              * self.model.steps
              * max(self.prior_prec, self.latent_prec)
              // 32
          )
  
      self.message = cs.random_message(initial_len, self.data_size)
      self.initial_bytes = self.flat_message.nbytes
  
imports: from abc import ABC, abstractmethod
  from typing import List, NamedTuple, Optional, Tuple, Union, overload
  import craystack
  import numpy
  import torch
  from craystack import codecs
  from craystack.bb_ans import BBANS
  from improved_diffusion.gaussian_diffusion import GaussianDiffusion
label_desc: Use image node_id 1 to create a new BitsBackCodec object  with example: obj = BitsBackCodec(model, data_shape, latent_prec, prior_prec, obs_prec, data_prec, initial_len, data_min, data_max, clip_stdd, track)