docstr: Collater utility for using QuantizeDataset within a DataLoader.
  Args:
      samples (_type_): Samples to collate.
  
  Returns:
      Dict[str, Union[Any, torch.Tensor]: Per-stream collated samples.
      The unit stream is padded with QuantizeDataset.unit_pad while other streams are padded
      with zeros. The non-audio parts of the samples (i.e. those that are in
      sample["rest"]) are not collated and are returned as-is under the "rest" key.
docstr_tok: ["Collater","utility","for","using","QuantizeDataset","within","a","DataLoader",".","Args",":","samples","(","_type_",")",":","Samples","to","collate",".","Returns",":","Dict","[","str",",","Union","[","Any",",","torch.Tensor","]",":","Per-stream","collated","samples",".","The","unit","stream","is","padded","with","QuantizeDataset.unit_pad","while","other","streams","are","padded","with","zeros",".","The","non-audio","parts","of","the","samples","(","i.e",".","those","that","are","in","sample","[","``","rest","''","]",")","are","not","collated","and","are","returned","as-is","under","the","``","rest","''","key","."]
code: def collater(self, samples: List[Any]):
      """Collater utility for using QuantizeDataset within a DataLoader.
      Args:
          samples (_type_): Samples to collate.
  
      Returns:
          Dict[str, Union[Any, torch.Tensor]: Per-stream collated samples.
          The unit stream is padded with QuantizeDataset.unit_pad while other streams are padded
          with zeros. The non-audio parts of the samples (i.e. those that are in
          sample["rest"]) are not collated and are returned as-is under the "rest" key.
      """
      units = collate_tensors(
          [s["units"] for s in samples], pad=self.unit_pad
      )
      if "f0" in samples[0]:
          f0 = collate_tensors(
              [s["f0"] for s in samples],
              pad=torch.zeros_like(samples[0]["f0"][0]),
          )
      else:
          f0 = None
      durations = collate_tensors(
          [s["durations"] for s in samples],
          pad=torch.zeros_like(samples[0]["durations"][0]),
      )
  
      bsz = len(samples)
      dense_dim = samples[0]["dense"].size(1)
      max_len = max(s["dense"].size(0) for s in samples)
  
      dense = torch.zeros((bsz, max_len, dense_dim))
      for i, s in enumerate(samples):
          l = s["dense"].size(0)
          dense[i, :l, :] = s["dense"]
  
      n_rest = len(samples[0]["rest"])
      _slice = lambda i: [s["rest"][i] for s in samples]
  
      rest = [_slice(i) for i in range(n_rest)]
  
      result = {
          "units": units,
          "durations": durations,
          "dense": dense,
          "rest": rest,
      }
      if f0 is not None:
          result["f0"] = (f0,)
      return result
  
imports: from typing import Callable, Union, Optional, Any, Dict, List
  import pathlib
  import torch
  import logging
  from torchaudio.datasets import LIBRISPEECH, LJSPEECH, COMMONVOICE, VCTK_092, YESNO
  from torch.utils.data import Dataset
  from textless.data.speech_encoder import SpeechEncoder
  from textless.data.collater_utils import collate_tensors
label_desc: Use image node_id 5 for calling the QuantizeDataset obj's underlying member method code with example usage: obj.collater(samples) and returns: result