def _serialize_function_spec(function_spec, coder): """Serialize a FunctionSpec object into its proto representation.""" if function_spec.is_method and not function_spec.fullargspec.args: raise NotImplementedError( "Missing support to serialize a method function without a named " "'self' argument.") proto = saved_object_graph_pb2.FunctionSpec() # Intentionally skip encoding annotations of a function because function # annotations are mainly for optional type checking during development # and does not affect runtime behavior. # https://www.python.org/dev/peps/pep-3107/ # https://docs.python.org/3/library/inspect.html#inspect.getfullargspec proto.fullargspec.CopyFrom( coder.encode_structure( function_spec.fullargspec._replace(annotations={}))) proto.is_method = function_spec.is_method proto.input_signature.CopyFrom( coder.encode_structure(function_spec.input_signature)) # See `tf.function` and the ExperimentalCompile proto for details. proto.experimental_compile = { None: saved_object_graph_pb2.FunctionSpec.ExperimentalCompile.DEFAULT, True: saved_object_graph_pb2.FunctionSpec.ExperimentalCompile.ON, False: saved_object_graph_pb2.FunctionSpec.ExperimentalCompile.OFF, }.get(function_spec.experimental_compile) return proto
def _serialize_function_spec(function_spec, coder): """Serialize a FunctionSpec object into its proto representation.""" proto = saved_object_graph_pb2.FunctionSpec() proto.fullargspec.CopyFrom(coder.encode_structure(function_spec.fullargspec)) proto.is_method = function_spec.is_method proto.args_to_prepend.CopyFrom( coder.encode_structure(function_spec.args_to_prepend)) proto.kwargs_to_include.CopyFrom( coder.encode_structure(function_spec.kwargs_to_include)) proto.input_signature.CopyFrom( coder.encode_structure(function_spec.input_signature)) return proto
def _serialize_function_spec(function_spec, coder): """Serialize a FunctionSpec object into its proto representation.""" if function_spec.is_method and not function_spec.fullargspec.args: raise NotImplementedError( "Missing support to serialize a method function without a named " "'self' argument.") proto = saved_object_graph_pb2.FunctionSpec() proto.fullargspec.CopyFrom(coder.encode_structure(function_spec.fullargspec)) proto.is_method = function_spec.is_method proto.input_signature.CopyFrom( coder.encode_structure(function_spec.input_signature)) return proto