Skip to content

Define the EXPERIMENTAL_PREFER_TRACING flag and the traceable option | feat(torchlib) #1176

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
merged 17 commits into from
Nov 28, 2023

Conversation

justinchuby
Copy link
Collaborator

@justinchuby justinchuby commented Nov 22, 2023

Stack from ghstack (oldest at bottom):

As an effort described in #1095, this PR

  • adds an experimental TORCHLIB_EXPERIMENTAL_PREFER_TRACING flag to allow the tracer to trace a function when possible.
  • defined the traceable option in the torch_op decorator to mark a function as traceable.

Signed-off-by: Justin Chu <[email protected]>

[ghstack-poisoned]
@justinchuby justinchuby changed the title Define the EXPERIMENTAL_PREFER_TRACING flag Define the EXPERIMENTAL_PREFER_TRACING flag | feat(torchlib) Nov 22, 2023
@justinchuby justinchuby requested a review from BowenBao November 22, 2023 03:27
@justinchuby justinchuby changed the title Define the EXPERIMENTAL_PREFER_TRACING flag | feat(torchlib) Define the EXPERIMENTAL_PREFER_TRACING flag and the traceable option | feat(torchlib) Nov 22, 2023
@justinchuby justinchuby added the module: torchlib Related to the torch/aten function lib in development label Nov 22, 2023
@justinchuby justinchuby mentioned this pull request Nov 22, 2023
5 tasks
Copy link

codecov bot commented Nov 22, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (49bd447) 78.67% compared to head (a28f765) 78.71%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1176      +/-   ##
==========================================
+ Coverage   78.67%   78.71%   +0.03%     
==========================================
  Files         118      118              
  Lines       15334    15348      +14     
  Branches     2392     2394       +2     
==========================================
+ Hits        12064    12081      +17     
+ Misses       2876     2873       -3     
  Partials      394      394              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Nov 22, 2023

Test Results

         24 files         24 suites   1h 50m 49s ⏱️
  11 222 tests   8 359 ✔️     2 862 💤 1
253 716 runs  56 747 ✔️ 196 968 💤 1

For more details on these failures, see this check.

Results for commit a28f765.

♻️ This comment has been updated with latest results.

…g and the traceable option | feat(torchlib)"


As an effort described in #1095, this PR

- adds an experimental `TORCHLIB_EXPERIMENTAL_PREFER_TRACING` flag to allow the tracer to trace a function when possible.
- defined the `traceable` option in the torch_op decorator to mark a function as `traceable`.

[ghstack-poisoned]
…ble option | feat(torchlib)"


As an effort described in #1095, this PR

- adds an experimental `TORCHLIB_EXPERIMENTAL_PREFER_TRACING` flag to allow the tracer to trace a function when possible.
- defined the `traceable` option in the torch_op decorator to mark a function as `traceable`.

[ghstack-poisoned]
@@ -112,6 +113,7 @@ def torch_op(
private: Whether the function is private (not directly exposed). It should
be true for all functions with names starting with "_".
complex: Whether the function expects complex-valued inputs.
traceable: Whether the function can be traced.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand this comment. Could you elaborate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A function is traceable if it can both be scripted and traced and produce the same result for a given input. Does that sound reasonable? I will add this to the docstring if it does.

Copy link
Collaborator Author

@justinchuby justinchuby Nov 22, 2023

Choose a reason for hiding this comment

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

  • A function can be tagged with traceable if its if branches (if any) can be statically evaluated.
  • A function should be tagged with traceable if it contains if branches and/or CastLike nodes so that they can be evaluated away with the EXPERIMENTAL_PREFER_TRACING on.
  • A function without if branches or CastLike nodes should not be tagged with traceable because inlining will do the same thing.
  • A function with @graph defined for a Scan op is not traceable yet.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

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 any chance one could wrongly tag a function traceable, and create a bug?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is a chance. We should be able to catch them in the op info tests.

@justinchuby justinchuby changed the base branch from main to gh/justinchuby/44/base November 22, 2023 23:48
…g and the traceable option | feat(torchlib)"


As an effort described in #1095, this PR

- adds an experimental `TORCHLIB_EXPERIMENTAL_PREFER_TRACING` flag to allow the tracer to trace a function when possible.
- defined the `traceable` option in the torch_op decorator to mark a function as `traceable`.

[ghstack-poisoned]
…ble option | feat(torchlib)"


As an effort described in #1095, this PR

- adds an experimental `TORCHLIB_EXPERIMENTAL_PREFER_TRACING` flag to allow the tracer to trace a function when possible.
- defined the `traceable` option in the torch_op decorator to mark a function as `traceable`.

[ghstack-poisoned]
…g and the traceable option | feat(torchlib)"


As an effort described in #1095, this PR

- adds an experimental `TORCHLIB_EXPERIMENTAL_PREFER_TRACING` flag to allow the tracer to trace a function when possible.
- defined the `traceable` option in the torch_op decorator to mark a function as `traceable`.

[ghstack-poisoned]
…ble option | feat(torchlib)"


As an effort described in #1095, this PR

- adds an experimental `TORCHLIB_EXPERIMENTAL_PREFER_TRACING` flag to allow the tracer to trace a function when possible.
- defined the `traceable` option in the torch_op decorator to mark a function as `traceable`.

[ghstack-poisoned]
…g and the traceable option | feat(torchlib)"


As an effort described in #1095, this PR

- adds an experimental `TORCHLIB_EXPERIMENTAL_PREFER_TRACING` flag to allow the tracer to trace a function when possible.
- defined the `traceable` option in the torch_op decorator to mark a function as `traceable`.

[ghstack-poisoned]
…ble option | feat(torchlib)"


As an effort described in #1095, this PR

- adds an experimental `TORCHLIB_EXPERIMENTAL_PREFER_TRACING` flag to allow the tracer to trace a function when possible.
- defined the `traceable` option in the torch_op decorator to mark a function as `traceable`.

[ghstack-poisoned]
…g and the traceable option | feat(torchlib)"


As an effort described in #1095, this PR

- adds an experimental `TORCHLIB_EXPERIMENTAL_PREFER_TRACING` flag to allow the tracer to trace a function when possible.
- defined the `traceable` option in the torch_op decorator to mark a function as `traceable`.

[ghstack-poisoned]
…ble option | feat(torchlib)"


As an effort described in #1095, this PR

- adds an experimental `TORCHLIB_EXPERIMENTAL_PREFER_TRACING` flag to allow the tracer to trace a function when possible.
- defined the `traceable` option in the torch_op decorator to mark a function as `traceable`.

[ghstack-poisoned]
…g and the traceable option | feat(torchlib)"


As an effort described in #1095, this PR

- adds an experimental `TORCHLIB_EXPERIMENTAL_PREFER_TRACING` flag to allow the tracer to trace a function when possible.
- defined the `traceable` option in the torch_op decorator to mark a function as `traceable`.

[ghstack-poisoned]
…ble option | feat(torchlib)"


As an effort described in #1095, this PR

- adds an experimental `TORCHLIB_EXPERIMENTAL_PREFER_TRACING` flag to allow the tracer to trace a function when possible.
- defined the `traceable` option in the torch_op decorator to mark a function as `traceable`.

[ghstack-poisoned]
xiaowuhu pushed a commit that referenced this pull request Nov 27, 2023
…t(torchlib) (#1180)

Stack from [ghstack](https://github.com/ezyang/ghstack) (oldest at
bottom):
* #1178
* #1177
* #1176
* __->__ #1180

### Changes

- Create env to test with TORCHLIB_EXPERIMENTAL_PREFER_TRACING on
- Test with Python 3.11 as well
- Fixes #1061
- Fix aten::any.dims and aten::all.dims
…g and the traceable option | feat(torchlib)"


As an effort described in #1095, this PR

- adds an experimental `TORCHLIB_EXPERIMENTAL_PREFER_TRACING` flag to allow the tracer to trace a function when possible.
- defined the `traceable` option in the torch_op decorator to mark a function as `traceable`.

[ghstack-poisoned]
…ble option | feat(torchlib)"


As an effort described in #1095, this PR

- adds an experimental `TORCHLIB_EXPERIMENTAL_PREFER_TRACING` flag to allow the tracer to trace a function when possible.
- defined the `traceable` option in the torch_op decorator to mark a function as `traceable`.

[ghstack-poisoned]
@justinchuby justinchuby changed the base branch from gh/justinchuby/44/base to main November 27, 2023 22:14
@justinchuby justinchuby requested a review from BowenBao November 28, 2023 02:34
@justinchuby
Copy link
Collaborator Author

Will merge now. LMK if I should create follow ups

@justinchuby justinchuby merged commit 9a87303 into main Nov 28, 2023
@justinchuby justinchuby deleted the gh/justinchuby/44/head branch November 28, 2023 18:29
justinchuby added a commit that referenced this pull request Nov 28, 2023
Stack from [ghstack](https://github.com/ezyang/ghstack) (oldest at
bottom):
* #1178
* __->__ #1177
* #1176

As an effort described in
#1095, this PR marks
functions with if branches as traceable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: torchlib Related to the torch/aten function lib in development
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants