ML Community Day is November 9! Join us for updates from TensorFlow, JAX, and more Learn more

Exports a tf.Module (and subclasses) obj to SavedModel format.

Used in the notebooks

Used in the guide Used in the tutorials

The obj must inherit from the Trackable class.

Example usage:

class Adder(tf.Module):
  @tf.function(input_signature=[tf.TensorSpec(shape=[], dtype=tf.float32)])
  def add(self, x):
    return x + x
model = Adder(), '/tmp/adder')

The resulting SavedModel is then servable with an input named "x", a scalar with dtype float32.


Signatures define the input and output types for a computation. The optional save signatures argument controls which methods in obj will be available to programs which consume SavedModels, for example, serving APIs. Python functions may be decorated with @tf.function(input_signature=...) and passed as signatures directly, or lazily with a call to get_concrete_function on the method decorated with @tf.function.


class Adder(tf.Module):
  def add(self, x):
    return x + x
model = Adder()
  model, '/tmp/adder',signatures=model.add.get_concrete_function(
    tf.TensorSpec([], tf.float32)))

If a @tf.function does not have an input signature and