code: def clone(model: ModelWithCRFLoss, inference_only=True):
      with tempfile.TemporaryDirectory() as tmpdir:
          file_path = os.path.join(tmpdir, "my_model.tf")
          model.save(file_path)
          new_model = tf.keras.models.load_model(file_path)
  
      if not inference_only:
          # since tf doesn't save the python code of train_step and test_step
          # we need to call the wrapper again.
          # This may change, maybe later on tf will save train_step and test_step.
          new_model_with_wrapper = ModelWithCRFLoss(
              new_model.base_model
          )
  
          # this works, but it may be cleaner to do a copy of the optimizer
          new_model_with_wrapper.compile(optimizer=new_model.optimizer)
          new_model = new_model_with_wrapper
  
      return new_model
  
imports: import itertools
  import os
  import math
  import tempfile
  import pytest
  import numpy
  import tensorflow
  from tensorflow_addons.layers.crf import CRF
  from tensorflow_addons.text.crf import crf_log_likelihood
  from tensorflow_addons.utils import test_utils
label_desc: Use image node_id 10 for calling a global function with example usage: clone(model, inference_only) and returns: new_model