code: def save(
      self,
      *,
      directory=None,
      filename=None,
      format="checkpoint",
      append=None,
  ):
      if (
          directory is None
          and filename is None
          and format == "checkpoint"
      ):
          if self.saver is None:
              raise TensorforceError.required(
                  name="Model.save", argument="directory"
              )
          if append is None:
              append = self.saver._step_counter
          else:
              append = self.units[append]
          return self.saver.save(checkpoint_number=append)
  
      if directory is None:
          raise TensorforceError.required(
              name="Model.save", argument="directory"
          )
  
      if filename is None:
          filename = self.name
  
      if append is not None:
          filename = (
              filename + "-" + str(self.units[append].numpy().item())
          )
  
      if format == "saved-model":
          if filename != self.name:
              directory = os.path.join(directory, filename)
  
          assert hasattr(self, "_independent_act_graphs")
          assert len(self._independent_act_graphs) == 1
          independent_act = next(
              iter(self._independent_act_graphs.values())
          )
  
          trackables = self.get_savedmodel_trackables()
          assert (
              "act" not in trackables
              and "initial_internals" not in trackables
          )
          trackables = OrderedDict(
              sorted(trackables.items(), key=(lambda kv: kv[0]))
          )
  
          @tf.function(input_signature=(), autograph=False)
          def initial_internals():
              return self.internals_spec.fmap(
                  function=(
                      lambda spec, internal: tf.constant(value=internal)
                  ),
                  cls=dict,
                  zip_values=self.initial_internals,
              )
  
          checkpoint = tf.train.Checkpoint(
              act=independent_act,
              initial_internals=initial_internals,
              **trackables,
          )
  
          # TensorFlow restriction: "Dictionaries outputs for functions used as signatures should
          # have one Tensor output per string key."
          if len(self.internals_spec) == 0 and not any(
              name is not None and "/" in name
              for name in self.actions_spec
          ):
              signatures = independent_act.get_concrete_function(
                  *self.input_signature(
                      function="independent_act"
                  ).to_list(to_dict=True)
              )
          else:
              signatures = None
  
          return tf.saved_model.save(
              obj=checkpoint,
              export_dir=directory,
              signatures=signatures,
          )
  
      if format == "checkpoint":
          # which variables are not saved? should all be saved probably, so remove option
          # always write temporary terminal=2/3 to indicate it is in process... has been removed recently...
          # check everywhere temrinal is checked that this is correct, if 3 is used.
          # Reset should reset estimator!!!
          if self.checkpoint is None:
              self.checkpoint = tf.train.Checkpoint(**{self.name: self})
  
          # We are using the high-level "save" method of the checkpoint to write a "checkpoint" file.
          # This makes it easily restorable later on.
          # The base class uses the lower level "write" method, which doesn't provide such niceties.
          return self.checkpoint.save(
              file_prefix=os.path.join(directory, filename)
          )
  
      # elif format == 'tensorflow':
      #     if self.summarizer_spec is not None:
      #         self.monitored_session.run(fetches=self.summarizer_flush)
      #     saver_path = self.saver.save(
      #         sess=self.session, save_path=path, global_step=append,
      #         # latest_filename=None,  # Defaults to 'checkpoint'.
      #         meta_graph_suffix='meta', write_meta_graph=True, write_state=True
      #     )
      #     assert saver_path.startswith(path)
      #     path = saver_path
  
      #     if not no_act_pb:
      #         graph_def = self.graph.as_graph_def()
  
      #         # freeze_graph clear_devices option
      #         for node in graph_def.node:
      #             node.device = ''
  
      #         graph_def = tf.compat.v1.graph_util.remove_training_nodes(input_graph=graph_def)
      #         output_node_names = [
      #             self.name + '.independent_act/' + name + '-output'
      #             for name in self.output_tensors['independent_act']
      #         ]
      #         # implies tf.compat.v1.graph_util.extract_sub_graph
      #         graph_def = tf.compat.v1.graph_util.convert_variables_to_constants(
      #             sess=self.monitored_session, input_graph_def=graph_def,
      #             output_node_names=output_node_names
      #         )
      #         graph_path = tf.io.write_graph(
      #             graph_or_graph_def=graph_def, logdir=directory,
      #             name=(os.path.split(path)[1] + '.pb'), as_text=False
      #         )
      #         assert graph_path == path + '.pb'
      #     return path
  
      elif format == "numpy":
          variables = dict()
          for variable in self.saved_variables:
              assert variable.name[-2] == ":"
              if variable.name.startswith(self.name + "/"):
                  variables[
                      variable.name[len(self.name) + 1 : -2]
                  ] = variable.numpy()
              else:
                  variables[variable.name[:-2]] = variable.numpy()
          path = os.path.join(directory, filename) + ".npz"
          np.savez(file=path, **variables)
          return path
  
      elif format == "hdf5":
          path = os.path.join(directory, filename) + ".hdf5"
          with h5py.File(name=path, mode="w") as filehandle:
              for variable in self.saved_variables:
                  assert variable.name[-2] == ":"
                  if variable.name.startswith(self.name + "/"):
                      filehandle.create_dataset(
                          name=variable.name[len(self.name) + 1 : -2],
                          data=variable.numpy(),
                      )
                  else:
                      filehandle.create_dataset(
                          name=variable.name[:-2], data=variable.numpy()
                      )
          return path
  
      else:
          raise TensorforceError.value(
              name="Model.save", argument="format", value=format
          )
  
imports: from collections import OrderedDict
  import logging
  import os
  import time
  import h5py
  import numpy
  import tensorflow
  from tensorforce import TensorforceError
  from tensorforce.core import ArrayDict, Module, SignatureDict, TensorDict, TensorSpec, TensorsSpec, tf_function, tf_util, VariableDict
  from tensorforce.core.layers import Layer
label_desc: Use image node_id 21 for calling the Model obj's underlying member method code with example usage: obj.save() and returns: self, tf, self, self, path, path