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

feat: combine graph by prefixing with unique name #4334

Merged
merged 3 commits into from
Nov 19, 2020

Conversation

stephanwlee
Copy link
Contributor

Previously, graph plugin combined multiple graphs traced by creating one
monolith of a GraphDef. In doing so, we checked whether, for example,
node names are unique to detect a case when our graph vis can result in
faulty UI.

To alleviate the poor UX, we decided, instead, to duplicate all nodes in
one giant GraphDef container prefixing all names. While this creates
some bloat, (1) users should see the confusing error less and (2)
combined graphs make it very clear that we have traced multiple graphs.

image

@google-cla google-cla bot added the cla: yes label Nov 17, 2020
Previously, graph plugin combined multiple graphs traced by creating one
monolith of a GraphDef. In doing so, we checked whether, for example,
node names are unique to detect a case when our graph vis can result in
faulty UI.

To alleviate the poor UX, we decided, instead, to duplicate all nodes in
one gaint GraphDef container  prefixing all names. While this creates
some bloat, (1) users should see the confusing error less and (2)
combined graphs make it very clear that we have traced multiple graphs.
Copy link
Collaborator

@nfelt nfelt left a comment

Choose a reason for hiding this comment

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

Looks like this addresses #1929? If so, worth adding Fixes #1929 to the description?

if dst_graph_def.versions.producer != graph_def.versions.producer:
raise ValueError("Cannot combine GraphDefs of different versions.")

mapped_graph_def = _prepend_names("graph_%d" % (index + 1), graph_def)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You might consider a function signature more like

def _add_with_prepended_names(prefix, graph_to_add, destination_graph)

That way we can avoid the overhead of constructing the temporary graphdef that's returned here, only to then copy its nodes and functions into the destination graph def. Since proto python objects aren't immutable, the python code has to do a deep copy each time we move the nodes around, so it would be nice not to do that twice when we could do it just once.

for func in orig_graph_def.library.function:
new_func = mut_graph_def.library.function.add()
new_func.CopyFrom(func)
# Not creating a structure out of factored out function. They already
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this comment refer to the fact that we don't use a / in the function name prefix, just an underscore? If so, the comment might make more sense as a comment on _prefixed_func_name() itself.

@stephanwlee
Copy link
Contributor Author

While I am cautiously optimistic that this change would alleviate much of #1929, I suspect this change has not covered few cases such as differing GraphDef version and gradient function support (while I have some code to handle it, I could not get my hands on a realistic example and had to just go by the comments on the definition). I will keep the issue for the time being and maybe remove the UI instruction to refer to #1929 when I truly think it is solved.

@stephanwlee stephanwlee merged commit d03fceb into tensorflow:master Nov 19, 2020
@stephanwlee stephanwlee deleted the multi_grap branch November 19, 2020 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants