code: def _determine_favorable_chunk_size(self, fn, args, min_chunk_size):
      logging.info("Tuning chunk size...")
  
      if min_chunk_size >= self.max_chunk_size:
          return min_chunk_size
  
      candidates = [
          2**l
          for l in range(int(math.log(self.max_chunk_size, 2)) + 1)
      ]
      candidates = [c for c in candidates if c > min_chunk_size]
      candidates = [min_chunk_size] + candidates
      candidates[-1] += 4
  
      def test_chunk_size(chunk_size):
          try:
              with torch.no_grad():
                  fn(*args, chunk_size=chunk_size)
              return True
          except RuntimeError:
              return False
  
      min_viable_chunk_size_index = 0
      i = len(candidates) - 1
      while i > min_viable_chunk_size_index:
          viable = test_chunk_size(candidates[i])
          if not viable:
              i = (min_viable_chunk_size_index + i) // 2
          else:
              min_viable_chunk_size_index = i
              i = (i + len(candidates) - 1) // 2
  
      return candidates[min_viable_chunk_size_index]
  
file_path: H2O/h2o_flexgen/benchmark/third_party/transformers/src/transformers/models/esm/openfold_utils/chunk_utils.py
imports: import logging
  import math
  from functools import partial
  from typing import Any, Callable, Dict, Optional, Sequence, Tuple
  import torch
  from .tensor_utils import tensor_tree_map, tree_map
label_desc: Use image node_id 2 for calling the ChunkSizeTuner obj's underlying member method code with example usage: obj._determine_favorable_chunk_size(fn, args, min_chunk_size) and returns: candidates, min_chunk_size, True, False