Skip to content

[ONNX] Add module name as PythonOp attribute #67193

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

Conversation

shubhambhokare1
Copy link
Collaborator

@shubhambhokare1 shubhambhokare1 commented Oct 25, 2021

Stores the module name of the autograd function as attribute for a PythonOp node in the IR graph.

Before this modification:

graph(%input : Float(1, strides=[1], requires_grad=0, device=cpu)):
  %3 : Float(1, strides=[1], requires_grad=0, device=cpu) = ^MyExp[inplace=0]()(%input)]
  %6 : Float(1, strides=[1], requires_grad=0, device=cpu) = ^MyExp[inplace=0]()(%input)]
  %7 : int = prim::Constant[value=1]()
  %8 : Float(1, strides=[1], requires_grad=0, device=cpu) = aten::add(%3, %6, %7)
  return (%8)

After this modification:

graph(%input : Float(1, strides=[1], requires_grad=0, device=cpu)):
  %3 : Float(1, strides=[1], requires_grad=0, device=cpu) = ^MyExp[module="autograd1", inplace=0]()(%input)]
  %6 : Float(1, strides=[1], requires_grad=0, device=cpu) = ^MyExp[module="autograd2", inplace=0]()(%input)]
  %7 : int = prim::Constant[value=1]()
  %8 : Float(1, strides=[1], requires_grad=0, device=cpu) = aten::add(%3, %6, %7)
  return (%8)

@pytorch-probot
Copy link

pytorch-probot bot commented Oct 25, 2021

CI Flow Status

⚛️ CI Flow

Ruleset - Version: v1
Ruleset - File: https://github.com/shubhambhokare1/pytorch/blob/1083490266502c83285d0dee9d47bed48d051f8a/.github/generated-ciflow-ruleset.json
PR ciflow labels: ciflow/default

Workflows Labels (bold enabled) Status
Triggered Workflows
linux-bionic-py3.6-clang9 ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/noarch, ciflow/xla ✅ triggered
linux-vulkan-bionic-py3.6-clang9 ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/vulkan ✅ triggered
linux-xenial-cuda11.3-py3.6-gcc7 ciflow/all, ciflow/cuda, ciflow/default, ciflow/linux ✅ triggered
linux-xenial-py3-clang5-mobile-build ciflow/all, ciflow/default, ciflow/linux, ciflow/mobile ✅ triggered
linux-xenial-py3-clang5-mobile-custom-build-dynamic ciflow/all, ciflow/default, ciflow/linux, ciflow/mobile ✅ triggered
linux-xenial-py3-clang5-mobile-custom-build-static ciflow/all, ciflow/default, ciflow/linux, ciflow/mobile ✅ triggered
linux-xenial-py3.6-clang7-asan ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/sanitizers ✅ triggered
linux-xenial-py3.6-clang7-onnx ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/onnx ✅ triggered
linux-xenial-py3.6-gcc5.4 ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux ✅ triggered
linux-xenial-py3.6-gcc7 ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux ✅ triggered
linux-xenial-py3.6-gcc7-bazel-test ciflow/all, ciflow/bazel, ciflow/cpu, ciflow/default, ciflow/linux ✅ triggered
pytorch-linux-xenial-py3-clang5-android-ndk-r19c-gradle-custom-build-single ciflow/all, ciflow/android, ciflow/cpu, ciflow/default, ciflow/linux ✅ triggered
pytorch-linux-xenial-py3-clang5-android-ndk-r19c-gradle-custom-build-single-full-jit ciflow/all, ciflow/android, ciflow/cpu, ciflow/default, ciflow/linux ✅ triggered
win-vs2019-cpu-py3 ciflow/all, ciflow/cpu, ciflow/default, ciflow/win ✅ triggered
win-vs2019-cuda11.3-py3 ciflow/all, ciflow/cuda, ciflow/default, ciflow/win ✅ triggered
Skipped Workflows
caffe2-linux-xenial-py3.6-gcc5.4 ciflow/all, ciflow/cpu, ciflow/linux 🚫 skipped
docker-builds ciflow/all 🚫 skipped
ios-12-5-1-arm64 ciflow/all, ciflow/ios, ciflow/macos 🚫 skipped
ios-12-5-1-arm64-coreml ciflow/all, ciflow/ios, ciflow/macos 🚫 skipped
ios-12-5-1-arm64-custom-ops ciflow/all, ciflow/ios, ciflow/macos 🚫 skipped
ios-12-5-1-arm64-full-jit ciflow/all, ciflow/ios, ciflow/macos 🚫 skipped
ios-12-5-1-arm64-metal ciflow/all, ciflow/ios, ciflow/macos 🚫 skipped
ios-12-5-1-x86-64 ciflow/all, ciflow/ios, ciflow/macos 🚫 skipped
ios-12-5-1-x86-64-coreml ciflow/all, ciflow/ios, ciflow/macos 🚫 skipped
ios-12-5-1-x86-64-full-jit ciflow/all, ciflow/ios, ciflow/macos 🚫 skipped
libtorch-linux-xenial-cuda10.2-py3.6-gcc7 ciflow/all, ciflow/cuda, ciflow/libtorch, ciflow/linux 🚫 skipped
libtorch-linux-xenial-cuda11.3-py3.6-gcc7 ciflow/all, ciflow/cuda, ciflow/libtorch, ciflow/linux 🚫 skipped
linux-bionic-cuda10.2-py3.9-gcc7 ciflow/all, ciflow/cuda, ciflow/linux, ciflow/slow 🚫 skipped
linux-xenial-py3-clang5-mobile-code-analysis ciflow/all, ciflow/linux, ciflow/mobile 🚫 skipped
parallelnative-linux-xenial-py3.6-gcc5.4 ciflow/all, ciflow/cpu, ciflow/linux 🚫 skipped
periodic-libtorch-linux-xenial-cuda11.1-py3.6-gcc7 ciflow/all, ciflow/cuda, ciflow/libtorch, ciflow/linux, ciflow/scheduled 🚫 skipped
periodic-linux-xenial-cuda10.2-py3-gcc7-slow-gradcheck ciflow/all, ciflow/cuda, ciflow/linux, ciflow/scheduled, ciflow/slow, ciflow/slow-gradcheck 🚫 skipped
periodic-linux-xenial-cuda11.1-py3.6-gcc7 ciflow/all, ciflow/cuda, ciflow/linux, ciflow/scheduled 🚫 skipped
periodic-win-vs2019-cuda11.1-py3 ciflow/all, ciflow/cuda, ciflow/scheduled, ciflow/win 🚫 skipped

You can add a comment to the PR and tag @pytorchbot with the following commands:
# ciflow rerun, "ciflow/default" will always be added automatically
@pytorchbot ciflow rerun

# ciflow rerun with additional labels "-l <ciflow/label_name>", which is equivalent to adding these labels manually and trigger the rerun
@pytorchbot ciflow rerun -l ciflow/scheduled -l ciflow/slow

For more information, please take a look at the CI Flow Wiki.

@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Oct 25, 2021

🔗 Helpful links

💊 CI failures summary and remediations

As of commit 1083490 (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).

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

Copy link
Collaborator

@garymm garymm left a comment

Choose a reason for hiding this comment

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

  1. Could you please add a test that demonstrates the new behavior?
  2. The PR title is misleading. This change does not actually add the fully qualified name as an attribute, it adds the module name. I think it'd be perfectly reasonable to add the qualified name instead if that's what you want to do. Just use __qualname__ instead of __module__. That may actually be better since it seems from the docs that __module__ may be None but __qualname__ should always be set. But either way seems OK to me, just make sure the PR title matches the implementation.

@@ -621,6 +621,20 @@ PyObject* process_outputs(PyObject *op_obj, const std::shared_ptr<PyNode>& cdata
}
}

auto module_name = PyDict_GetItemString(((PyTypeObject*)op_obj)->tp_dict, "__module__");
if (!module_name) {
return NULL;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please justify the error handling code here?
It seems like most uses of this code probably won't mind if the module is missing, so making this condition return early seems like it may not be the right thing to do.

@garymm garymm self-assigned this Oct 25, 2021
@shubhambhokare1 shubhambhokare1 changed the title [ONNX] Add fully qualified name as PythonOp attribute [ONNX] Add module name as PythonOp attribute Oct 28, 2021
@shubhambhokare1 shubhambhokare1 force-pushed the sbhokare/fully-qualified branch from 5c2e3c6 to afc24d0 Compare November 4, 2021 19:42
Copy link
Collaborator

@garymm garymm left a comment

Choose a reason for hiding this comment

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

Thanks!

Copy link
Collaborator

@BowenBao BowenBao left a comment

Choose a reason for hiding this comment

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

LGTM

@shubhambhokare1 shubhambhokare1 merged commit 35db1ec into pytorch:onnx_ms_1 Dec 10, 2021
BowenBao pushed a commit to BowenBao/pytorch that referenced this pull request Jan 5, 2022
* Add module name as pythonOp attr

* Move to trace_post_record

* Add tests

* Code compactness
BowenBao pushed a commit to BowenBao/pytorch that referenced this pull request Jan 21, 2022
* Add module name as pythonOp attr

* Move to trace_post_record

* Add tests

* Code compactness
BowenBao pushed a commit to BowenBao/pytorch that referenced this pull request Jan 21, 2022
* Add module name as pythonOp attr

* Move to trace_post_record

* Add tests

* Code compactness
BowenBao pushed a commit to BowenBao/pytorch that referenced this pull request Jan 31, 2022
* Add module name as pythonOp attr

* Move to trace_post_record

* Add tests

* Code compactness
garymm pushed a commit to garymm/pytorch that referenced this pull request Feb 9, 2022
* Add module name as pythonOp attr

* Move to trace_post_record

* Add tests

* Code compactness
hwangdeyu pushed a commit to hwangdeyu/pytorch that referenced this pull request Feb 9, 2022
* Add module name as pythonOp attr

* Move to trace_post_record

* Add tests

* Code compactness
BowenBao added a commit that referenced this pull request Mar 2, 2022
…te (#67193)"

* Add module name as pythonOp attr

* Move to trace_post_record

* Add tests

* Code compactness

[ghstack-poisoned]
BowenBao added a commit that referenced this pull request Mar 2, 2022
* Add module name as pythonOp attr

* Move to trace_post_record

* Add tests

* Code compactness

[ghstack-poisoned]
facebook-github-bot pushed a commit that referenced this pull request Mar 9, 2022
Summary:
Pull Request resolved: #73281

* Add module name as pythonOp attr

* Move to trace_post_record

* Add tests

* Code compactness

Test Plan: Imported from OSS

Reviewed By: jbschlosser

Differential Revision: D34625647

Pulled By: malfet

fbshipit-source-id: b04b2a4f1dc2cf733fcf50a3b022337f80d6eead
pytorchmergebot pushed a commit that referenced this pull request Mar 9, 2022
Summary:
Pull Request resolved: #73281

* Add module name as pythonOp attr

* Move to trace_post_record

* Add tests

* Code compactness

Test Plan: Imported from OSS

Reviewed By: jbschlosser

Differential Revision: D34625647

Pulled By: malfet

fbshipit-source-id: b04b2a4f1dc2cf733fcf50a3b022337f80d6eead
(cherry picked from commit 56e8658)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants