Skip to content

Conversation

@narendasan
Copy link
Collaborator

@narendasan narendasan commented Sep 3, 2021

Description

There was an issue where the module fallback notation pass just assumes
methods exist. This should catch that. This might be something we may want to release as a patch

Fixes #613, (potentially #609, Also probably partially solves: #608)

Type of change

Please delete options that are not relevant and/or add your own.

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the style guidelines of this project (You can use the linters)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas and hacks
  • I have made corresponding changes to the documentation
  • I have added tests to verify my fix or my feature
  • New and existing unit tests pass locally with my changes

@github-actions github-actions bot added component: core Issues re: The core compiler component: lowering Issues re: The lowering / preprocessing passes labels Sep 3, 2021
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

There are some changes that do not conform to C++ style guidelines:

diff --git a/workspace/core/lowering/lowering.cpp b/tmp/changes.txt
index 42be486..dae163a 100644
--- a/workspace/core/lowering/lowering.cpp
+++ b/tmp/changes.txt
@@ -60,10 +60,7 @@ void LowerGraph(std::shared_ptr<torch::jit::Graph>& g, LowerInfo lower_info) {
  LOG_GRAPH(*g);
}

-torch::jit::Module LowerModule(
-    const torch::jit::Module& mod,
-    std::string method_name,
-    const LowerInfo& lower_info) {
+torch::jit::Module LowerModule(const torch::jit::Module& mod, std::string method_name, const LowerInfo& lower_info) {
  std::unordered_set<std::string> forced_fallback_modules(
      lower_info.forced_fallback_modules.begin(), lower_info.forced_fallback_modules.end());
  passes::NotateModuleForFallback(mod, "", method_name, forced_fallback_modules);
ERROR: Some files do not conform to style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

There are some changes that do not conform to C++ style guidelines:

diff --git a/workspace/core/lowering/lowering.cpp b/tmp/changes.txt
index 42be486..dae163a 100644
--- a/workspace/core/lowering/lowering.cpp
+++ b/tmp/changes.txt
@@ -60,10 +60,7 @@ void LowerGraph(std::shared_ptr<torch::jit::Graph>& g, LowerInfo lower_info) {
  LOG_GRAPH(*g);
}

-torch::jit::Module LowerModule(
-    const torch::jit::Module& mod,
-    std::string method_name,
-    const LowerInfo& lower_info) {
+torch::jit::Module LowerModule(const torch::jit::Module& mod, std::string method_name, const LowerInfo& lower_info) {
  std::unordered_set<std::string> forced_fallback_modules(
      lower_info.forced_fallback_modules.begin(), lower_info.forced_fallback_modules.end());
  passes::NotateModuleForFallback(mod, "", method_name, forced_fallback_modules);
ERROR: Some files do not conform to style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

There are some changes that do not conform to C++ style guidelines:

diff --git a/workspace/core/lowering/lowering.cpp b/tmp/changes.txt
index 42be486..dae163a 100644
--- a/workspace/core/lowering/lowering.cpp
+++ b/tmp/changes.txt
@@ -60,10 +60,7 @@ void LowerGraph(std::shared_ptr<torch::jit::Graph>& g, LowerInfo lower_info) {
  LOG_GRAPH(*g);
}

-torch::jit::Module LowerModule(
-    const torch::jit::Module& mod,
-    std::string method_name,
-    const LowerInfo& lower_info) {
+torch::jit::Module LowerModule(const torch::jit::Module& mod, std::string method_name, const LowerInfo& lower_info) {
  std::unordered_set<std::string> forced_fallback_modules(
      lower_info.forced_fallback_modules.begin(), lower_info.forced_fallback_modules.end());
  passes::NotateModuleForFallback(mod, "", method_name, forced_fallback_modules);
ERROR: Some files do not conform to style guidelines

@narendasan narendasan force-pushed the fix_mod_fallback_methods branch from c049894 to 29ded84 Compare September 3, 2021 22:14
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines


for (const auto sub_mod : mod.named_children()) {
NotateModuleForFallback(sub_mod.value, sub_mod.name, method_name, forced_fallback_modules);
if (sub_mod.value.find_method(method_name)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there ever a case where we might pass in a name other than "forward" as the method name here? In that case, would the desired behavior be to only recurse through submodules with that specific method (and ignore others, and their children)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What we really should be doing is finding the Method calls and using that to recurse vs all children probably

Copy link
Collaborator

@peri044 peri044 left a comment

Choose a reason for hiding this comment

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

One minor change maybe when forced_fallback_modules is empty ?
PR runs fine and BERT 1.9 graph passes

torch::jit::Module LowerModule(const torch::jit::Module& mod, std::string method_name, const LowerInfo& lower_info) {
std::unordered_set<std::string> forced_fallback_modules(
lower_info.forced_fallback_modules.begin(), lower_info.forced_fallback_modules.end());
passes::NotateModuleForFallback(mod, "", method_name, forced_fallback_modules);
Copy link
Collaborator

Choose a reason for hiding this comment

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

When the forced_fallback_modules is empty, we don't need to have this pass so we can disable it. This can prevent iterating through all the nodes in graph. Disabling this also fixed BERT issue but your other fix is necessary.

@peri044
Copy link
Collaborator

peri044 commented Sep 22, 2021

Can we merge this ? Seems like we are getting duplicate "Method forward is not defined" bugs.

@narendasan narendasan added the release: patch This change needs to go out as a patch to the current version label Sep 23, 2021
@isgursoy
Copy link

isgursoy commented Sep 26, 2021

Yeah when can we expect to get this patch as a new version?

@narendasan
Copy link
Collaborator Author

We are trying to get out a patch release in the next couple weeks. The issue is I think this WAR is probably not the correct solution. I am trying to determine if a formal solution could be implemented in a reasonable amount of time

This commit fixes module level fallback by using method calls
to determine modules to recurse down too. This should be robust
to names other than forward used for methods as well as ignoring
functional modules.

Signed-off-by: Naren Dasan <[email protected]>
Signed-off-by: Naren Dasan <[email protected]>
@narendasan narendasan force-pushed the fix_mod_fallback_methods branch from f7240e3 to f94ae8f Compare September 29, 2021 05:07
@narendasan narendasan requested a review from peri044 September 29, 2021 05:07
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to C++ style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code conforms to Python style guidelines

Copy link
Collaborator

@peri044 peri044 left a comment

Choose a reason for hiding this comment

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

LGTM. Tests pass

@narendasan
Copy link
Collaborator Author

narendasan commented Sep 29, 2021

@peri044 can you also test with a network you know failed previously? Also try with module level fallback specifying a module that is not part of the module to be compiled

@peri044
Copy link
Collaborator

peri044 commented Sep 29, 2021

@narendasan Tested a network (DETR) which failed previously. Tried a module which is not a part of the graph. Works fine.

@narendasan narendasan merged commit 2918675 into master Oct 1, 2021
@narendasan narendasan deleted the fix_mod_fallback_methods branch October 1, 2021 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: core Issues re: The core compiler component: lowering Issues re: The lowering / preprocessing passes release: patch This change needs to go out as a patch to the current version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 [Bug] Compiling a model containing ModuleList gives the error "Method 'forward' is not defined."

5 participants