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

Some high level descriptions on the MEMORY policy will be very helpful #46

Open
wangli1426 opened this issue Jul 30, 2019 · 4 comments
Open

Comments

@wangli1426
Copy link

I am trying to understand the heuristic algorithm used in the memory policy. However I could not fully understand the whole logic, especially the following if statement as shown below.

if not set(b_inp).intersection(f_inp) and len(b_inp)+len(f_inp) >= len(ts_all):

Some explanations or guidance will be highly appreciated.

Thanks.

@yaroslavvb
Copy link
Collaborator

The high level goal is to find nodes which separate the graph into two parts

From https://medium.com/tensorflow/fitting-larger-networks-into-memory-583e3c758ff9

0_iBtm1m0IFhG9d7HE

A bottleneck is a graph separate which is a single node, and that line is a heuristic which tries to find it.

The first part of heuristic looks at ops when walking forward and backward from the point, and checking if there's an overlap. No overlap suggests that x3 is a separator in a diagram below.

set(b_inp).intersection(f_inp)

Screenshot 2019-07-30 07 24 17

The second part, len(b_inp)+len(f_inp) >= len(ts_all) , was added to make it work in an edge case when backward and forward traverse didn't capture all the tensors, in which case we abort and don't try to count it as a separator/bottleneck node. I don't remember in which case that happened, but it was necessary to make tests pass, so one of the tests triggers this condition.

@wangli1426
Copy link
Author

Thanks for the explanation. It is very clear and helpful.

May I ask what's the purpose of the following code block? Thanks in advance.

with util.capture_ops() as bwd_ops:

@yaroslavvb
Copy link
Collaborator

It saves new ops added to the graph inside this block to bwd_ops

@wangli1426
Copy link
Author

Got it. Thanks.

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

No branches or pull requests

2 participants