Skip to content

Migrate from TF_DeprecatedSession to TF_Session #285

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

Merged
merged 1 commit into from
Feb 4, 2023

Conversation

Minnozz
Copy link
Contributor

@Minnozz Minnozz commented Jan 17, 2023

This is a prerequisite for supporting SavedModel.

@Minnozz
Copy link
Contributor Author

Minnozz commented Jan 20, 2023

With my very limited understanding of TensorFlow, I suspect that the old call to TF_ExtendGraph merges the supplied GraphDef with the current Session, while the new call to TF_GraphImportGraphDef does not consider the existing graph and therefore cannot resolve references to existing nodes.

@Minnozz
Copy link
Contributor Author

Minnozz commented Jan 22, 2023

I will try using TF_NewOperation calls instead of using a GraphDef as intermediate.

@fkm3
Copy link
Contributor

fkm3 commented Jan 23, 2023

That might be a lot of work. If I remember correctly, a lot of the haskell code was designed exploiting the fact that we could build up a graph of protos (without having to interact with the C API or do anything "impure") and then just chuck it all into tensorflow at once via TF_ExtendGraph, so a lot of refactoring might be necessary (I'd be happy to be wrong though).

Not sure if it is feasible, but maybe at the point where TF_ExtendGraph is currently called, instead we could traverse the GraphDef proto in haskell, translating its contents into calls to TF_NewOperation and friends. Of course it seems like a waste to build up the GraphDef and then only use it for that, but it might be the shortest path to a solution.

@Minnozz
Copy link
Contributor Author

Minnozz commented Jan 23, 2023

Thanks for the feedback; I'll give it a try to see if it's feasible.

I'm currently using the NodeDef protos in the Builder before they are put into the GraphDef proto, but I think that is equivalent to your suggestion.

@Minnozz
Copy link
Contributor Author

Minnozz commented Jan 23, 2023

It is indeed a lot of work. I will try using the TF_GraphImportGraphDef approach again, but this time with an input mapping for existing nodes in the graph.

@Minnozz Minnozz force-pushed the deprecated-session branch from ee69aa3 to 382b9c1 Compare January 24, 2023 12:15
@Minnozz Minnozz marked this pull request as ready for review January 24, 2023 12:16
@Minnozz
Copy link
Contributor Author

Minnozz commented Jan 24, 2023

Passing an input map seems to work.

@Minnozz
Copy link
Contributor Author

Minnozz commented Jan 31, 2023

@fkm3 Thanks for looking into this PR; can you tell something about the CI failure?

@fkm3
Copy link
Contributor

fkm3 commented Jan 31, 2023

It is just some warnings-as-errors, you should be able to reproduce using the --pedantic flag of stack or ghc (or use the CI docker script).

tensorflow                 > [ 1 of 12] Compiling TensorFlow.Internal.Raw
tensorflow                 > 
tensorflow                 > /[tfhs/tensorflow/src/TensorFlow/Internal/Raw.chs:86](https://cs.corp.google.com/piper///depot/google3/tfhs/tensorflow/src/TensorFlow/Internal/Raw.chs?l=86):29: error: [-Wname-shadowing, -Werror=name-shadowing]
tensorflow                 >     This binding for ‘ptr’ shadows the existing binding
tensorflow                 >       bound at [src/TensorFlow/Internal/Raw.chs:86](https://cs.corp.google.com/piper///depot/google3/src/TensorFlow/Internal/Raw.chs?l=86):10
tensorflow                 >    |
tensorflow                 > 86 |     peek ptr = Output <$> {# get TF_Output->oper #} ptr
tensorflow                 >    |                             ^^^
tensorflow                 > 
tensorflow                 > /[tfhs/tensorflow/src/TensorFlow/Internal/Raw.chs:87](https://cs.corp.google.com/piper///depot/google3/tfhs/tensorflow/src/TensorFlow/Internal/Raw.chs?l=87):47: error: [-Wname-shadowing, -Werror=name-shadowing]
tensorflow                 >     This binding for ‘ptr’ shadows the existing binding
tensorflow                 >       bound at [src/TensorFlow/Internal/Raw.chs:86](https://cs.corp.google.com/piper///depot/google3/src/TensorFlow/Internal/Raw.chs?l=86):10
tensorflow                 >    |
tensorflow                 > 87 |                       <*> (fromIntegral <$> {# get TF_Output->index #} ptr)
tensorflow                 >    |                                               ^^^
tensorflow                 > 
tensorflow                 > /[tfhs/tensorflow/src/TensorFlow/Internal/Raw.chs:89](https://cs.corp.google.com/piper///depot/google3/tfhs/tensorflow/src/TensorFlow/Internal/Raw.chs?l=89):11: error: [-Wname-shadowing, -Werror=name-shadowing]
tensorflow                 >     This binding for ‘ptr’ shadows the existing binding
tensorflow                 >       bound at [src/TensorFlow/Internal/Raw.chs:88](https://cs.corp.google.com/piper///depot/google3/src/TensorFlow/Internal/Raw.chs?l=88):10
tensorflow                 >    |
tensorflow                 > 89 |         {# set TF_Output->oper #} ptr oper
tensorflow                 >    |           ^^^
tensorflow                 > 
tensorflow                 > /[tfhs/tensorflow/src/TensorFlow/Internal/Raw.chs:90](https://cs.corp.google.com/piper///depot/google3/tfhs/tensorflow/src/TensorFlow/Internal/Raw.chs?l=90):11: error: [-Wname-shadowing, -Werror=name-shadowing]
tensorflow                 >     This binding for ‘ptr’ shadows the existing binding
tensorflow                 >       bound at [src/TensorFlow/Internal/Raw.chs:88](https://cs.corp.google.com/piper///depot/google3/src/TensorFlow/Internal/Raw.chs?l=88):10
tensorflow                 >    |
tensorflow                 > 90 |         {# set TF_Output->index #} ptr $ fromIntegral index
tensorflow                 >    |           ^^^

@Minnozz Minnozz force-pushed the deprecated-session branch from 382b9c1 to 9c467ed Compare January 31, 2023 20:01
@Minnozz
Copy link
Contributor Author

Minnozz commented Jan 31, 2023

Oops, thought I checked that. Fixed now.

Copy link
Contributor

@fkm3 fkm3 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 figuring this out. I think a handful of people including myself have considered doing this and bounced off it.

@Minnozz Minnozz force-pushed the deprecated-session branch from 9c467ed to f8edd59 Compare January 31, 2023 20:45
Instead of calling TF_ExtendGraph, we call TF_GraphImportGraphDef and
pass an input map for all existing nodes in the graph.
@Minnozz Minnozz force-pushed the deprecated-session branch from e928ed0 to 80ce0d3 Compare February 2, 2023 10:31
Copy link
Contributor Author

@Minnozz Minnozz left a comment

Choose a reason for hiding this comment

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

@fkm3 I think I've addressed your feedback, what do you think of the current PR?

@Minnozz Minnozz requested a review from fkm3 February 2, 2023 10:36
@fkm3 fkm3 added the kokoro:run label Feb 4, 2023
Copy link
Contributor

@fkm3 fkm3 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!

@fkm3 fkm3 merged commit fb629d1 into tensorflow:master Feb 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants