Skip to content

Conversation

@eellison
Copy link
Contributor

@eellison eellison commented Jul 15, 2020

Stack from ghstack:

Previously we were re-running CSE every time we recursed into a new block, which in turn created a new Alias Db for the whole graph. This was O(# Nodes * # Blocks).

For graphs which don't have any autodiff opportunities, such as Densenet, create_autodiff_subgraphs is now linear in number of nodes. For Densenet this pass was measured at ~.1 seconds.

This pass is still non-linear for models which actually do create autodiff subgraphs, because in the

      bool any_changed = true;
      while (any_changed) {
        AliasDb aliasDb(graph_);
        any_changed = false;
        for (auto it = workblock.end()->reverseIterator();
             it != workblock.begin()->reverseIterator();) {
          bool changed;
          std::tie(it, changed) = scanNode(*it, aliasDb);
          any_changed |= changed;
        }
      }

loop we recreate the AliasDb (which is O(N)) every time we merge something and scan node returns. I will make that linear in next PR in the stack.

Differential Revision: D22600606

[ghstack-poisoned]
@eellison eellison requested a review from apaszke as a code owner July 15, 2020 16:35
@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Jul 15, 2020
@dr-ci
Copy link

dr-ci bot commented Jul 15, 2020

💊 CI failures summary and remediations

As of commit a8f6a98 (more details on the Dr. CI page):


💚 💚 Looks good so far! There are no failures yet. 💚 💚


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group.

See how this bot performed.

This comment has been revised 25 times.

@eellison eellison requested a review from Krovatkin July 15, 2020 16:42
eellison pushed a commit that referenced this pull request Jul 15, 2020
ghstack-source-id: 3e3da36
Pull Request resolved: #41479
@eellison eellison changed the title Don't re run CSE on every block [JIT] Don't re run CSE on every block Jul 15, 2020
Copy link
Contributor

@Krovatkin Krovatkin left a comment

Choose a reason for hiding this comment

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

:shipit:

Previously we were re-running CSE every time we recursed into a new block, which in turn created a new Alias Db for the whole graph. This was O(# Nodes * # Blocks). 

For graphs which don't have any autodiff opportunities, such as Densenet,  create_autodiff_subgraphs is now linear in number of nodes. For Densenet this pass was measured at ~.1 seconds. 

This pass is still non-linear for models which actually do create autodiff subgraphs, because in the 
```
      bool any_changed = true;
      while (any_changed) {
        AliasDb aliasDb(graph_);
        any_changed = false;
        for (auto it = workblock.end()->reverseIterator();
             it != workblock.begin()->reverseIterator();) {
          bool changed;
          std::tie(it, changed) = scanNode(*it, aliasDb);
          any_changed |= changed;
        }
      }
``` 
loop we recreate the AliasDb (which is O(N)) every time we merge something and scan node returns. I will make that linear in next PR in the stack.


[ghstack-poisoned]
eellison pushed a commit that referenced this pull request Jul 16, 2020
ghstack-source-id: 0b816c9
Pull Request resolved: #41479
Previously we were re-running CSE every time we recursed into a new block, which in turn created a new Alias Db for the whole graph. This was O(# Nodes * # Blocks). 

For graphs which don't have any autodiff opportunities, such as Densenet,  create_autodiff_subgraphs is now linear in number of nodes. For Densenet this pass was measured at ~.1 seconds. 

This pass is still non-linear for models which actually do create autodiff subgraphs, because in the 
```
      bool any_changed = true;
      while (any_changed) {
        AliasDb aliasDb(graph_);
        any_changed = false;
        for (auto it = workblock.end()->reverseIterator();
             it != workblock.begin()->reverseIterator();) {
          bool changed;
          std::tie(it, changed) = scanNode(*it, aliasDb);
          any_changed |= changed;
        }
      }
``` 
loop we recreate the AliasDb (which is O(N)) every time we merge something and scan node returns. I will make that linear in next PR in the stack.


[ghstack-poisoned]
eellison pushed a commit that referenced this pull request Jul 17, 2020
ghstack-source-id: bd25b5c
Pull Request resolved: #41479
Previously we were re-running CSE every time we recursed into a new block, which in turn created a new Alias Db for the whole graph. This was O(# Nodes * # Blocks). 

For graphs which don't have any autodiff opportunities, such as Densenet,  create_autodiff_subgraphs is now linear in number of nodes. For Densenet this pass was measured at ~.1 seconds. 

This pass is still non-linear for models which actually do create autodiff subgraphs, because in the 
```
      bool any_changed = true;
      while (any_changed) {
        AliasDb aliasDb(graph_);
        any_changed = false;
        for (auto it = workblock.end()->reverseIterator();
             it != workblock.begin()->reverseIterator();) {
          bool changed;
          std::tie(it, changed) = scanNode(*it, aliasDb);
          any_changed |= changed;
        }
      }
``` 
loop we recreate the AliasDb (which is O(N)) every time we merge something and scan node returns. I will make that linear in next PR in the stack.

Differential Revision: [D22600606](https://our.internmc.facebook.com/intern/diff/D22600606)

[ghstack-poisoned]
eellison pushed a commit that referenced this pull request Jul 20, 2020
ghstack-source-id: 3ca982b
Pull Request resolved: #41479
Previously we were re-running CSE every time we recursed into a new block, which in turn created a new Alias Db for the whole graph. This was O(# Nodes * # Blocks). 

For graphs which don't have any autodiff opportunities, such as Densenet,  create_autodiff_subgraphs is now linear in number of nodes. For Densenet this pass was measured at ~.1 seconds. 

This pass is still non-linear for models which actually do create autodiff subgraphs, because in the 
```
      bool any_changed = true;
      while (any_changed) {
        AliasDb aliasDb(graph_);
        any_changed = false;
        for (auto it = workblock.end()->reverseIterator();
             it != workblock.begin()->reverseIterator();) {
          bool changed;
          std::tie(it, changed) = scanNode(*it, aliasDb);
          any_changed |= changed;
        }
      }
``` 
loop we recreate the AliasDb (which is O(N)) every time we merge something and scan node returns. I will make that linear in next PR in the stack.

Differential Revision: [D22600606](https://our.internmc.facebook.com/intern/diff/D22600606)

[ghstack-poisoned]
eellison pushed a commit that referenced this pull request Jul 23, 2020
ghstack-source-id: 21801e1
Pull Request resolved: #41479
@facebook-github-bot
Copy link
Contributor

@eellison merged this pull request in b898bdd.

@facebook-github-bot facebook-github-bot deleted the gh/eellison/88/head branch July 27, 2020 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants