class_docstr: Holds context information during a forward pass through a model. This class should be used via the
  ``ForwardContext.wrap()`` method.
  
  Note that the context is thread-local.
class_docstr_tok: ["Holds","context","information","during","a","forward","pass","through","a","model",".","This","class","should","be","used","via","the","``","ForwardContext.wrap","(",")","``","method",".","Note","that","the","context","is","thread-local","."]
docstr: Decorator method that wraps a ``forward()`` function of a model class.
docstr_tok: ["Decorator","method","that","wraps","a","``","forward","(",")","``","function","of","a","model","class","."]
code: def wrap(cls, f):
      """
      Decorator method that wraps a ``forward()`` function of a model class.
      """
  
      @functools.wraps(f)
      def wrapper_func(self, *args, **kwargs):
          if self.adapters_config is not None:
              with cls(self, *args, **kwargs) as ctx:
                  # whether to output the context attributes
                  output_context = kwargs.pop("output_context", False)
                  kwargs = {
                      k: v
                      for k, v in kwargs.items()
                      if k.replace("output_", "")
                      not in cls.context_attributes
                  }
                  results = f(self, *args, **kwargs)
  
                  # append output attributes
                  if isinstance(results, tuple):
                      for attr in cls.context_attributes:
                          if getattr(ctx, "output_" + attr, False):
                              results = results + (
                                  dict(getattr(ctx, attr)),
                              )
                  else:
                      for attr in cls.context_attributes:
                          if getattr(ctx, "output_" + attr, False):
                              results[attr] = dict(getattr(ctx, attr))
  
                  if output_context:
                      context_dict = ctx.__dict__
  
              if output_context:
                  return results, context_dict
              else:
                  return results
          else:
              return f(self, *args, **kwargs)
  
      return wrapper_func
  
file_path: adapters/src/adapters/context.py
imports: import functools
  import threading
  from .composition import parse_composition, parse_heads_from_composition
label_desc: Use image node_id 4 for calling the ForwardContext obj's underlying member method code with example usage: obj.wrap(cls, f) and returns: wrapper_func, f, results,  context_dict, results