Skip to content

Conversation

@zou3519
Copy link
Contributor

@zou3519 zou3519 commented Apr 26, 2023

Stack from ghstack:

This PR changes the CustomOp API. There are now two ways to create a
CustomOp object.

Method 1: with no schema string. We will infer what the schema string is
from your type annotations

@custom_op("customlib::foo")
def foo(x: Tensor) -> Tensor:
    ...

Method 2: with a schema string, if the inference doesn't work well.

@custom_op("customlib::foo", "(Tensor x) -> Tensor")
def foo(x):
    ...

Some details:

  • We support most combinations of {Tensor, Number, int, float, bool} and
    {Optional[typ], Tuple[typ, ...]} as inputs. The combinations we support are mostly
    from me reading native_functions.yaml.
  • We support only Tensor or Tuple of Tensor of fixed size returns.
  • A lot of this PR is input validation for both of the above two
    methods. For example, when a user provides a manual schema string, then
    their function must not have any type annotations and the number of args
    and arg names must match the schema.

Test Plan:

  • new tests

This PR changes the CustomOp API. There are now two ways to create a
CustomOp object.

Method 1: with no schema string. We will infer what the schema string is
from your type annotations

```py
@custom_op("customlib::foo")
def foo(x: Tensor) -> Tensor:
    ...
```

Method 2: with a schema string, if the inference doesn't work well.

```py
@custom_op("customlib::foo", "(Tensor x) -> Tensor")
def foo(x):
    ...
```

Some details:
- We support most combinations of {Tensor, Number, int, float, bool} and
{Optional[typ], Tuple[typ, ...]} as inputs. The combinations we support are mostly
from me reading native_functions.yaml.
- We support only Tensor or Tuple of Tensor of fixed size returns.
- A lot of this PR is input validation for both of the above two
methods. For example, when a user provides a manual schema string, then
their function must not have any type annotations and the number of args
and arg names must match the schema.

Test Plan:
- new tests

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Apr 26, 2023

🔗 Helpful Links

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

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

✅ No Failures

As of commit 0833eda:
💚 Looks good so far! There are no failures yet. 💚

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

zou3519 added a commit that referenced this pull request Apr 26, 2023
This PR changes the CustomOp API. There are now two ways to create a
CustomOp object.

Method 1: with no schema string. We will infer what the schema string is
from your type annotations

```py
custom_op("customlib::foo")
def foo(x: Tensor) -> Tensor:
    ...
```

Method 2: with a schema string, if the inference doesn't work well.

```py
custom_op("customlib::foo", "(Tensor x) -> Tensor")
def foo(x):
    ...
```

Some details:
- We support most combinations of {Tensor, Number, int, float, bool} and
{Optional[typ], Tuple[typ, ...]} as inputs. The combinations we support are mostly
from me reading native_functions.yaml.
- We support only Tensor or Tuple of Tensor of fixed size returns.
- A lot of this PR is input validation for both of the above two
methods. For example, when a user provides a manual schema string, then
their function must not have any type annotations and the number of args
and arg names must match the schema.

Test Plan:
- new tests

ghstack-source-id: 727f2c6
Pull Request resolved: #100127
@zou3519 zou3519 added the release notes: composability release notes category label Apr 26, 2023
@zou3519 zou3519 requested review from bdhirsh, ezyang and soulitzer April 26, 2023 21:45
This API is used as a decorator (see examples).
Arguments:
TODO(rzou)
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO

This PR changes the CustomOp API. There are now two ways to create a
CustomOp object.

Method 1: with no schema string. We will infer what the schema string is
from your type annotations

```py
custom_op("customlib::foo")
def foo(x: Tensor) -> Tensor:
    ...
```

Method 2: with a schema string, if the inference doesn't work well.

```py
custom_op("customlib::foo", "(Tensor x) -> Tensor")
def foo(x):
    ...
```

Some details:
- We support most combinations of {Tensor, Number, int, float, bool} and
{Optional[typ], Tuple[typ, ...]} as inputs. The combinations we support are mostly
from me reading native_functions.yaml.
- We support only Tensor or Tuple of Tensor of fixed size returns.
- A lot of this PR is input validation for both of the above two
methods. For example, when a user provides a manual schema string, then
their function must not have any type annotations and the number of args
and arg names must match the schema.

Test Plan:
- new tests

[ghstack-poisoned]
This PR changes the CustomOp API. There are now two ways to create a
CustomOp object.

Method 1: with no schema string. We will infer what the schema string is
from your type annotations

```py
custom_op("customlib::foo")
def foo(x: Tensor) -> Tensor:
    ...
```

Method 2: with a schema string, if the inference doesn't work well.

```py
custom_op("customlib::foo", "(Tensor x) -> Tensor")
def foo(x):
    ...
```

Some details:
- We support most combinations of {Tensor, Number, int, float, bool} and
{Optional[typ], Tuple[typ, ...]} as inputs. The combinations we support are mostly
from me reading native_functions.yaml.
- We support only Tensor or Tuple of Tensor of fixed size returns.
- A lot of this PR is input validation for both of the above two
methods. For example, when a user provides a manual schema string, then
their function must not have any type annotations and the number of args
and arg names must match the schema.

Test Plan:
- new tests

[ghstack-poisoned]
This PR changes the CustomOp API. There are now two ways to create a
CustomOp object.

Method 1: with no schema string. We will infer what the schema string is
from your type annotations

```py
custom_op("customlib::foo")
def foo(x: Tensor) -> Tensor:
    ...
```

Method 2: with a schema string, if the inference doesn't work well.

```py
custom_op("customlib::foo", "(Tensor x) -> Tensor")
def foo(x):
    ...
```

Some details:
- We support most combinations of {Tensor, Number, int, float, bool} and
{Optional[typ], Tuple[typ, ...]} as inputs. The combinations we support are mostly
from me reading native_functions.yaml.
- We support only Tensor or Tuple of Tensor of fixed size returns.
- A lot of this PR is input validation for both of the above two
methods. For example, when a user provides a manual schema string, then
their function must not have any type annotations and the number of args
and arg names must match the schema.

Test Plan:
- new tests

[ghstack-poisoned]
This PR changes the CustomOp API. There are now two ways to create a
CustomOp object.

Method 1: with no schema string. We will infer what the schema string is
from your type annotations

```py
custom_op("customlib::foo")
def foo(x: Tensor) -> Tensor:
    ...
```

Method 2: with a schema string, if the inference doesn't work well.

```py
custom_op("customlib::foo", "(Tensor x) -> Tensor")
def foo(x):
    ...
```

Some details:
- We support most combinations of {Tensor, Number, int, float, bool} and
{Optional[typ], Tuple[typ, ...]} as inputs. The combinations we support are mostly
from me reading native_functions.yaml.
- We support only Tensor or Tuple of Tensor of fixed size returns.
- A lot of this PR is input validation for both of the above two
methods. For example, when a user provides a manual schema string, then
their function must not have any type annotations and the number of args
and arg names must match the schema.

Test Plan:
- new tests

[ghstack-poisoned]
zou3519 added a commit that referenced this pull request Apr 27, 2023
This PR changes the CustomOp API. There are now two ways to create a
CustomOp object.

Method 1: with no schema string. We will infer what the schema string is
from your type annotations

```py
custom_op("customlib::foo")
def foo(x: Tensor) -> Tensor:
    ...
```

Method 2: with a schema string, if the inference doesn't work well.

```py
custom_op("customlib::foo", "(Tensor x) -> Tensor")
def foo(x):
    ...
```

Some details:
- We support most combinations of {Tensor, Number, int, float, bool} and
{Optional[typ], Tuple[typ, ...]} as inputs. The combinations we support are mostly
from me reading native_functions.yaml.
- We support only Tensor or Tuple of Tensor of fixed size returns.
- A lot of this PR is input validation for both of the above two
methods. For example, when a user provides a manual schema string, then
their function must not have any type annotations and the number of args
and arg names must match the schema.

Test Plan:
- new tests

ghstack-source-id: ac5ff4b
Pull Request resolved: #100127
@zou3519 zou3519 added the ciflow/trunk Trigger trunk jobs on your pull request label Apr 28, 2023
@zou3519
Copy link
Contributor Author

zou3519 commented Apr 28, 2023

@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

@facebook-github-bot facebook-github-bot deleted the gh/zou3519/640/head branch June 8, 2023 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged merging release notes: composability release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants