Skip to content

Conversation

@larryliu0820
Copy link
Contributor

Summary:
RFC: pytorch/rfcs#40
In #69881 we added the ability to generate codegen unboxing source files. Notice that the generated code to register an operator looks like this:

    // aten::add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1) -> Tensor
    OperatorGenerator(
        TORCH_SELECTIVE_SCHEMA("aten::add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1) -> Tensor"),
        [](Stack & stack) {
            RECORD_FUNCTION("add", std::vector<c10::IValue>());
            at::unboxing::add_Tensor(stack);
        },
        aliasAnalysisFromSchema()
    ),

However, this means we have to parse the schema and get back arguments with default values in static init time. As written in the RFC, there's a more performant option: providing these arguments with default values using codegen, then we don't have to do expensive regex pattern matching in parsing. Here's how it looks like:

    // aten::add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1) -> Tensor
    OperatorGenerator(
        "aten::add",
        "Tensor",
        {
            c10::Argument("self", nullptr, c10::nullopt, c10::IValue(c10::nullopt)),
    	    c10::Argument("other", nullptr, c10::nullopt, c10::IValue(c10::nullopt)),
    	    c10::Argument("alpha", nullptr, c10::nullopt, c10::IValue(1))
        },
        {
            c10::Argument("")
        },
        [](Stack & stack) {
            RECORD_FUNCTION("add", std::vector<c10::IValue>());
            at::unboxing::add_Tensor(stack);
        },
        aliasAnalysisFromSchema()
    ),

We also added corresponding APIs in operator.h to take in the arguments.

Test Plan: Rely on CI

Differential Revision: D33077733

@pytorch-bot
Copy link

pytorch-bot bot commented Mar 10, 2022

CI Flow Status

⚛️ CI Flow

Ruleset - Version: v1
Ruleset - File: https://github.com/larryliu0820/pytorch/blob/3aa6c95c279568f1a9afca040f4c18503f628114/.github/generated-ciflow-ruleset.json
PR ciflow labels: ciflow/default
Add ciflow labels to this PR to trigger more builds:

Workflows Labels (bold enabled) Status
Triggered Workflows
linux-binary-conda ciflow/binaries, ciflow/binaries_conda, ciflow/default ✅ triggered
linux-binary-libtorch-cxx11-abi ciflow/all, ciflow/binaries, ciflow/binaries_libtorch, ciflow/default, ciflow/trunk ✅ triggered
linux-binary-libtorch-pre-cxx11 ciflow/all, ciflow/binaries, ciflow/binaries_libtorch, ciflow/default, ciflow/trunk ✅ triggered
linux-binary-manywheel ciflow/all, ciflow/binaries, ciflow/binaries_wheel, ciflow/default, ciflow/trunk ✅ triggered
linux-bionic-py3.7-clang9 ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/noarch, ciflow/trunk ✅ triggered
linux-bionic-rocm4.5-py3.7 ciflow/all, ciflow/default, ciflow/linux, ciflow/rocm, ciflow/trunk ✅ triggered
linux-docs ciflow/all, ciflow/cpu, ciflow/default, ciflow/docs, ciflow/linux, ciflow/trunk ✅ triggered
linux-vulkan-bionic-py3.7-clang9 ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/trunk, ciflow/vulkan ✅ triggered
linux-xenial-cuda11.3-py3.7-gcc7 ciflow/all, ciflow/cuda, ciflow/default, ciflow/linux, ciflow/trunk ✅ triggered
linux-xenial-cuda11.3-py3.7-gcc7-bazel-test ciflow/all, ciflow/bazel, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/trunk ✅ triggered
linux-xenial-py3-clang5-mobile-build ciflow/all, ciflow/default, ciflow/linux, ciflow/mobile, ciflow/trunk ✅ triggered
linux-xenial-py3-clang5-mobile-custom-build-static ciflow/all, ciflow/default, ciflow/linux, ciflow/mobile, ciflow/trunk ✅ triggered
linux-xenial-py3.7-clang7-asan ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/sanitizers, ciflow/trunk ✅ triggered
linux-xenial-py3.7-clang7-onnx ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/onnx, ciflow/trunk ✅ triggered
linux-xenial-py3.7-gcc5.4 ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/trunk ✅ triggered
linux-xenial-py3.7-gcc5.4-mobile-lightweight-dispatch-build ciflow/all, ciflow/cpu, ciflow/default, ciflow/libtorch, ciflow/linux, ciflow/mobile, ciflow/trunk ✅ triggered
linux-xenial-py3.7-gcc7 ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/trunk ✅ triggered
linux-xenial-py3.7-gcc7-no-ops ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/trunk ✅ triggered
macos-arm64-binary-conda ciflow/binaries, ciflow/binaries_conda, ciflow/default ✅ triggered
macos-arm64-binary-wheel ciflow/binaries, ciflow/binaries_wheel, ciflow/default ✅ triggered
macos-binary-conda ciflow/binaries, ciflow/binaries_conda, ciflow/default ✅ triggered
macos-binary-libtorch-cxx11-abi ciflow/binaries, ciflow/binaries_libtorch, ciflow/default ✅ triggered
macos-binary-libtorch-pre-cxx11 ciflow/binaries, ciflow/binaries_libtorch, ciflow/default ✅ triggered
macos-binary-wheel ciflow/binaries, ciflow/binaries_wheel, ciflow/default ✅ triggered
pytorch-linux-xenial-py3-clang5-android-ndk-r19c-gradle-custom-build-single ciflow/all, ciflow/android, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/trunk ✅ 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, ciflow/trunk ✅ triggered
win-vs2019-cpu-py3 ciflow/all, ciflow/cpu, ciflow/default, ciflow/trunk, ciflow/win ✅ triggered
win-vs2019-cuda11.3-py3 ciflow/all, ciflow/cuda, ciflow/default, ciflow/trunk, ciflow/win ✅ triggered
windows-binary-conda ciflow/binaries, ciflow/binaries_conda, ciflow/default ✅ triggered
windows-binary-libtorch-debug ciflow/all, ciflow/binaries, ciflow/binaries_libtorch, ciflow/default, ciflow/trunk ✅ triggered
windows-binary-libtorch-release ciflow/all, ciflow/binaries, ciflow/binaries_libtorch, ciflow/default, ciflow/trunk ✅ triggered
windows-binary-wheel ciflow/all, ciflow/binaries, ciflow/binaries_wheel, ciflow/default, ciflow/trunk ✅ triggered
Skipped Workflows
caffe2-linux-xenial-py3.7-gcc5.4 ciflow/all, ciflow/cpu, ciflow/linux, ciflow/trunk 🚫 skipped
docker-builds ciflow/all, ciflow/trunk 🚫 skipped
ios-12-5-1-arm64 ciflow/all, ciflow/ios, ciflow/macos, ciflow/scheduled 🚫 skipped
ios-12-5-1-arm64-coreml ciflow/all, ciflow/ios, ciflow/macos, ciflow/scheduled 🚫 skipped
ios-12-5-1-arm64-custom-ops ciflow/all, ciflow/ios, ciflow/macos, ciflow/scheduled 🚫 skipped
ios-12-5-1-arm64-metal ciflow/all, ciflow/ios, ciflow/macos, ciflow/scheduled 🚫 skipped
ios-12-5-1-x86-64 ciflow/all, ciflow/ios, ciflow/macos, ciflow/trunk 🚫 skipped
ios-12-5-1-x86-64-coreml ciflow/all, ciflow/ios, ciflow/macos, ciflow/trunk 🚫 skipped
libtorch-linux-xenial-cuda10.2-py3.7-gcc7 ciflow/all, ciflow/cuda, ciflow/libtorch, ciflow/linux, ciflow/trunk 🚫 skipped
libtorch-linux-xenial-cuda11.3-py3.7-gcc7 ciflow/all, ciflow/cuda, ciflow/libtorch, ciflow/linux, ciflow/trunk 🚫 skipped
linux-bionic-cuda10.2-py3.9-gcc7 ciflow/all, ciflow/cuda, ciflow/linux, ciflow/slow, ciflow/trunk 🚫 skipped
linux-bionic-rocm4.5-py3.7-distributed ciflow/all, ciflow/linux, ciflow/rocm, ciflow/trunk 🚫 skipped
linux-docs-push ciflow/all, ciflow/cpu, ciflow/linux, ciflow/scheduled 🚫 skipped
linux-xenial-cuda11.3-py3.7-gcc7-no-ops ciflow/all, ciflow/cuda, ciflow/linux, ciflow/trunk 🚫 skipped
macos-10-15-py3-arm64 ciflow/all, ciflow/macos, ciflow/trunk 🚫 skipped
macos-10-15-py3-lite-interpreter-x86-64 ciflow/all, ciflow/macos, ciflow/trunk 🚫 skipped
macos-11-py3-x86-64 ciflow/all, ciflow/macos, ciflow/trunk 🚫 skipped
parallelnative-linux-xenial-py3.7-gcc5.4 ciflow/all, ciflow/cpu, ciflow/linux, ciflow/trunk 🚫 skipped
periodic-libtorch-linux-bionic-cuda11.5-py3.7-gcc7 ciflow/all, ciflow/cuda, ciflow/libtorch, ciflow/linux, ciflow/scheduled 🚫 skipped
periodic-linux-bionic-cuda11.5-py3.7-gcc7 ciflow/all, ciflow/cuda, 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.3-py3.7-gcc7-debug ciflow/all, ciflow/cuda, ciflow/linux, ciflow/scheduled 🚫 skipped
periodic-win-vs2019-cuda11.5-py3 ciflow/all, ciflow/cuda, ciflow/scheduled, ciflow/win 🚫 skipped
pytorch-linux-xenial-py3-clang5-android-ndk-r19c-build ciflow/all, ciflow/android, ciflow/cpu, ciflow/linux, ciflow/trunk 🚫 skipped
pytorch-xla-linux-bionic-py3.7-clang8 ciflow/all, ciflow/cpu, ciflow/linux, ciflow/trunk, ciflow/xla 🚫 skipped

@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Mar 10, 2022

🔗 Helpful links

💊 CI failures summary and remediations

As of commit ffb9b64 (more details on the Dr. CI page):


  • 5/5 failures introduced in this PR

🕵️ 5 new failures recognized by patterns

The following CI failures do not appear to be due to upstream breakages:

See GitHub Actions build win-vs2019-cpu-py3 / test (default, 2, 2, windows.4xlarge) (1/5)

Step: "Test" (full log | diagnosis details | 🔁 rerun)

2022-03-15T01:30:06.9499765Z Build left local git repository checkout dirty
2022-03-15T01:30:06.2450582Z + assert_git_not_dirty
2022-03-15T01:30:06.2451104Z + [[ win-vs2019-cpu-py3 != *rocm* ]]
2022-03-15T01:30:06.2451506Z + [[ win-vs2019-cpu-py3 != *xla* ]]
2022-03-15T01:30:06.2519079Z ++ git status --porcelain
2022-03-15T01:30:06.9497520Z + git_status='?? Tensor),'
2022-03-15T01:30:06.9497968Z + [[ -n ?? Tensor), ]]
2022-03-15T01:30:06.9498359Z + echo 'Build left local git repository checkout dirty'
2022-03-15T01:30:06.9498805Z + echo 'git status --porcelain:'
2022-03-15T01:30:06.9499127Z + echo '?? Tensor),'
2022-03-15T01:30:06.9499394Z + exit 1
2022-03-15T01:30:06.9499765Z Build left local git repository checkout dirty
2022-03-15T01:30:06.9500166Z git status --porcelain:
2022-03-15T01:30:06.9500461Z ?? Tensor),
2022-03-15T01:30:06.9500718Z + cleanup
2022-03-15T01:30:06.9500978Z + retcode=1
2022-03-15T01:30:06.9501215Z + set +x
2022-03-15T01:30:06.9528764Z ##[error]Process completed with exit code 1.
2022-03-15T01:30:06.9674023Z ##[group]Run # -ir => recursive include all files in pattern
2022-03-15T01:30:06.9674647Z �[36;1m# -ir => recursive include all files in pattern�[0m
2022-03-15T01:30:06.9675135Z �[36;1m7z a "test-jsons-$Env:FILE_SUFFIX.zip" -ir'!test\*.json'�[0m
2022-03-15T01:30:06.9692295Z shell: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.EXE -command ". '{0}'"

See GitHub Actions build win-vs2019-cpu-py3 / test (default, 1, 2, windows.4xlarge) (2/5)

Step: "Test" (full log | diagnosis details | 🔁 rerun)

2022-03-15T01:31:03.8735397Z Build left local git repository checkout dirty
2022-03-15T01:31:02.9524585Z + assert_git_not_dirty
2022-03-15T01:31:02.9525576Z + [[ win-vs2019-cpu-py3 != *rocm* ]]
2022-03-15T01:31:02.9525987Z + [[ win-vs2019-cpu-py3 != *xla* ]]
2022-03-15T01:31:02.9592648Z ++ git status --porcelain
2022-03-15T01:31:03.8733113Z + git_status='?? Tensor),'
2022-03-15T01:31:03.8733592Z + [[ -n ?? Tensor), ]]
2022-03-15T01:31:03.8733989Z + echo 'Build left local git repository checkout dirty'
2022-03-15T01:31:03.8734455Z + echo 'git status --porcelain:'
2022-03-15T01:31:03.8734773Z + echo '?? Tensor),'
2022-03-15T01:31:03.8735040Z + exit 1
2022-03-15T01:31:03.8735397Z Build left local git repository checkout dirty
2022-03-15T01:31:03.8735855Z git status --porcelain:
2022-03-15T01:31:03.8736155Z ?? Tensor),
2022-03-15T01:31:03.8736409Z + cleanup
2022-03-15T01:31:03.8736671Z + retcode=1
2022-03-15T01:31:03.8736909Z + set +x
2022-03-15T01:31:03.8765988Z ##[error]Process completed with exit code 1.
2022-03-15T01:31:03.9146135Z ##[group]Run # -ir => recursive include all files in pattern
2022-03-15T01:31:03.9146786Z �[36;1m# -ir => recursive include all files in pattern�[0m
2022-03-15T01:31:03.9147265Z �[36;1m7z a "test-jsons-$Env:FILE_SUFFIX.zip" -ir'!test\*.json'�[0m
2022-03-15T01:31:03.9165092Z shell: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.EXE -command ". '{0}'"

See GitHub Actions build win-vs2019-cuda11.3-py3 / test (default, 2, 2, windows.8xlarge.nvidia.gpu) (3/5)

Step: "Test" (full log | diagnosis details | 🔁 rerun)

2022-03-15T01:07:01.7892065Z Build left local git repository checkout dirty
2022-03-15T01:06:57.4584852Z + assert_git_not_dirty
2022-03-15T01:06:57.4585672Z + [[ win-vs2019-cuda11.3-py3 != *rocm* ]]
2022-03-15T01:06:57.4586315Z + [[ win-vs2019-cuda11.3-py3 != *xla* ]]
2022-03-15T01:06:57.4682377Z ++ git status --porcelain
2022-03-15T01:07:01.7888237Z + git_status='?? Tensor),'
2022-03-15T01:07:01.7889221Z + [[ -n ?? Tensor), ]]
2022-03-15T01:07:01.7890134Z + echo 'Build left local git repository checkout dirty'
2022-03-15T01:07:01.7890743Z + echo 'git status --porcelain:'
2022-03-15T01:07:01.7891206Z + echo '?? Tensor),'
2022-03-15T01:07:01.7891561Z + exit 1
2022-03-15T01:07:01.7892065Z Build left local git repository checkout dirty
2022-03-15T01:07:01.7892609Z git status --porcelain:
2022-03-15T01:07:01.7893025Z ?? Tensor),
2022-03-15T01:07:01.7907396Z + cleanup
2022-03-15T01:07:01.7907824Z + retcode=1
2022-03-15T01:07:01.7908181Z + set +x
2022-03-15T01:07:01.7944164Z ##[error]Process completed with exit code 1.
2022-03-15T01:07:01.8528191Z ##[group]Run # -ir => recursive include all files in pattern
2022-03-15T01:07:01.8529048Z �[36;1m# -ir => recursive include all files in pattern�[0m
2022-03-15T01:07:01.8529753Z �[36;1m7z a "test-jsons-$Env:FILE_SUFFIX.zip" -ir'!test\*.json'�[0m
2022-03-15T01:07:01.8553854Z shell: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.EXE -command ". '{0}'"

See GitHub Actions build win-vs2019-cuda11.3-py3 / test (default, 1, 2, windows.8xlarge.nvidia.gpu) (4/5)

Step: "Test" (full log | diagnosis details | 🔁 rerun)

2022-03-15T01:29:40.8754874Z Build left local git repository checkout dirty
2022-03-15T01:29:38.9339852Z Generated XML report: test-reports\python-unittest\test_jit_fuser_legacy\TEST-test_jit_fuser.TestFuser-20220315012938.xml
2022-03-15T01:29:39.7951120Z + assert_git_not_dirty
2022-03-15T01:29:39.7951793Z + [[ win-vs2019-cuda11.3-py3 != *rocm* ]]
2022-03-15T01:29:39.7952412Z + [[ win-vs2019-cuda11.3-py3 != *xla* ]]
2022-03-15T01:29:39.8047717Z ++ git status --porcelain
2022-03-15T01:29:40.8750952Z + git_status='?? Tensor),'
2022-03-15T01:29:40.8751836Z + [[ -n ?? Tensor), ]]
2022-03-15T01:29:40.8752926Z + echo 'Build left local git repository checkout dirty'
2022-03-15T01:29:40.8753681Z + echo 'git status --porcelain:'
2022-03-15T01:29:40.8754152Z + echo '?? Tensor),'
2022-03-15T01:29:40.8754874Z Build left local git repository checkout dirty
2022-03-15T01:29:40.8755457Z git status --porcelain:
2022-03-15T01:29:40.8755876Z + exit 1
2022-03-15T01:29:40.8756229Z + cleanup
2022-03-15T01:29:40.8756597Z + retcode=1
2022-03-15T01:29:40.8756933Z + set +x
2022-03-15T01:29:40.8757282Z ?? Tensor),
2022-03-15T01:29:40.8792552Z ##[error]Process completed with exit code 1.
2022-03-15T01:29:40.9065412Z ##[group]Run # -ir => recursive include all files in pattern
2022-03-15T01:29:40.9066903Z �[36;1m# -ir => recursive include all files in pattern�[0m
2022-03-15T01:29:40.9068287Z �[36;1m7z a "test-jsons-$Env:FILE_SUFFIX.zip" -ir'!test\*.json'�[0m

See GitHub Actions build win-vs2019-cuda11.3-py3 / test (force_on_cpu, 1, 1, windows.4xlarge) (5/5)

Step: "Test" (full log | diagnosis details | 🔁 rerun)

2022-03-15T00:48:52.4361832Z Build left local git repository checkout dirty
2022-03-15T00:48:51.7144887Z + assert_git_not_dirty
2022-03-15T00:48:51.7145356Z + [[ win-vs2019-cuda11.3-py3 != *rocm* ]]
2022-03-15T00:48:51.7145821Z + [[ win-vs2019-cuda11.3-py3 != *xla* ]]
2022-03-15T00:48:51.7213687Z ++ git status --porcelain
2022-03-15T00:48:52.4359432Z + git_status='?? Tensor),'
2022-03-15T00:48:52.4359934Z + [[ -n ?? Tensor), ]]
2022-03-15T00:48:52.4360351Z + echo 'Build left local git repository checkout dirty'
2022-03-15T00:48:52.4360819Z + echo 'git status --porcelain:'
2022-03-15T00:48:52.4361177Z + echo '?? Tensor),'
2022-03-15T00:48:52.4361450Z + exit 1
2022-03-15T00:48:52.4361832Z Build left local git repository checkout dirty
2022-03-15T00:48:52.4362260Z git status --porcelain:
2022-03-15T00:48:52.4362649Z ?? Tensor),
2022-03-15T00:48:52.4362922Z + cleanup
2022-03-15T00:48:52.4363198Z + retcode=1
2022-03-15T00:48:52.4363463Z + set +x
2022-03-15T00:48:52.4395017Z ##[error]Process completed with exit code 1.
2022-03-15T00:48:52.4554090Z ##[group]Run # -ir => recursive include all files in pattern
2022-03-15T00:48:52.4554788Z �[36;1m# -ir => recursive include all files in pattern�[0m
2022-03-15T00:48:52.4555289Z �[36;1m7z a "test-jsons-$Env:FILE_SUFFIX.zip" -ir'!test\*.json'�[0m
2022-03-15T00:48:52.4574167Z shell: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.EXE -command ". '{0}'"

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.

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D33077733

@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Mar 10, 2022
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D33077733

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D33077733

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D33077733

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D33077733

Summary:
Pull Request resolved: pytorch#74069

RFC: pytorch/rfcs#40
In pytorch#69881 we added the ability to generate codegen unboxing source files. Notice that the generated code to register an operator looks like this:
```
    // aten::add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1) -> Tensor
    OperatorGenerator(
        TORCH_SELECTIVE_SCHEMA("aten::add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1) -> Tensor"),
        [](Stack & stack) {
            RECORD_FUNCTION("add", std::vector<c10::IValue>());
            at::unboxing::add_Tensor(stack);
        },
        aliasAnalysisFromSchema()
    ),
```
However, this means we have to parse the schema and get back arguments with default values in static init time. As written in the RFC, there's a more performant option: providing these arguments with default values using codegen, then we don't have to do expensive regex pattern matching in parsing. Here's how it looks like:
```
    // aten::add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1) -> Tensor
    OperatorGenerator(
        "aten::add",
        "Tensor",
        {
            c10::Argument("self", nullptr, c10::nullopt, c10::IValue(c10::nullopt)),
    	    c10::Argument("other", nullptr, c10::nullopt, c10::IValue(c10::nullopt)),
    	    c10::Argument("alpha", nullptr, c10::nullopt, c10::IValue(1))
        },
        {
            c10::Argument("")
        },
        [](Stack & stack) {
            RECORD_FUNCTION("add", std::vector<c10::IValue>());
            at::unboxing::add_Tensor(stack);
        },
        aliasAnalysisFromSchema()
    ),
```

We also added corresponding APIs in `operator.h` to take in the arguments.

Test Plan: Rely on CI

Reviewed By: kimishpatel

Differential Revision: D33077733

fbshipit-source-id: db6fcb3066ba352cb338a018324c02c32d67b941
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D33077733

facebook-github-bot pushed a commit that referenced this pull request Mar 15, 2022
Summary:
Pull Request resolved: #74069

RFC: pytorch/rfcs#40
In #69881 we added the ability to generate codegen unboxing source files. Notice that the generated code to register an operator looks like this:
```
    // aten::add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1) -> Tensor
    OperatorGenerator(
        TORCH_SELECTIVE_SCHEMA("aten::add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1) -> Tensor"),
        [](Stack & stack) {
            RECORD_FUNCTION("add", std::vector<c10::IValue>());
            at::unboxing::add_Tensor(stack);
        },
        aliasAnalysisFromSchema()
    ),
```
However, this means we have to parse the schema and get back arguments with default values in static init time. As written in the RFC, there's a more performant option: providing these arguments with default values using codegen, then we don't have to do expensive regex pattern matching in parsing. Here's how it looks like:
```
    // aten::add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1) -> Tensor
    OperatorGenerator(
        "aten::add",
        "Tensor",
        {
            c10::Argument("self", nullptr, c10::nullopt, c10::IValue(c10::nullopt)),
    	    c10::Argument("other", nullptr, c10::nullopt, c10::IValue(c10::nullopt)),
    	    c10::Argument("alpha", nullptr, c10::nullopt, c10::IValue(1))
        },
        {
            c10::Argument("")
        },
        [](Stack & stack) {
            RECORD_FUNCTION("add", std::vector<c10::IValue>());
            at::unboxing::add_Tensor(stack);
        },
        aliasAnalysisFromSchema()
    ),
```

We also added corresponding APIs in `operator.h` to take in the arguments.

Test Plan: Rely on CI

Reviewed By: kimishpatel

Differential Revision: D33077733

fbshipit-source-id: e7f13a2f162c70d4e506b4f64cdbb7afec39f4e6
@github-actions
Copy link
Contributor

Hey @larryliu0820.
You've committed this PR, but it does not have both a 'release notes: ...' and 'topics: ...' label. Please add one of each to the PR. The 'release notes: ...' label should represent the part of PyTorch that this PR changes (fx, autograd, distributed, etc) and the 'topics: ...' label should represent the kind of PR it is (not user facing, new feature, bug fix, perf improvement, etc). The list of valid labels can be found here for the 'release notes: ...' and here for the 'topics: ...'.
For changes that are 'topic: not user facing' there is no need for a release notes label.

@larryliu0820 larryliu0820 linked an issue Mar 16, 2022 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed fb-exported oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[PyTorch] Lightweight dispatch

2 participants