Skip to content

Conversation

@zou3519
Copy link
Contributor

@zou3519 zou3519 commented Jul 3, 2024

Stack from ghstack (oldest at bottom):

We add torch.library.Library._register_torch_dispatch_rule. Here, a user
can provide us a specific rule to run for a specific
(torch_dispatch_class, operator) pair. The motivation is that a user
might want to extend a subclass/mode but may not have access to the
source code of the subclass/mode.

I'll make this public in a follow-up PR if we think the approach and API
is good.

Keep in mind that many subclasses will likely deliver their own open
registration solution (DTensor has register_sharding_prop_rule and NJT
has register_jagged_op); _register_torch_dispatch_rule is meant as a
catch-all open registration mechanism for when the subclass hasn't
provided anything more specific.

Test Plan:

  • new tests

…odes)

We add torch.library.Library._register_torch_dispatch_rule. Here, a user
can provide us a specific rule to run for a specific
(torch_dispatch_class, operator) pair. The motivation is that a user
might want to extend a subclass/mode but may not have access to the
source code of the subclass/mode.

I'll make this public in a follow-up PR if we think the approach and API
is good.

Keep in mind that many subclasses will likely deliver their own open
registration solution (DTensor has register_sharding_prop_rule and NJT
has register_jagged_op); _register_torch_dispatch_rule is meant as a
catch-all open registration mechanism for when the subclass hasn't
provided anything more specific.

Test Plan:
- new tests

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Jul 3, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/130064

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 73bc42c with merge base 9c1ba5a (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

…sses (and modes)"

We add torch.library.Library._register_torch_dispatch_rule. Here, a user
can provide us a specific rule to run for a specific
(torch_dispatch_class, operator) pair. The motivation is that a user
might want to extend a subclass/mode but may not have access to the
source code of the subclass/mode.

I'll make this public in a follow-up PR if we think the approach and API
is good.

Keep in mind that many subclasses will likely deliver their own open
registration solution (DTensor has register_sharding_prop_rule and NJT
has register_jagged_op); _register_torch_dispatch_rule is meant as a
catch-all open registration mechanism for when the subclass hasn't
provided anything more specific.

Test Plan:
- new tests

[ghstack-poisoned]
zou3519 added a commit that referenced this pull request Jul 3, 2024
…odes)

We add torch.library.Library._register_torch_dispatch_rule. Here, a user
can provide us a specific rule to run for a specific
(torch_dispatch_class, operator) pair. The motivation is that a user
might want to extend a subclass/mode but may not have access to the
source code of the subclass/mode.

I'll make this public in a follow-up PR if we think the approach and API
is good.

Keep in mind that many subclasses will likely deliver their own open
registration solution (DTensor has register_sharding_prop_rule and NJT
has register_jagged_op); _register_torch_dispatch_rule is meant as a
catch-all open registration mechanism for when the subclass hasn't
provided anything more specific.

Test Plan:
- new tests

ghstack-source-id: 7675dbc
Pull Request resolved: #130064
@zou3519 zou3519 requested review from a team, albanD and bdhirsh July 5, 2024 13:36
Copy link
Collaborator

@albanD albanD left a comment

Choose a reason for hiding this comment

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

Sounds great!

…sses (and modes)"

We add torch.library.Library._register_torch_dispatch_rule. Here, a user
can provide us a specific rule to run for a specific
(torch_dispatch_class, operator) pair. The motivation is that a user
might want to extend a subclass/mode but may not have access to the
source code of the subclass/mode.

I'll make this public in a follow-up PR if we think the approach and API
is good.

Keep in mind that many subclasses will likely deliver their own open
registration solution (DTensor has register_sharding_prop_rule and NJT
has register_jagged_op); _register_torch_dispatch_rule is meant as a
catch-all open registration mechanism for when the subclass hasn't
provided anything more specific.

Test Plan:
- new tests

[ghstack-poisoned]
@zou3519 zou3519 added ciflow/trunk Trigger trunk jobs on your pull request release notes: composability release notes category labels Jul 8, 2024
@zou3519
Copy link
Contributor Author

zou3519 commented Jul 8, 2024

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@huydhn
Copy link
Contributor

huydhn commented Jul 9, 2024

@pytorchbot revert -m 'Sorry for reverting your change but test_profiler_tree is failing in trunk after this lands https://hud.pytorch.org/pytorch/pytorch/commit/922d2737d5e0ad22ee1dcf91c48ab09d641de840, maybe a landrace' -c landrace

@pytorchmergebot
Copy link
Collaborator

@pytorchbot successfully started a revert job. Check the current status here.
Questions? Feedback? Please reach out to the PyTorch DevX Team

@pytorchmergebot
Copy link
Collaborator

@zou3519 your PR has been successfully reverted.

…sses (and modes)"

We add torch.library.Library._register_torch_dispatch_rule. Here, a user
can provide us a specific rule to run for a specific
(torch_dispatch_class, operator) pair. The motivation is that a user
might want to extend a subclass/mode but may not have access to the
source code of the subclass/mode.

I'll make this public in a follow-up PR if we think the approach and API
is good.

Keep in mind that many subclasses will likely deliver their own open
registration solution (DTensor has register_sharding_prop_rule and NJT
has register_jagged_op); _register_torch_dispatch_rule is meant as a
catch-all open registration mechanism for when the subclass hasn't
provided anything more specific.

Test Plan:
- new tests

[ghstack-poisoned]
@zou3519
Copy link
Contributor Author

zou3519 commented Jul 9, 2024

@huydhn afaict that test was added in 2022, is something else wrong with CI? I did confirm that the test failed locally.

@clee2000 clee2000 added the ci-no-td Do not run TD on this PR label Jul 9, 2024
pytorchmergebot pushed a commit that referenced this pull request Jul 9, 2024
This is the API for defining the interaction between a torch_dispatch
class and a custom op. Taking API bikeshedding.

Test Plan:
- new tests
Pull Request resolved: #130261
Approved by: https://github.com/albanD
ghstack dependencies: #130064
datagero pushed a commit to datagero/pytorch that referenced this pull request Jul 10, 2024
…odes) (pytorch#130064)

We add torch.library.Library._register_torch_dispatch_rule. Here, a user
can provide us a specific rule to run for a specific
(torch_dispatch_class, operator) pair. The motivation is that a user
might want to extend a subclass/mode but may not have access to the
source code of the subclass/mode.

I'll make this public in a follow-up PR if we think the approach and API
is good.

Keep in mind that many subclasses will likely deliver their own open
registration solution (DTensor has register_sharding_prop_rule and NJT
has register_jagged_op); _register_torch_dispatch_rule is meant as a
catch-all open registration mechanism for when the subclass hasn't
provided anything more specific.

Test Plan:
- new tests
Pull Request resolved: pytorch#130064
Approved by: https://github.com/albanD
datagero pushed a commit to datagero/pytorch that referenced this pull request Jul 10, 2024
…0261)

This is the API for defining the interaction between a torch_dispatch
class and a custom op. Taking API bikeshedding.

Test Plan:
- new tests
Pull Request resolved: pytorch#130261
Approved by: https://github.com/albanD
ghstack dependencies: pytorch#130064
pytorchmergebot added a commit that referenced this pull request Jul 10, 2024
@izaitsevfb
Copy link
Contributor

@pytorchbot revert -m "fails internal builds, see D59553526" -c ghfirst

ERROR    ...
ERROR    reason: Action failed: fbcode//caffe2:_C_impl_cuda (fbcode//buck2/platform/execution:linux-x86_64#22f53947965bda2d) (cxx_compile torch/csrc/utils/python_arg_parser.cpp (pic))
ERROR    Remote command returned non-zero exit code 1
ERROR    Remote action, reproduce with: `frecli cas download-action 9c60783056764f8cb03d98ef26e521ad27a68f14daa5ed7ef3c9d9790a5e70cb:145`
ERROR    Stdout: <empty>
ERROR    Stderr:
ERROR    fbcode/caffe2/torch/csrc/utils/python_arg_parser.cpp:265:3: error: unknown type name 'PYBIND11_CONSTINIT'
ERROR      PYBIND11_CONSTINIT static py::gil_safe_call_once_and_store<py::object>
ERROR      ^
ERROR    fbcode/caffe2/torch/csrc/utils/python_arg_parser.cpp:265:33: error: definition or redeclaration of 'gil_safe_call_once_and_store' not allowed inside a function
ERROR      PYBIND11_CONSTINIT static py::gil_safe_call_once_and_store<py::object>
ERROR                                ~~~~^
ERROR    fbcode/caffe2/torch/csrc/utils/python_arg_parser.cpp:265:33: error: no member named 'gil_safe_call_once_and_store' in namespace 'pybind11'
ERROR      PYBIND11_CONSTINIT static py::gil_safe_call_once_and_store<py::object>
ERROR                                ~~~~^
ERROR    fbcode/caffe2/torch/csrc/utils/python_arg_parser.cpp:265:61: error: expected ';' at end of declaration
ERROR      PYBIND11_CONSTINIT static py::gil_safe_call_once_and_store<py::object>
ERROR                                                                ^
ERROR                                                                ;
ERROR    fbcode/caffe2/torch/csrc/utils/python_arg_parser.cpp:268:7: error: use of undeclared identifier 'storage'
ERROR          storage
ERROR          ^
ERROR    5 errors generated.
ERROR 
ERROR      --> fbcode/buck2/prelude/python/sourcedb/build.bxl:25:9
ERROR       |
ERROR    25 |         fail(error_message)
ERROR       |         ^^^^^^^^^^^^^^^^^^^
ERROR       |
ERROR 

@pytorchmergebot
Copy link
Collaborator

@pytorchbot successfully started a revert job. Check the current status here.
Questions? Feedback? Please reach out to the PyTorch DevX Team

@pytorchmergebot
Copy link
Collaborator

@zou3519 your PR has been successfully reverted.

…sses (and modes)"

We add torch.library.Library._register_torch_dispatch_rule. Here, a user
can provide us a specific rule to run for a specific
(torch_dispatch_class, operator) pair. The motivation is that a user
might want to extend a subclass/mode but may not have access to the
source code of the subclass/mode.

I'll make this public in a follow-up PR if we think the approach and API
is good.

Keep in mind that many subclasses will likely deliver their own open
registration solution (DTensor has register_sharding_prop_rule and NJT
has register_jagged_op); _register_torch_dispatch_rule is meant as a
catch-all open registration mechanism for when the subclass hasn't
provided anything more specific.

Test Plan:
- new tests

[ghstack-poisoned]
Comment on lines +265 to +267
static auto find_torch_dispatch_rule =
py::module_::import("torch._library.simple_registry")
.attr("find_torch_dispatch_rule");
Copy link
Collaborator

@XuehaiPan XuehaiPan Jul 11, 2024

Choose a reason for hiding this comment

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

Suggested change
static auto find_torch_dispatch_rule =
py::module_::import("torch._library.simple_registry")
.attr("find_torch_dispatch_rule");
static const py::handle find_torch_dispatch_rule =
py::module_::import("torch._library.simple_registry")
.attr("find_torch_dispatch_rule").release();

Use py::handle instead of py::object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's the difference?
Also I can fix this up (go back to the original approach you suggested) when we update pybind11 internally (which will hopefully be soon); I want to merge this PR sooner than later because it may have performance implications.

Copy link
Collaborator

Choose a reason for hiding this comment

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

py::handle is equivalent to PyObject *. It will not do Py_DECREF(obj.m_ptr) on C++ instance destruction where py::object will. handle = object.release() will leak the instance to keep it alive on Python side.

…sses (and modes)"

We add torch.library.Library._register_torch_dispatch_rule. Here, a user
can provide us a specific rule to run for a specific
(torch_dispatch_class, operator) pair. The motivation is that a user
might want to extend a subclass/mode but may not have access to the
source code of the subclass/mode.

I'll make this public in a follow-up PR if we think the approach and API
is good.

Keep in mind that many subclasses will likely deliver their own open
registration solution (DTensor has register_sharding_prop_rule and NJT
has register_jagged_op); _register_torch_dispatch_rule is meant as a
catch-all open registration mechanism for when the subclass hasn't
provided anything more specific.

Test Plan:
- new tests

[ghstack-poisoned]
pytorchmergebot pushed a commit that referenced this pull request Jul 12, 2024
This is the API for defining the interaction between a torch_dispatch
class and a custom op. Taking API bikeshedding.

Test Plan:
- new tests
Pull Request resolved: #130261
Approved by: https://github.com/albanD
ghstack dependencies: #130064
xuhancn pushed a commit to xuhancn/pytorch that referenced this pull request Jul 25, 2024
…odes) (pytorch#130064)

We add torch.library.Library._register_torch_dispatch_rule. Here, a user
can provide us a specific rule to run for a specific
(torch_dispatch_class, operator) pair. The motivation is that a user
might want to extend a subclass/mode but may not have access to the
source code of the subclass/mode.

I'll make this public in a follow-up PR if we think the approach and API
is good.

Keep in mind that many subclasses will likely deliver their own open
registration solution (DTensor has register_sharding_prop_rule and NJT
has register_jagged_op); _register_torch_dispatch_rule is meant as a
catch-all open registration mechanism for when the subclass hasn't
provided anything more specific.

Test Plan:
- new tests
Pull Request resolved: pytorch#130064
Approved by: https://github.com/albanD
xuhancn pushed a commit to xuhancn/pytorch that referenced this pull request Jul 25, 2024
…0261)

This is the API for defining the interaction between a torch_dispatch
class and a custom op. Taking API bikeshedding.

Test Plan:
- new tests
Pull Request resolved: pytorch#130261
Approved by: https://github.com/albanD
ghstack dependencies: pytorch#130064
xuhancn pushed a commit to xuhancn/pytorch that referenced this pull request Jul 25, 2024
xuhancn pushed a commit to xuhancn/pytorch that referenced this pull request Jul 25, 2024
xuhancn pushed a commit to xuhancn/pytorch that referenced this pull request Jul 25, 2024
…odes) (pytorch#130064)

We add torch.library.Library._register_torch_dispatch_rule. Here, a user
can provide us a specific rule to run for a specific
(torch_dispatch_class, operator) pair. The motivation is that a user
might want to extend a subclass/mode but may not have access to the
source code of the subclass/mode.

I'll make this public in a follow-up PR if we think the approach and API
is good.

Keep in mind that many subclasses will likely deliver their own open
registration solution (DTensor has register_sharding_prop_rule and NJT
has register_jagged_op); _register_torch_dispatch_rule is meant as a
catch-all open registration mechanism for when the subclass hasn't
provided anything more specific.

Test Plan:
- new tests
Pull Request resolved: pytorch#130064
Approved by: https://github.com/albanD
xuhancn pushed a commit to xuhancn/pytorch that referenced this pull request Jul 25, 2024
…0261)

This is the API for defining the interaction between a torch_dispatch
class and a custom op. Taking API bikeshedding.

Test Plan:
- new tests
Pull Request resolved: pytorch#130261
Approved by: https://github.com/albanD
ghstack dependencies: pytorch#130064
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-no-td Do not run TD on this PR ciflow/trunk Trigger trunk jobs on your pull request Merged release notes: composability release notes category Reverted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants