code: def _preserve_cls_structure(
      data: dict[str, t.Any], cl: t.Type[_T]
  ) -> _T:
      if isinstance(data, cl):
          return data
      return cl(**data)
  
imports: from __future__ import annotations
  import logging
  import typing
  import attr
  import cattr.errors
  import yaml
  from cattr.gen import make_dict_unstructure_fn
  from cattr.gen import override
  from ...utils import bentoml_cattr
label_desc: Use image node_id 2 for calling a global function with example usage: _preserve_cls_structure(data, cl) and returns: cl, data