class_docstr: Callback to ensure memory usage is safe, otherwise early stops the model to avoid OOM errors.
  
  This callback is CatBoost specific.
  
  Parameters
  ----------
  period : int, default = 10
      Number of iterations between checking memory status. Higher values are less precise but use less compute.
  verbose : bool, default = False
      Whether to log information on memory status even if memory usage is low.
docstr: Checks if memory usage is unsafe. If so, then returns True to signal the model to stop training early.
docstr_tok: ["Checks","if","memory","usage","is","unsafe",".","If","so",",","then","returns","True","to","signal","the","model","to","stop","training","early","."]
code: def memory_check(self, iter) -> bool:
      """Checks if memory usage is unsafe. If so, then returns True to signal the model to stop training early."""
      available_bytes = ResourceManager.get_available_virtual_mem()
      cur_rss = ResourceManager.get_memory_rss()
  
      if cur_rss < self.init_mem_rss:
          self.init_mem_rss = cur_rss
      estimated_model_size_mb = (cur_rss - self.init_mem_rss) >> 20
      available_mb = available_bytes >> 20
      model_size_memory_ratio = estimated_model_size_mb / available_mb
  
      early_stop = False
      if model_size_memory_ratio > 1.0:
          logger.warning(
              f"Warning: Large model size may cause OOM error if training continues"
          )
          early_stop = True
  
      if available_mb < 512:  # Less than 500 MB
          logger.warning(
              f"Warning: Low available memory may cause OOM error if training continues"
          )
          early_stop = True
  
      if early_stop:
          logger.warning(
              "Warning: Early stopped model prior to optimal result to avoid OOM error. "
              "Please increase available memory to avoid subpar model quality."
          )
          logger.warning(
              f"Available Memory: {available_mb} MB, Estimated Model size: {estimated_model_size_mb} MB"
          )
          return True
      elif self.verbose or (model_size_memory_ratio > 0.25):
          logging.debug(
              f"Available Memory: {available_mb} MB, Estimated Model size: {estimated_model_size_mb} MB"
          )
  
      if model_size_memory_ratio > 0.5:
          self._cur_period = 1  # Increase rate of memory check if model gets large enough to cause OOM potentially
      elif iter > self.period:
          self._cur_period = self.period
  
      return False
  
file_path: autogluon/tabular/src/autogluon/tabular/models/catboost/callbacks.py
imports: import logging
  import time
  from autogluon.common.utils.resource_utils import ResourceManager
  from .catboost_utils import CATBOOST_QUANTILE_PREFIX
label_desc: Use image node_id 3 for calling the MemoryCheckCallback obj's underlying member method code with example usage: obj.memory_check(iter) and returns: False, True