[go: nahoru, domu]

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

[TransformGraph & TF2 SavedModel] - Missing API #43688

Open
DEKHTIARJonathan opened this issue Sep 30, 2020 · 12 comments
Open

[TransformGraph & TF2 SavedModel] - Missing API #43688

DEKHTIARJonathan opened this issue Sep 30, 2020 · 12 comments
Assignees
Labels
stat:awaiting tensorflower Status - Awaiting response from tensorflower type:bug Bug

Comments

@DEKHTIARJonathan
Copy link
Contributor
DEKHTIARJonathan commented Sep 30, 2020

Issue

When using the latest TF2 release and latest available container (2.3.1 at the time of writing), it appears that the following API is missing:

from tensorflow.tools.graph_transforms import TransformGraph  # ModuleNotFoundError: No module named 'tensorflow.tools.graph_transforms'
from tensorflow.compat.v1.tools.graph_transforms import TransformGraph  # ModuleNotFoundError: No module named 'tensorflow.compat.v1.tools'

Which used to be available in TF1 (https://github.com/tensorflow/tensorflow/tree/master/tensorflow/tools/graph_transforms).

Though it doesn't make much of a sense since Tensorflow 2 ship with the C++ library associated:

ls -al /usr/local/lib/python3.6/dist-packages/tensorflow/python/_pywrap_transform_graph.so 
-rwxr-xr-x 1 root staff 1274144 Sep 29 00:25 /usr/local/lib/python3.6/dist-packages/tensorflow/python/_pywrap_transform_graph.so

Motivation

This function is very useful to pre-process and "clean" the graph before inference when using a SavedModel (namely for TF-TRT, could also maybe concerns TF Serving or TF Lite, I didn't check).

Any chance to have this API (or a replacement) back in the TF API ? I understand that TF2 is eager mode oriented, though the SavedModel format is a graph format ... So, would makes sense to keep this API in the mix since the SavedModel format is still actively used and supported in TF2.

CC: @sanjoy @reedwm

@reedwm
Copy link
Member
reedwm commented Oct 1, 2020

@av8ramit do you know why the TransformGraph class is not in the pip package anymore? The class is defined here.

@av8ramit av8ramit assigned av8ramit and unassigned Saduf2019 Oct 1, 2020
@av8ramit
Copy link
av8ramit commented Oct 1, 2020

Thanks for filing the issue @DEKHTIARJonathan. Taking a look and will get back to you.

@av8ramit
Copy link
av8ramit commented Oct 1, 2020

So I believe that API was removed from the 2.0 pip package. It appears the recommended alternative is to build it from source using bazel. @annarev do you perhaps have more context into alternatives or why it was removed from the 2.0 APIs?

@DEKHTIARJonathan
Copy link
Contributor Author
DEKHTIARJonathan commented Oct 1, 2020

@av8ramit Building from source might be an issue. In principle, I have nothing against it. However in this case we would it in one of the core APIs of Tensorflow.

We would like to use it in the TF-TRT APIs (tensorflow/python/compiler/tensorrt), so we would need to have this available by default in Tensorflow2.

And we can't really ask each TF-TRT user to build TF from source ...


Btw. Kuddos to the team who implemented this API, very nicely put together ;)

@annarev
Copy link
Contributor
annarev commented Oct 1, 2020

Graph transforms were removed and meant to be replaced by Grappler according to this RFC:
https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md

@petewarden, @rmlarsen do you know if there is an alternative for this usecase (pre-process graph before inference with SavedModel)?

@annarev annarev assigned petewarden and rmlarsen and unassigned av8ramit and annarev Oct 1, 2020
@av8ramit
Copy link
av8ramit commented Oct 1, 2020

Sorry @DEKHTIARJonathan I am not the best person to answer this (I was looped in in the event this was a pybind export issue), but I'll leave it to Pete and Rasmus to hopefully shed some more light.

@DEKHTIARJonathan
Copy link
Contributor Author
DEKHTIARJonathan commented Oct 2, 2020

@annarev let me give you a crude of what I could be interested in doing if that could help:

transforms = [
        "remove_nodes(op=Identity, op=CheckNumerics, op=StopGradient, op=Placeholder)",
        "sort_by_execution_order",
        "remove_attribute(attribute_name=_XlaSeparateCompiledGradients)",
        "remove_attribute(attribute_name=_XlaCompile)",
        "remove_attribute(attribute_name=_XlaScope)",
        "sort_by_execution_order",
        'merge_duplicate_nodes',
        "sort_by_execution_order",
        'strip_unused_nodes',
        "sort_by_execution_order",
        'fold_constants(ignore_errors=true)',
        "sort_by_execution_order",
        'fold_batch_norms',
        "sort_by_execution_order",
    ]

    print("Applying Graph Transformations ...")
    return TransformGraph(
        graph_def,
        input_node_names,  # an array of the input node(s)
        output_node_names,  # an array of output nodes
        transforms
    )

The order of execution is important. Is there any way to order grappler optimization passes in case I find a way to use the grappler ?

@Howave
Copy link
Howave commented Dec 29, 2021

then how to use the transforms in grappler optimization?

@iaverypadberg
Copy link

Has any progress been made on this? Anybody find a fix?

@DEKHTIARJonathan
Copy link
Contributor Author

@av8ramit @reedwm any update ?

@reedwm
Copy link
Member
reedwm commented Mar 30, 2022

@rohan100jain, should these files be added back in the pip package?

@reedwm reedwm assigned rohan100jain and unassigned petewarden and rmlarsen Mar 30, 2022
@av8ramit
Copy link

@DEKHTIARJonathan I no longer work on this project, unfortunately. Good luck!

@sushreebarsa sushreebarsa added the stat:awaiting tensorflower Status - Awaiting response from tensorflower label Sep 13, 2022
EtiNL pushed a commit to EtiNL/SR_with_DeepLearning that referenced this issue Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stat:awaiting tensorflower Status - Awaiting response from tensorflower type:bug Bug
Projects
None yet
Development

No branches or pull requests