Skip to content

Conversation

@tangleintel
Copy link
Contributor

@tangleintel tangleintel commented Jun 22, 2022

Support python callable object's parameters' unpacking feature in torch.jit.trace()

Python support passing a tuple or dictionary to a callable object and automatically unpacking the parameter to make the function get the right value. For tuple, the elements' order will result in the correctness of arguments' matching while dictionary use the arguments' name for matching.
In torch.jit.trace(), we support passing a tuple or a single tensor as our example_inputs to trigger the graph construction. Passing a tuple meanings the tuple elements' order should strictly align with the parameters' order declared in the forward() function. But in some scenarios, it's not that easy or just can't manually make such a tuple to trace a model when we already have off-the-shelf dataset which consists of dictionaries. Take the below 2 examples as illustration case:

  1. In the first example, say, if we have a dataset and each of the data is a dictionary such as data = {'key1':value1, 'key2':value2, 'key3':value3}, we will fetch the data from dataloader and extract its value and make a tuple as the example_inputs passing to jit.trace(). But if the forward() method of our module which we want to trace has such declaration:
    def forward(self, key2=value2, key3=value3, key1=value1):
    Thus, we need manually reorder the value in the tuple and check if they can match to the declaration. This case is just not friendly to users but we can still trace the module by reordering.

  2. In the second example, say, we still have the same dataset, but the forward() method's declaration as below:
    def forward(self, key2=value2, key3=value3, key4=None, key5=None, key1=value1, key6=value6):
    This time, we can't just passing a tuple by simply reordering the value, cause we missing key4 and key5 in the dataset, and we can't passing a tuple like example_inputs = (value2, value3, None, None, value1) since tracer doesn't support None type when the corresponding missing arguments' default value are None. For this situation, it's even not traceable.

These cases are not fabricated deliberately. We met these issue in Hugging Face's text-classification tasks with some datasets(such as GLUE tasks), and we expect it's a common issue.

So, we propose to make torch.jit.trace() support python function's kwargs unpacking feature with dictionary to address these issues. If we can support unpacking parameter with dictionary, then we can automatically reorder the value by argument's name information inside the trace, and thus we can serialize the dictionary and assemble a traceable stack for the graph.

Some concerns about the implementation

  1. The real data's key's name may not align with the forward() method's arguments' name, so we should highlight this point to make the user assure the example_inputs's key name must align with the name of the argument in the documentation if we would support this feature. When the user do not provide the expected name, we should explicitly report the error message.
  2. To make a traceable stack, we don't follow the forward() arguments' order in python code. Thus the graph's input parameters' order will be different with the forward() method in python code such as:
    graph(%self : __torch__.module.___torch_mangle_n.Mymodule, %key1 : type1, %key2 : type2, %key3 : type3)
    other than:
    graph(%self : __torch__.module.___torch_mangle_n.Mymodule, %key2 : type2, %key3 : type3, %key1 : type1)
    If somewhere else have the assumption that the IR's input parameters' order should strictly align with the order we defined in the python code, then our implementation may be infeasible. Such as the below situation:
    If we have a module which will be traced with forward() method declaration as below:
    def forward(self, key2, key3=value3, key4=value4, key5=value5, key1=value1, key6=value6): (with key2 as positional argumrnt)
    When we trace the module, we pass it with dictionary:
    traced_module = torch.jit.trace(origin_moduel, dict_input, strict=False)
    where dict_input is a python dictionary such as {'key1':value1, 'key2':value2, 'key3':value3}
    But when we use the traced module, we pass it with positional arguments with the assumption its order should be aligned with what the python forward() code declared:
    traced_module(inputs[1], key1=inputs[0], key3=inputs[2])
    where inputs[1]'s value is actually correspond to key2 as we declared in the forward(). In this situation, the invoke of traced module will fail cause we reordered the arguments with key1 as the graph's first argument.
    Possible solution 1:
    The first solution we came up with which will add some attributes in FunctionSchema to represent if the arguments' order have been changed before tracing and record the original arguments' order. These attributes can be set before tracing when we knew the example_inputs parameter is a dictionary, and are used the function createStackForSchema() to judge if we should recover the original order when we construct the stack.
    Cons:
    To support this feature and fix this issue, we shouldn't modify any basic data structure or class such as FunctionSchema .
    Possible solution 1:
    We specify in the documentation of torch.jit.trace() if the user would use dictionary as their example_inputs, then the must use the traced module with dictionary too.
    Cons:
    This restrict the flexibility of this API.

Note

  1. This PR will make some UT introduced in 39601 fail, which I think should be classified as unpacking a tuple containing a single dictionary element in our solution.
  2. I think there is ambiguity since currently we only specify passing a tuple or a single Tensor as our example_inputs parameter in torch.jit.trace()'s documentation, but it seems we can still passing a dictionary.

@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Jun 22, 2022

🔗 Helpful links

❌ 6 New Failures, 1 Flaky Failures

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

Expand to see more

🕵️ 6 new failures recognized by patterns

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

See GitHub Actions build pull / linux-bionic-py3_7-clang8-xla / test (xla, 1, 1, linux.2xlarge) (1/6)

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

2022-07-17T06:15:25.6355129Z ##[error]Process completed with exit code 1.
2022-07-17T06:15:25.6124850Z �[0m�[37m�[40mnpm�[0m �[0m�[31m�[40mERR!�[0m �[0m�[35mtypeerror�[0m     at pickVersionFromRegistryDocument (/usr/share/npm/lib/fetch-package-metadata.js:134:20)
2022-07-17T06:15:25.6127416Z �[0m�[37m�[40mnpm�[0m �[0m�[31m�[40mERR!�[0m �[0m�[35mtypeerror�[0m     at /usr/share/npm/node_modules/iferr/index.js:13:50
2022-07-17T06:15:25.6129066Z �[0m�[37m�[40mnpm�[0m �[0m�[31m�[40mERR!�[0m �[0m�[35mtypeerror�[0m This is an error with npm itself. Please report this error at:
2022-07-17T06:15:25.6130554Z �[0m�[37m�[40mnpm�[0m �[0m�[31m�[40mERR!�[0m �[0m�[35mtypeerror�[0m     <http://github.com/npm/npm/issues>
2022-07-17T06:15:25.6255604Z �[0m
2022-07-17T06:15:25.6256948Z �[37m�[40mnpm�[0m �[0m�[31m�[40mERR!�[0m�[35m�[0m Please include the following file with any support request:
2022-07-17T06:15:25.6258769Z �[0m�[37m�[40mnpm�[0m �[0m�[31m�[40mERR!�[0m�[35m�[0m     /var/lib/jenkins/workspace/npm-debug.log
2022-07-17T06:15:25.6317152Z �[0m+ cleanup
2022-07-17T06:15:25.6317438Z + retcode=1
2022-07-17T06:15:25.6317687Z + set +x
2022-07-17T06:15:25.6355129Z ##[error]Process completed with exit code 1.
2022-07-17T06:15:25.6413620Z Prepare all required actions
2022-07-17T06:15:25.6413910Z Getting action download info
2022-07-17T06:15:25.7657951Z ##[group]Run ./.github/actions/get-workflow-job-id
2022-07-17T06:15:25.7658167Z with:
2022-07-17T06:15:25.7658563Z   github-token: ***
2022-07-17T06:15:25.7658720Z env:
2022-07-17T06:15:25.7658963Z   GIT_DEFAULT_BRANCH: master
2022-07-17T06:15:25.7659148Z ##[endgroup]
2022-07-17T06:15:25.7684587Z ##[group]Run nick-fields/retry@71062288b76e2b6214ebde0e673ce0de1755740a
2022-07-17T06:15:25.7684819Z with:

See GitHub Actions build Lint / lintrunner (2/6)

Step: "Run lintrunner on all files" (full log | diagnosis details | 🔁 rerun)

2022-07-17T05:26:53.8656558Z ##[error]Name "gh_post_comment" is not defined
Run `lintrunner -a` to apply this patch.
2022-07-17T05:26:53.8648911Z ##[error]This line has trailing spaces; please remove them.
2022-07-17T05:26:53.8650508Z ##[warning]blank line contains whitespace
See https://www.flake8rules.com/rules/W293.html
2022-07-17T05:26:53.8652061Z ##[warning]missing whitespace after ':'
See https://www.flake8rules.com/rules/E231.html
2022-07-17T05:26:53.8653637Z ##[warning]missing whitespace after ':'
See https://www.flake8rules.com/rules/E231.html
2022-07-17T05:26:53.8655188Z ##[warning]missing whitespace after ':'
See https://www.flake8rules.com/rules/E231.html
2022-07-17T05:26:53.8656558Z ##[error]Name "gh_post_comment" is not defined 
2022-07-17T05:26:53.8658144Z ##[warning]line too long (144 > 120 characters)
See https://github.com/PyCQA/flake8-bugbear#list-of-warnings
2022-07-17T05:26:53.8702582Z Post job cleanup.
2022-07-17T05:26:53.8743042Z Post job cleanup.
2022-07-17T05:26:53.9788656Z [command]/usr/bin/git version
2022-07-17T05:26:53.9837871Z git version 2.37.0
2022-07-17T05:26:53.9882259Z Temporarily overriding HOME='/home/runner/actions-runner/_work/_temp/6ed0c11d-e034-475a-9d99-51bd9f86a9c6' before making global git config changes
2022-07-17T05:26:53.9882862Z Adding repository directory to the temporary git global config as a safe directory
2022-07-17T05:26:53.9887607Z [command]/usr/bin/git config --global --add safe.directory /home/runner/actions-runner/_work/pytorch/pytorch
2022-07-17T05:26:53.9930804Z [command]/usr/bin/git config --local --name-only --get-regexp core\.sshCommand

See GitHub Actions build pull / linux-xenial-py3-clang5-mobile-custom-build-static / build (3/6)

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

2022-07-17T05:25:33.9856237Z ##[error]Process completed with exit code 1.
2022-07-17T05:25:33.9815455Z Non-cacheable compilations            0
2022-07-17T05:25:33.9815851Z Non-cacheable calls                   0
2022-07-17T05:25:33.9816310Z Non-compilation calls                 0
2022-07-17T05:25:33.9816675Z Unsupported compiler calls            0
2022-07-17T05:25:33.9816892Z Average cache write               0.000 s
2022-07-17T05:25:33.9817105Z Average cache read miss           0.000 s
2022-07-17T05:25:33.9817306Z Average cache read hit            0.000 s
2022-07-17T05:25:33.9817525Z Failed distributed compilations       0
2022-07-17T05:25:33.9818084Z Cache location                  S3, bucket: Bucket(name=ossci-compiler-cache-circleci-v2, base_url=http://ossci-compiler-cache-circleci-v2.s3.amazonaws.com/)
2022-07-17T05:25:33.9818570Z /var/lib/jenkins/workspace/.jenkins/pytorch/common.sh: line 66: JOB_BASE_NAME: unbound variable
2022-07-17T05:25:33.9856237Z ##[error]Process completed with exit code 1.
2022-07-17T05:25:33.9890929Z Prepare all required actions
2022-07-17T05:25:33.9911657Z ##[group]Run ./.github/actions/teardown-linux
2022-07-17T05:25:33.9911891Z with:
2022-07-17T05:25:33.9912298Z ##[endgroup]
2022-07-17T05:25:33.9928878Z ##[group]Run .github/scripts/wait_for_ssh_to_drain.sh
2022-07-17T05:25:33.9929178Z �[36;1m.github/scripts/wait_for_ssh_to_drain.sh�[0m
2022-07-17T05:25:33.9949734Z shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
2022-07-17T05:25:33.9949983Z ##[endgroup]
2022-07-17T05:25:34.0005967Z Holding runner for 2 hours until all ssh sessions have logged out
2022-07-17T05:25:34.0065423Z ##[group]Run # ignore expansion of "docker ps -q" since it could be empty

See GitHub Actions build pull / linux-focal-py3.7-gcc7-mobile-lightweight-dispatch-build / build (4/6)

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

2022-07-17T05:25:17.4623061Z ##[error]Process completed with exit code 1.
2022-07-17T05:25:17.4590507Z Non-cacheable compilations            0
2022-07-17T05:25:17.4590778Z Non-cacheable calls                   0
2022-07-17T05:25:17.4591103Z Non-compilation calls                 0
2022-07-17T05:25:17.4591341Z Unsupported compiler calls            0
2022-07-17T05:25:17.4591552Z Average cache write               0.000 s
2022-07-17T05:25:17.4591750Z Average cache read miss           0.000 s
2022-07-17T05:25:17.4591954Z Average cache read hit            0.000 s
2022-07-17T05:25:17.4592169Z Failed distributed compilations       0
2022-07-17T05:25:17.4592845Z Cache location                  S3, bucket: Bucket(name=ossci-compiler-cache-circleci-v2, base_url=http://ossci-compiler-cache-circleci-v2.s3.amazonaws.com/)
2022-07-17T05:25:17.4593320Z /var/lib/jenkins/workspace/.jenkins/pytorch/common.sh: line 66: JOB_BASE_NAME: unbound variable
2022-07-17T05:25:17.4623061Z ##[error]Process completed with exit code 1.
2022-07-17T05:25:17.4649831Z Prepare all required actions
2022-07-17T05:25:17.4668992Z ##[group]Run ./.github/actions/teardown-linux
2022-07-17T05:25:17.4669196Z with:
2022-07-17T05:25:17.4669342Z ##[endgroup]
2022-07-17T05:25:17.4684562Z ##[group]Run .github/scripts/wait_for_ssh_to_drain.sh
2022-07-17T05:25:17.4684818Z �[36;1m.github/scripts/wait_for_ssh_to_drain.sh�[0m
2022-07-17T05:25:17.4696262Z shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
2022-07-17T05:25:17.4696489Z ##[endgroup]
2022-07-17T05:25:17.4733713Z Holding runner for 2 hours until all ssh sessions have logged out
2022-07-17T05:25:17.4841211Z ##[group]Run # ignore expansion of "docker ps -q" since it could be empty

See GitHub Actions build pull / linux-xenial-py3-clang5-mobile-build / build (5/6)

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

2022-07-17T05:24:52.6549186Z ##[error]Process completed with exit code 1.
2022-07-17T05:24:52.6517625Z Non-cacheable compilations            0
2022-07-17T05:24:52.6518057Z Non-cacheable calls                   0
2022-07-17T05:24:52.6518512Z Non-compilation calls                 0
2022-07-17T05:24:52.6518925Z Unsupported compiler calls            0
2022-07-17T05:24:52.6519327Z Average cache write               0.000 s
2022-07-17T05:24:52.6520195Z Average cache read miss           0.000 s
2022-07-17T05:24:52.6520535Z Average cache read hit            0.000 s
2022-07-17T05:24:52.6520843Z Failed distributed compilations       0
2022-07-17T05:24:52.6521492Z Cache location                  S3, bucket: Bucket(name=ossci-compiler-cache-circleci-v2, base_url=http://ossci-compiler-cache-circleci-v2.s3.amazonaws.com/)
2022-07-17T05:24:52.6522052Z /var/lib/jenkins/workspace/.jenkins/pytorch/common.sh: line 66: JOB_BASE_NAME: unbound variable
2022-07-17T05:24:52.6549186Z ##[error]Process completed with exit code 1.
2022-07-17T05:24:52.6573623Z Prepare all required actions
2022-07-17T05:24:52.6592800Z ##[group]Run ./.github/actions/teardown-linux
2022-07-17T05:24:52.6593005Z with:
2022-07-17T05:24:52.6593154Z ##[endgroup]
2022-07-17T05:24:52.6608185Z ##[group]Run .github/scripts/wait_for_ssh_to_drain.sh
2022-07-17T05:24:52.6608444Z �[36;1m.github/scripts/wait_for_ssh_to_drain.sh�[0m
2022-07-17T05:24:52.6619660Z shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
2022-07-17T05:24:52.6619890Z ##[endgroup]
2022-07-17T05:24:52.6655718Z Holding runner for 2 hours until all ssh sessions have logged out
2022-07-17T05:24:52.6692788Z ##[group]Run # ignore expansion of "docker ps -q" since it could be empty

See GitHub Actions build pull / linux-focal-py3.7-clang10-onnx / build (6/6)

Step: "Pull docker image" (full log | diagnosis details | 🔁 rerun)

2022-07-17T05:27:54.0326415Z �[91m./configure: line 6876: /usr/bin/file: No such file or directory
2022-07-17T05:27:53.9277244Z checking for dlltool... no
2022-07-17T05:27:53.9279418Z checking how to associate runtime and link libraries... printf %s\n
2022-07-17T05:27:53.9284430Z checking for ar... ar
2022-07-17T05:27:53.9494735Z checking for archiver @FILE support... @
2022-07-17T05:27:53.9499112Z checking for strip... strip
2022-07-17T05:27:53.9503845Z checking for ranlib... ranlib
2022-07-17T05:27:54.0121870Z checking command to parse /usr/bin/nm -B output from gcc object... ok
2022-07-17T05:27:54.0134388Z checking for sysroot... no
2022-07-17T05:27:54.0173251Z checking for a working dd... /usr/bin/dd
2022-07-17T05:27:54.0211898Z checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
2022-07-17T05:27:54.0326415Z �[91m./configure: line 6876: /usr/bin/file: No such file or directory
2022-07-17T05:27:54.0339884Z �[0mchecking for mt... no
2022-07-17T05:27:54.0374954Z checking if : is a manifest tool... no
2022-07-17T05:27:54.0555500Z checking how to run the C preprocessor... gcc -E
2022-07-17T05:27:54.1419409Z checking for ANSI C header files... yes
2022-07-17T05:27:54.1611866Z checking for sys/types.h... yes
2022-07-17T05:27:54.1829137Z checking for sys/stat.h... yes
2022-07-17T05:27:54.2046997Z checking for stdlib.h... yes
2022-07-17T05:27:54.2279122Z checking for string.h... yes
2022-07-17T05:27:54.2509863Z checking for memory.h... yes
2022-07-17T05:27:54.2738206Z checking for strings.h... yes

❄️ 1 failure tentatively classified as flaky

but reruns have not yet been triggered to confirm:

See GitHub Actions build pull / linux-focal-rocm5.1-py3.7 / build (1/1)

Step: "Calculate docker image" (full log | diagnosis details | 🔁 rerun) ❄️

2022-07-17T05:34:57.3150977Z E: Failed to fetch...64/Packages 404 Not Found [IP: 13.82.220.49 443]
2022-07-17T05:34:56.3285112Z Ign:7 https://repo.radeon.com/amdgpu//ubuntu focal/main all Packages
2022-07-17T05:34:56.3305918Z Ign:4 https://repo.radeon.com/amdgpu//ubuntu focal/main amd64 Packages
2022-07-17T05:34:56.3326069Z Ign:7 https://repo.radeon.com/amdgpu//ubuntu focal/main all Packages
2022-07-17T05:34:56.3353439Z Err:4 https://repo.radeon.com/amdgpu//ubuntu focal/main amd64 Packages
2022-07-17T05:34:56.3353733Z   404  Not Found [IP: 13.82.220.49 443]
2022-07-17T05:34:56.3374642Z Ign:7 https://repo.radeon.com/amdgpu//ubuntu focal/main all Packages
2022-07-17T05:34:56.3433915Z Get:10 http://repo.radeon.com/rocm/apt/5.1 ubuntu/main amd64 Packages [26.3 kB]
2022-07-17T05:34:56.6020777Z Fetched 29.0 kB in 0s (85.9 kB/s)
2022-07-17T05:34:57.3006300Z Reading package lists...
2022-07-17T05:34:57.3150035Z �[91mW: The repository 'https://repo.radeon.com/amdgpu//ubuntu focal Release' does not have a Release file.
2022-07-17T05:34:57.3150977Z E: Failed to fetch https://repo.radeon.com/amdgpu//ubuntu/dists/focal/main/binary-amd64/Packages  404  Not Found [IP: 13.82.220.49 443]
2022-07-17T05:34:57.3151619Z E: Some index files failed to download. They have been ignored, or old ones used instead.
2022-07-17T05:34:57.7079258Z The command '/bin/sh -c bash ./install_rocm.sh' returned a non-zero code: 100
2022-07-17T05:34:57.7097338Z �[0m
2022-07-17T05:34:57.7101983Z ##[error]Process completed with exit code 100.
2022-07-17T05:34:57.7198868Z Prepare all required actions
2022-07-17T05:34:57.7199106Z Getting action download info
2022-07-17T05:34:57.9111714Z Download action repository 'nick-fields/retry@71062288b76e2b6214ebde0e673ce0de1755740a' (SHA:71062288b76e2b6214ebde0e673ce0de1755740a)
2022-07-17T05:34:58.0182613Z ##[group]Run ./.github/actions/get-workflow-job-id
2022-07-17T05:34:58.0182917Z with:
2022-07-17T05:34:58.0183229Z   github-token: ***

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 facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Jun 22, 2022
@tangleintel tangleintel marked this pull request as draft June 22, 2022 23:59
@davidberard98
Copy link
Contributor

feel free to add me as a reviewer when this is ready

@tangleintel
Copy link
Contributor Author

feel free to add me as a reviewer when this is ready

Hi, @davidberard98
Thanks for your replay. Currently we are under internal review for this PR. We will complete the description of the problem and list some limitation for current implementation, and we will add some unit test to demonstrate the usage of this feature.
We are hoping the suggestions and feedbacks from you. Pls, should I add anyone else related this problem as reviewers?

albanD and others added 22 commits July 11, 2022 14:02
Fixes pytorch#80983

Also fix a small bug uncovered by the new test where creating memory_view for 0-sized inputs is not valid and is now skipped

Pull Request resolved: pytorch#81105
Approved by: https://github.com/ezyang
Summary:
Fixed formatting using clang-format:

```clang-format -style=file cumsum.cpp```

Test Plan: Compile time change only.  Test not needed.

Reviewed By: kirklandsign

Differential Revision: D37703962

Pull Request resolved: pytorch#81107
Approved by: https://github.com/kirklandsign
I don't think there's a way to avoid functions returning undefined tensors as outputs, so codegen will have to detect them before calling _set_fw_grad. Alternatively, we can just make calling _set_fw_grad with undefined self a no-op, but I'm biasing toward keeping _set_fw_grad more strict in case it is called in other areas.

Fixes pytorch#81111
Pull Request resolved: pytorch#81114
Approved by: https://github.com/albanD
Fixes the buggy `set_requires_cuda_init` introduced in pytorch#80788.

Pull Request resolved: pytorch#81183
Approved by: https://github.com/ezyang
Issues like https://github.com/pytorch/pytorch/runs/7271166135?check_suite_focus=true shouldn't happen!

This used to not pop up with @swang392's OG implementation, but now that the script returns None, we should add an if.

Pull Request resolved: pytorch#81226
Approved by: https://github.com/seemethere, https://github.com/swang392, https://github.com/malfet
Adds a push trigger for the docker-builds workflow so that docker images
will be re-built when changes that affect docker-builds get pushed

Signed-off-by: Eli Uriegas <eliuriegas@fb.com>
Pull Request resolved: pytorch#81228
Approved by: https://github.com/malfet
disable `backwards_compat` test config b/c its broken by pytorch#81160
reenable when fixed
Pull Request resolved: pytorch#81246
Approved by: https://github.com/malfet
I also filed  while creating this PR.

This PR...

**Filed issues**

- pytorch#79818
- pytorch#80154

**prims**

- Fixes prims.squeeze when called with an unsorted list of dimensions
- Removes the clone prim

**refs**
- adds contiguous
- adds expand
- updates clone to call empty_like and copy_to
- updates empty to accept a memory format
- updates empty_like to accept a memory_format

**utils**
- adds helper functions for working with memory formats and channels last tensors, in particular

**tests**

- removes unused clamp sample input functions (mooted by clamp's new reference inputs)
- extends the reference inputs for clone to include different memory formats
- creates reference inputs for contiguous
- xfails operators that depend on clone (including clone) on `test_python_ref` (see issues)
Pull Request resolved: pytorch#79820
Approved by: https://github.com/ngimel
…sed version registration call (pytorch#81131)

Summary:
Added registration call to make pytorch runtime aware of `inference_wrapper_run_flat_out` functionality. Added fused version of op which will enable out variants when [OptimizeGraph pass](https://fburl.com/code/lsagnmge) is made.

Next: need to add variadic version of fused and unfused op.

Reviewed By: tgalkovskyi

Differential Revision: D37139204

Pull Request resolved: pytorch#81131
Approved by: https://github.com/tenpercent, https://github.com/qxy11
This reverts commit cc31260.

Reverted pytorch#74727 on behalf of https://github.com/mehtanirav due to Breaking multiple internals builds and tests
Previously we had a hack for tree_flatten not supporting
torch.return_types. That was fixed a while ago
(pytorch#74624) so we can delete the
hack.

Test Plan:
- wait for tests
Pull Request resolved: pytorch#81057
Approved by: https://github.com/kshitij12345, https://github.com/ezyang
…ept Callable (pytorch#81059)

Maybe niche, but for one-off debugging purposes, I want a variant of
check_backward_formula that accepts a callable rather than an OpInfo.
This is because when debugging, I try to create a repro that does not
involve OpInfos because OpInfos are difficult to deal with (they have
a lot of sample inputs, I may want to test my own sample inputs without
creating a new OpInfo, etc).

This PR refactors check_backward_formula so that it accepts a Callable
instead of an OpInfo. Example usage:

```
import torch
from torch.testing._internal.composite_compliance import check_backward_formula

x = torch.tensor([[1., 1.], [1., 0.]], requires_grad=True)
args = (x, 1)

check_backward_formula_callable(torch.prod, args, {})
```

Test Plan:
- run existing tests
Pull Request resolved: pytorch#81059
Approved by: https://github.com/kshitij12345, https://github.com/ezyang
…81060)

Composite compliance is supposed to check if a composite function
calls .item()
([ref](https://github.com/pytorch/pytorch/blob/39db8b3823b8db82396cb979105a83e5e137a02f/torch/testing/_internal/composite_compliance.py#L135-L138)).
This PR fixes that and adds some more documentation.

Why do we need this check? The original motivations are that Tensor subclasses
may not support .item calls (e.g. vmap and ProxyTensor).
There is no way for these subclasses to meaningfully override the .item() calls
in composite functions that exist inside the PyTorch framework without raising
an error* so we should aim to rewrite composite operations to not call .item().

*We're open to other solutions, this is just the one we decided on when we
wrote composite compliance testing and these tests help us keep track of the
failing functionality.

Test Plan:
- wait for tests
Pull Request resolved: pytorch#81060
Approved by: https://github.com/ezyang
…ubclass (pytorch#80734)

- Added overloads to is_mutable method in FunctionSchema to tell whether an argument at index is mutable or an argument with name is mutable.
- Created SchemaInfo subclass of FunctionSchema with constructors from FunctionSchema and from const char* signature.
- Tested is_mutable method overloads in new test_schema_info.cpp file.

**Note that this pr is used to set up SchemaInfo. Implementation for SchemaInfo will be addressed in later commits**

Differential Revision: [D37651384](https://our.internmc.facebook.com/intern/diff/D37651384)
Pull Request resolved: pytorch#80734
Approved by: https://github.com/davidberard98
This reworks [80257](pytorch#80257) a bit to use ufmt:

* ufmt https://ufmt.omnilib.dev/en/stable/ unifies both black and usort to automatically format the file in the "most Pythonic" way
* Also make a demo run for all files in `tools/linter/**/*.py`

Pull Request resolved: pytorch#81157
Approved by: https://github.com/suo
…ccept Callable (pytorch#81239)

Like pytorch#81059; this PR addresses
the review comments.

Test Plan:
- run tests
Pull Request resolved: pytorch#81239
Approved by: https://github.com/ezyang
…ps (pytorch#81142)

This PR:
- Adds ref for relu6 and makes its OpInfo a UnaryUfuncInfo
- Correct hardshrink ref when lambd < 0 and when inputs are nan
- Corrected nan behavior vectorized implementation of hardshrink (fixes pytorch#81138)
- Make OpInfos for {hard,soft}shrink, hardtanh UnaryUfuncInfos and add error_inputs for softshrink

Pull Request resolved: pytorch#81142
Approved by: https://github.com/Lezcano, https://github.com/ngimel, https://github.com/mruberry
@tangleintel tangleintel deleted the support_dict_for_jit_trace branch July 18, 2022 03:05
@tangleintel tangleintel restored the support_dict_for_jit_trace branch July 18, 2022 03:08
@tangleintel tangleintel deleted the support_dict_for_jit_trace branch July 18, 2022 03:18
@tangleintel tangleintel restored the support_dict_for_jit_trace branch July 18, 2022 03:29
@tangleintel
Copy link
Contributor Author

Close this one & create 81623

@IvanYashchuk IvanYashchuk removed their request for review July 19, 2022 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed oncall: jit Add this issue/PR to JIT oncall triage queue open source

Projects

None yet

Development

Successfully merging this pull request may close these issues.