class_docstr: Wrapper to add per-example caching to a LIT model.
docstr: Wrap a model to add caching.
  
  Args:
    model: a LIT model
    name: name, used for logging and data files
    cache_dir: if given, will load/save data to disk
    strict_id_validation: if true, will re-compute hashes using id_hash_fn and
      verify that they match the provided IDs. See b/293984290.
    id_hash_fn: function of example --> string id, used by
      strict_id_validation mode.
code: def __init__(
      self,
      model: lit_model.Model,
      name: str,
      cache_dir: Optional[str] = None,
      strict_id_validation: bool = False,
      id_hash_fn: Optional[lit_dataset.IdFnType] = None,
  ):
      """Wrap a model to add caching.
  
      Args:
        model: a LIT model
        name: name, used for logging and data files
        cache_dir: if given, will load/save data to disk
        strict_id_validation: if true, will re-compute hashes using id_hash_fn and
          verify that they match the provided IDs. See b/293984290.
        id_hash_fn: function of example --> string id, used by
          strict_id_validation mode.
      """
      if strict_id_validation and id_hash_fn is None:
          raise ValueError(
              "Must provide id_hash_fn to use strict_id_validation mode."
          )
  
      super().__init__(model)
      self._name = name
      self._log_prefix = f"CachingModelWrapper '{name:s}'"
      self._strict_id_validation = strict_id_validation
      self._id_hash_fn = id_hash_fn
      self._cache = PredsCache(
          name, model.supports_concurrent_predictions, cache_dir
      )
      self.load_cache()
  
imports: from collections.abc import Callable, Iterable
  import os
  import pickle
  import threading
  from typing import Any, Optional, Union
  from absl import logging
  from lit_nlp.api import dataset
  from lit_nlp.api import model
  from lit_nlp.api import types
  from lit_nlp.lib import serialize
label_desc: Use image node_id 1 to create a new CachingModelWrapper object from inherited base classes: lit_model with example: obj = CachingModelWrapper(model, name, cache_dir, strict_id_validation, id_hash_fn)