Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display exported concrete and polymorphic functions in SavedModel CLI #30752

Merged

Conversation

captain-pool
Copy link
Contributor

@captain-pool captain-pool commented Jul 16, 2019

Adding features to saved_model_cli to show SavedModel2.0 Functions.
SavedModelCLI doesn't show details of Polymorphic Functions or multiple Concrete Functions. This Pull request addresses this problem,
The Sample output is provided here: #30752 (comment)
This PR is made for Google Summer of Code 2019

CC: @vbardiovskyg @srjoglekar246

@tensorflow-bot tensorflow-bot bot added the size:M CL Change Size: Medium label Jul 16, 2019
@gbaned gbaned self-assigned this Jul 16, 2019
@gbaned gbaned requested a review from vbardiovskyg July 16, 2019 12:28
@vbardiovskyg vbardiovskyg changed the title Added show function description feature for SavedModel 2.0 Display exported concrete and polymorphic functions in SavedModel CLI Jul 18, 2019
@gbaned gbaned added the awaiting review Pull request awaiting review label Jul 24, 2019
Copy link
Contributor

@vbardiovskyg vbardiovskyg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing. I think this is a great first step to start showing defined functions on SavedModelV2s that don't expose any v1 style signatures.

Could you please copy/paste a typical output of the CLI feature you are adding into the review comment?

tensorflow/python/tools/saved_model_cli.py Outdated Show resolved Hide resolved
tensorflow/python/tools/saved_model_cli.py Outdated Show resolved Hide resolved
tensorflow/python/tools/saved_model_cli.py Outdated Show resolved Hide resolved
tensorflow/python/tools/saved_model_cli.py Show resolved Hide resolved
tensorflow/python/tools/saved_model_cli.py Outdated Show resolved Hide resolved
tensorflow/python/tools/saved_model_cli.py Outdated Show resolved Hide resolved
tensorflow/python/tools/saved_model_cli.py Outdated Show resolved Hide resolved
tensorflow/python/tools/saved_model_cli.py Outdated Show resolved Hide resolved
tensorflow/python/tools/saved_model_cli.py Outdated Show resolved Hide resolved
@captain-pool
Copy link
Contributor Author

captain-pool commented Jul 24, 2019

As Requested, Output of SavedModel2.0

Model

import tensorflow.compat.v2 as tf
tf.enable_v2_behaviour()
class A(tf.train.Checkpoint):
  @tf.function
  def func1(self, a, b, c):
    if c:
      return a + b 
    else:
      return a * b
  @tf.function(input_signature=[tf.TensorSpec(shape=(2, 2), dtype=tf.float32)])
  def func2(self, x):
    return x + 2
  @tf.function
  def __call__(self, y, c=7):
    return y + 2 * c

a = A()
a.func1(tf.constant(5), tf.constant(9), {"key1": [{"k1":tf.constant(5), "k2":1}, 2], "key2": 2})
a.func1(tf.constant(5), tf.constant(9), False)
a(tf.constant(5))
tf.saved_model.save(a, "/tmp/model")

Run

$ saved_model_cli show --dir /tmp/model --all

Output

MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs:

signature_def['__saved_model_init_op']:
  The given SavedModel SignatureDef contains the following input(s):
  The given SavedModel SignatureDef contains the following output(s):
    outputs['__saved_model_init_op'] tensor_info:
        dtype: DT_INVALID
        shape: unknown_rank
        name: NoOp
  Method name is: 

signature_def['serving_default']:
  The given SavedModel SignatureDef contains the following input(s):
    inputs['x'] tensor_info:
        dtype: DT_FLOAT
        shape: (2, 2)
        name: serving_default_x:0
  The given SavedModel SignatureDef contains the following output(s):
    outputs['output_0'] tensor_info:
        dtype: DT_FLOAT
        shape: (2, 2)
        name: PartitionedCall:0
  Method name is: tensorflow/serving/predict

Defined Functions:
  Function Name: 'func2'
    Option #1
      Callable with:
        Argument #1
          x: TensorSpec(shape=(2, 2), dtype=tf.float32, name='x')

  Function Name: 'func1'
    Option #1
      Callable with:
        Argument #1
          a: TensorSpec(shape=(), dtype=tf.int32, name='a')
        Argument #2
          b: TensorSpec(shape=(), dtype=tf.int32, name='b')
        Argument #3
          DType: bool
          Value: True
    Option #2
      Callable with:
        Argument #1
          a: TensorSpec(shape=(), dtype=tf.int32, name='a')
        Argument #2
          b: TensorSpec(shape=(), dtype=tf.int32, name='b')
        Argument #3
          DType: dict
          Value: {'key1': [{'k1': TensorSpec(shape=(), dtype=tf.int32, name='c/key1/0/k1'), 'k2': 1}, 2], 'key2': 2} 

  Function Name: '__call__'
    Option #1
      Callable with:
        Argument #1
          y: TensorSpec(shape=(), dtype=tf.int32, name='y')
        Argument #2
          DType: int
          Value: 7

@tensorflowbutler tensorflowbutler removed the awaiting review Pull request awaiting review label Jul 25, 2019
@gbaned gbaned requested a review from vbardiovskyg July 31, 2019 09:53
Copy link
Contributor

@vbardiovskyg vbardiovskyg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay.

The PR looks good except for the single comment and also the missing test. Please add at least one to saved_model_cli_test. Most of that file is loading a model from saved_model/testdata/half_plus_two/00000123, but I think you can just create a model and save it in temp directory, then load it, all from one test function.

tensorflow/python/tools/saved_model_cli.py Show resolved Hide resolved
…ete function ID. Skipped TF 1.X models while showing Polymorphic function.
@captain-pool
Copy link
Contributor Author

Added the test, @vbardiovskyg please take a look :)

tensorflow/python/tools/saved_model_cli_test.py Outdated Show resolved Hide resolved
tensorflow/python/tools/saved_model_cli_test.py Outdated Show resolved Hide resolved
tensorflow/python/tools/saved_model_cli_test.py Outdated Show resolved Hide resolved
@captain-pool
Copy link
Contributor Author

@vbardiovskyg

vbardiovskyg
vbardiovskyg previously approved these changes Aug 9, 2019
Copy link
Contributor

@vbardiovskyg vbardiovskyg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the change!

@tensorflow-bot tensorflow-bot bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Aug 9, 2019
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Aug 9, 2019
@captain-pool
Copy link
Contributor Author

@vbardiovskyg

vbardiovskyg
vbardiovskyg previously approved these changes Aug 12, 2019
Copy link
Contributor

@vbardiovskyg vbardiovskyg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@tensorflow-bot tensorflow-bot bot added the kokoro:force-run Tests on submitted change label Aug 12, 2019
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Aug 12, 2019
@captain-pool
Copy link
Contributor Author

@vbardiovskyg , This should remove the linter issues.

@rthadur rthadur removed the ready to pull PR ready for merge process label Aug 12, 2019
Copy link
Contributor

@vbardiovskyg vbardiovskyg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why you didn't break the line using "" or brackets, but approving since it is not a big deal.

@tensorflow-bot tensorflow-bot bot added the kokoro:force-run Tests on submitted change label Aug 13, 2019
@tensorflow-bot tensorflow-bot bot added the ready to pull PR ready for merge process label Aug 13, 2019
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Aug 13, 2019
@tensorflow-copybara tensorflow-copybara merged commit a0dfde1 into tensorflow:master Aug 16, 2019
tensorflow-copybara pushed a commit that referenced this pull request Aug 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes ready to pull PR ready for merge process size:M CL Change Size: Medium
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants