code: def patch_compiled(target_model: Model, source_model: Model):
      """Patch the compiled loss and metric of `source_model` to `target_model`."""
      if source_model._is_compiled:
          kwargs = {
              "run_eagerly": source_model._run_eagerly,
              "steps_per_execution": int(
                  source_model._steps_per_execution
              ),
          }
          if source_model.compiled_loss is not None:
              kwargs["loss"] = source_model.compiled_loss._user_losses
              kwargs[
                  "loss_weights"
              ] = source_model.compiled_loss._user_loss_weights
          if source_model.compiled_metrics is not None:
              kwargs[
                  "metrics"
              ] = source_model.compiled_metrics._user_metrics
              kwargs[
                  "weighted_metrics"
              ] = source_model.compiled_metrics._user_weighted_metrics
          target_model.compile(**kwargs)
      return target_model
  
file_path: BigDL/python/nano/src/bigdl/nano/utils/tf/attributes.py
imports: import inspect
  from functools import partial
  from tensorflow.keras import Model
  from bigdl.nano.utils.common import invalidOperationError
label_desc: Use image node_id 2 for calling a global function with example usage: patch_compiled(target_model, source_model) and returns: target_model