Skip to content

Commit 0833eda

Browse files
committed
Update on "Improved CustomOp API with schema inference"
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]
2 parents d6136b3 + a694d6f commit 0833eda

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

test/test_meta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
OpDTypes,
2727
)
2828
from torch.testing._internal.common_methods_invocations import op_db
29-
from torchgen.yaml import YamlLoader
29+
from torchgen.yaml_utils import YamlLoader
3030
from torchgen.model import OperatorName
3131

3232
import sys

0 commit comments

Comments
 (0)