code: def _filter_by_size_dynamic(
      indices, size_fn, max_positions, raise_exception=False
  ):
      def compare_leq(a, b):
          return a <= b if not isinstance(a, tuple) else max(a) <= b
  
      def check_size(idx):
          if isinstance(max_positions, float) or isinstance(
              max_positions, int
          ):
              return size_fn(idx) <= max_positions
          elif isinstance(max_positions, dict):
              idx_size = size_fn(idx)
              assert isinstance(idx_size, dict)
              intersect_keys = set(max_positions.keys()) & set(
                  idx_size.keys()
              )
              return all(
                  all(
                      a is None or b is None or a <= b
                      for a, b in zip(idx_size[key], max_positions[key])
                  )
                  for key in intersect_keys
              )
          else:
              # For MultiCorpusSampledDataset, will generalize it later
              if not isinstance(size_fn(idx), Iterable):
                  return all(size_fn(idx) <= b for b in max_positions)
              return all(
                  a is None or b is None or a <= b
                  for a, b in zip(size_fn(idx), max_positions)
              )
  
      ignored = []
      itr = collect_filtered(check_size, indices, ignored)
      indices = np.fromiter(itr, dtype=np.int64, count=-1)
      return indices, ignored
  
imports: import contextlib
  import itertools
  import logging
  import re
  import warnings
  from typing import Optional, Tuple
  import math
  import numpy
  import torch
  from fairseq.file_io import PathManager
  from fairseq import utils
  import os
label_desc: Use image node_id 6 for calling a global function with example usage: _filter_by_size_dynamic(indices, size_fn, max_positions, raise_exception) and returns: indices,  ignored, unknown, unknown, all, all, all