code: def decode(
      codec: BitsBackCodec,
      save_dir: Union[str, Path],
      save_interval: int,
  ):
      """
      Decode data using Bits-Back coding.
  
      Args:
          codec: Codec to use for decoding.
          save_dir: Directory to save the data.
          save_interval: Interval after which to save a checkpoint.
      """
      save_dir = Path(save_dir)
      while codec.data_count > 0:
          _, data = codec.decode()
          out_path = save_dir / f"batch{codec.data_count:05d}.npz"
          np.savez(out_path, batch=data.astype(np.int32))
          num_remaining = codec.data_shape[0] * codec.data_count
          logger.log(f"{num_remaining} samples remaining...")
  
          # checkpoint
          if num_remaining % save_interval < codec.data_shape[0]:
              ckpt_path = (
                  save_dir / f"decode-ckpt{-num_remaining:06d}.npz"
              )
              np.savez(ckpt_path, **codec.state_dict())
  
file_path: NeuralCompression/projects/bits_back_diffusion/encode.py
imports: from itertools import islice
  from pathlib import Path
  from typing import Dict, Iterator, List, Tuple, Union
  import hydra
  import numpy
  import torch
  import torch.distributed
  import wandb
  from bits_back_diffusion.codec import BitsBackCodec
  from bits_back_diffusion.script_util import plot_evolution, setup, update_checkpoint
  from improved_diffusion import logger
  from omegaconf import DictConfig
label_desc: Use image node_id 3 for calling a global function with example usage: decode(codec, save_dir, save_interval) without return types