Skip to content
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

[MPS] Fix binary ops between int32 tensor with int64 scalar #80220

Closed
wants to merge 4 commits into from

Conversation

malfet
Copy link
Contributor

@malfet malfet commented Jun 24, 2022

For some reason, tensor op scalar does not follow the normal binary promotion rules
So cast output tensor to expected type if needed
It seems that one should have casted input tensors to expected output tensor type, but it does not really work for boolean binary ops, so...
Add output tensor type/shape to cached graph key
Extend TestMPS. test_add_scalars to test for this regression

Fixes #79835

@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Jun 24, 2022

🔗 Helpful links

❌ 1 New Failures

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

Expand to see more
  • 1/1 failures introduced in this PR

🕵️ 1 new failure recognized by patterns

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

See GitHub Actions build pull / linux-docs / build-docs (cpp) (1/1)

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

2022-06-25T03:57:02.3493039Z ##[error]Process completed with exit code 137.
2022-06-25T03:51:43.8869962Z �[01mwriting output... �[39;49;00m[ 90%] �[32mapi/structat_1_1native_1_1_convolution_descriptor .. api/structtorch_1_1enumtype_1_1k_conv_transpose2_d�[39;49;00m
2022-06-25T03:51:57.9925687Z �[01mwriting output... �[39;49;00m[ 92%] �[32mapi/structtorch_1_1enumtype_1_1k_conv_transpose3_d .. api/structtorch_1_1nn_1_1_huber_loss_impl�[39;49;00m
2022-06-25T03:52:13.5104074Z �[01mwriting output... �[39;49;00m[ 93%] �[32mapi/structtorch_1_1nn_1_1_huber_loss_options .. api/structtorch_1_1nn_1_1functional_1_1_multihead_attention_forward_func_options�[39;49;00m
2022-06-25T03:52:20.4672357Z �[01mwriting output... �[39;49;00m[ 95%] �[32mapi/structtorch_1_1nn_1_1functional_1_1_normalize_func_options .. api/typedef_namespacetorch_1_1nn_1_1functional_1a8318be8a4bab733f842c57a3d54ee3dc�[39;49;00m
2022-06-25T03:52:24.4783854Z �[01mwriting output... �[39;49;00m[ 96%] �[32mapi/typedef_namespacetorch_1_1nn_1_1functional_1a872abe58e376dc403b3bea4259d4d2b5 .. api/typedef_namespacetorch_1_1nn_1afecfb211f39a66e9ed2c0c18d556375f�[39;49;00m
2022-06-25T03:52:35.3250664Z �[01mwriting output... �[39;49;00m[ 98%] �[32mapi/typedef_namespacetorch_1_1python_1_1detail_1a9808c29bfe27f974414c895b4ff37f2f .. api/variable_namespacetorch_1ae4963b260c95c4e846fa7538f1c63638�[39;49;00m
2022-06-25T03:52:37.2403543Z �[01mwriting output... �[39;49;00m[100%] �[32mapi/variable_namespacetorch_1aeaf16f038962bbc7c4a0f57696fa3fb1 .. notes/versioning�[39;49;00m
2022-06-25T03:52:37.2403970Z 
2022-06-25T03:52:37.2482317Z �[01mwaiting for workers...�[39;49;00m
2022-06-25T03:57:02.3038945Z /home/ec2-user/actions-runner/_work/_temp/9858733c-cb33-445a-ad48-9bc369035e45.sh: line 27: 20863 Killed                  docker exec -t "${container_name}" bash -c "sudo chown -R jenkins . && pip install dist/*.whl && ./.circleci/scripts/${DOCS_TYPE}_doc_push_script.sh"
2022-06-25T03:57:02.3493039Z ##[error]Process completed with exit code 137.
2022-06-25T03:57:02.3723783Z Prepare all required actions
2022-06-25T03:57:02.3784601Z ##[group]Run ./.github/actions/chown-workspace
2022-06-25T03:57:02.3784832Z ##[endgroup]
2022-06-25T03:57:02.4354941Z ##[group]Run docker run --rm -v "$(pwd)":/v -w /v "${ALPINE_IMAGE}" chown -R "$(id -u):$(id -g)" .
2022-06-25T03:57:02.4355409Z �[36;1mdocker run --rm -v "$(pwd)":/v -w /v "${ALPINE_IMAGE}" chown -R "$(id -u):$(id -g)" .�[0m
2022-06-25T03:57:02.4967880Z shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
2022-06-25T03:57:02.4968187Z env:
2022-06-25T03:57:02.4968517Z   ALPINE_IMAGE: 308535385114.dkr.ecr.us-east-1.amazonaws.com/tool/alpine
2022-06-25T03:57:02.4968851Z ##[endgroup]
2022-06-25T03:57:10.7621749Z Post job cleanup.

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.

@malfet
Copy link
Contributor Author

malfet commented Jun 24, 2022

Added test as well, and reworked the logic

@malfet malfet assigned albanD and unassigned albanD Jun 24, 2022
@malfet malfet requested a review from albanD June 24, 2022 14:47
@malfet malfet added the ciflow/trunk Trigger trunk jobs on your pull request label Jun 24, 2022
@malfet
Copy link
Contributor Author

malfet commented Jun 24, 2022

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

@pytorchbot successfully started a merge job. Check the current status here

@github-actions
Copy link

Hey @malfet.
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.

@malfet
Copy link
Contributor Author

malfet commented Jun 24, 2022

@pytorchbot revert -m "Did not push the final version of commit" -c weird

@pytorchmergebot
Copy link
Collaborator

@pytorchbot successfully started a revert job. Check the current status here

@pytorchmergebot
Copy link
Collaborator

@malfet your PR has been successfully reverted.

pytorchmergebot added a commit that referenced this pull request Jun 24, 2022
…80220)"

This reverts commit a6556ef.

Reverted #80220 on behalf of https://github.com/malfet due to Did not push the final version of commit
@malfet malfet reopened this Jun 24, 2022
@malfet malfet force-pushed the malfet/mps-fix-binary-ops branch from 8806a13 to a6dbe78 Compare June 24, 2022 22:35
For some reason, tensor .op. scalar does not follow the normal binary promotion rules
So instead of common type, cast arguments to output tensor's scalar type

Fixes #79835

Pull Request resolved: #80220
Approved by: https://github.com/albanD
@malfet malfet force-pushed the malfet/mps-fix-binary-ops branch from a6dbe78 to c62630f Compare June 25, 2022 00:22
@malfet malfet added the topic: bug fixes topic category label Jun 25, 2022
@malfet malfet added module: mps Related to Apple Metal Performance Shaders framework release notes: mps Release notes category and removed module: mps Related to Apple Metal Performance Shaders framework labels Jun 25, 2022
@malfet
Copy link
Contributor Author

malfet commented Jun 25, 2022

@pytorchbot merge -f

@pytorchmergebot
Copy link
Collaborator

@pytorchbot successfully started a merge job. Check the current status here

facebook-github-bot pushed a commit that referenced this pull request Jun 27, 2022
…80220)

Summary:
For some reason, tensor *op* scalar does not follow the normal binary promotion rules
So cast output tensor to expected type if needed
It seems that one should have casted input tensors to expected output tensor type, but it does not really work for boolean binary ops, so...
Add output tensor type/shape to cached graph key
Extend `TestMPS. test_add_scalars` to test for this regression

Fixes #79835

Pull Request resolved: #80220
Approved by: https://github.com/albanD

Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/06f874e276f585d643881f5a2078445b9faa0d65

Reviewed By: atalman

Differential Revision: D37455737

Pulled By: malfet

fbshipit-source-id: 1e617b33018fb968b90bc50e1f384f503b620527
@malfet malfet removed Merged Reverted topic: bug fixes topic category release notes: mps Release notes category labels Jun 28, 2022
@malfet malfet added this to the 1.12.1 milestone Jun 30, 2022
@atalman atalman removed this from the 1.12.1 milestone Jul 8, 2022
kulinseth pushed a commit to kulinseth/pytorch that referenced this pull request Jul 9, 2022
…80220)

For some reason, tensor *op* scalar does not follow the normal binary promotion rules
So cast output tensor to expected type if needed
It seems that one should have casted input tensors to expected output tensor type, but it does not really work for boolean binary ops, so...
Add output tensor type/shape to cached graph key
Extend `TestMPS. test_add_scalars` to test for this regression

Fixes pytorch#79835

Pull Request resolved: pytorch#80220
Approved by: https://github.com/albanD
@malfet malfet deleted the malfet/mps-fix-binary-ops branch July 17, 2022 18:10
atalman pushed a commit to atalman/pytorch that referenced this pull request Jul 22, 2022
…80220)

For some reason, tensor *op* scalar does not follow the normal binary promotion rules
So cast output tensor to expected type if needed
It seems that one should have casted input tensors to expected output tensor type, but it does not really work for boolean binary ops, so...
Add output tensor type/shape to cached graph key
Extend `TestMPS. test_add_scalars` to test for this regression

Fixes pytorch#79835

Pull Request resolved: pytorch#80220
Approved by: https://github.com/albanD
atalman added a commit that referenced this pull request Jul 25, 2022
* MPS: Fixes (#78930)

Cast integer to float in UnaryOps
Add tensor dtype in key generation
Enable FP16 scalars and use placeholder for alpha tensor in add/sum ops

Fixes #ISSUE_NUMBER

Pull Request resolved: #78930
Approved by: https://github.com/albanD

* MPS: Binary cast fix by proper type promotion and remove spurious copy warning (#79185)

Fixes #78019, #78020
Fixes #79185
Pull Request resolved: #79185
Approved by: https://github.com/albanD, https://github.com/razarmehr

* MPS: add exponential op (#79188)

Add exponential distribution

Fixes #ISSUE_NUMBER

Pull Request resolved: #79188
Approved by: https://github.com/razarmehr, https://github.com/albanD

* [MPS] Delete unused vars from OperationUtils.mm

Pull Request resolved: #79514

Approved by: https://github.com/kulinseth, https://github.com/albanD

* [MPS] Fix getDefaultGenerator and copy_kernel_mps

Returning reference to stack memory is really bad

Pull Request resolved: #79515

Approved by: https://github.com/albanD

* [MPS][BE]Do not use `new/delete[]` in `chainViewOperation`

`std::array` will do just fine

Pull Request resolved: #79516

Approved by: https://github.com/albanD

* [MPS] Support stride of stride

Fixes #79181

Pull Request resolved: #79521

Approved by: https://github.com/kulinseth

* MPS: TopK raise an error if K>16 (#79677)

* Error out in TopK when k>16.
* Add a test case too.

Fixes #78915

Pull Request resolved: #79677
Approved by: https://github.com/albanD

* [MPS]: Add fix for squeezed input axes handling in BCE loss (#79676)

Fixes #79527

Pull Request resolved: #79676
Approved by: https://github.com/razarmehr, https://github.com/albanD

* MPS: Add amax and amin Ops with tests  (#79682)

* Add amax and amin with tests

Fixes #ISSUE_NUMBER

Pull Request resolved: #79682
Approved by: https://github.com/albanD

* [MPS] Fix torch.uint8 support (#80049)

`ScalarType.Byte` should be cast to `MPSDataTypeUInt8`
And support for `torch.int8` as well as test those conversions in `TestMPS.test_to`

Fixes #80006

Pull Request resolved: #80049
Approved by: https://github.com/albanD

* [MPS] Fix binary ops between int32 tensor with int64 scalar (#80220)

For some reason, tensor *op* scalar does not follow the normal binary promotion rules
So cast output tensor to expected type if needed
It seems that one should have casted input tensors to expected output tensor type, but it does not really work for boolean binary ops, so...
Add output tensor type/shape to cached graph key
Extend `TestMPS. test_add_scalars` to test for this regression

Fixes #79835

Pull Request resolved: #80220
Approved by: https://github.com/albanD

* [MPS] Add equal operator (#80195)

Which is, in essence is composite of `eq`->`all`->`item`
`native/mps/operators/Equal.cpp` is an almost verbatim copy of `native/cuda/Equal.cpp`

Fix codegen by generating MPSFunctions headers

Pull Request resolved: #80195
Approved by: https://github.com/albanD

* [MPS] add `aten::normal.Tensor_float` `aten::normal.float_Tensor` `aten::normal.Tensor_Tensor` (#80297)

Fixes #ISSUE_NUMBER

Pull Request resolved: #80297
Approved by: https://github.com/albanD, https://github.com/kulinseth

* [MPS] Add flip (#80214)

Fixes #ISSUE_NUMBER

Pull Request resolved: #80214
Approved by: https://github.com/DenisVieriu97, https://github.com/albanD

* [MPS] Add logical ops (#80216)

This PR adds `logical_not`, `logical_and`, `logical_or`, `logical_xor`.
Pull Request resolved: #80216
Approved by: https://github.com/albanD, https://github.com/kulinseth

* [MPS] Add glu (#79866)

Adds mps op for `aten::glu.out`.

Pull Request resolved: #79866
Approved by: https://github.com/kulinseth, https://github.com/albanD

* [MPS] Fix std/var cache issue (#80502)

Use `getTensorsStringKey` which has tensor shape info added as part of the key to prevent cache lookup issue when the shape of input tensor is changed.

Fixes #80499

Pull Request resolved: #80502
Approved by: https://github.com/malfet, https://github.com/kulinseth

* Add scatter support for view operations (#79939)

* Add scatter support for view operations; #78074, #78886, #79672
* Update test_slicing_replace_column to properly test different sizes
* Handle in-place changes for binary ops; add new testcase
* Add new view ops testing scatter; add MPSDebugConfig.h config file for debugging purposes
* Merge gatherViewTensor and scatterViewTensor into a generic function
* Add scatter on demand in scatterViewOperation instead of caching it into a generic graph
* Create separate graphs for scatter and gather;
* Create scatter graph at scatter time

Fixes #ISSUE_NUMBER

Pull Request resolved: #79939
Approved by: https://github.com/razarmehr

* MPS: Fix handling of 1D tensors in linear backward (#80759)

Fixes ##79784

Pull Request resolved: #80759
Approved by: https://github.com/ezyang

* [MPS] Move the View ops to a separate file and reduce the number of graphs created (#80491)

This is dependent on the PR to go in first: #79939

Remove the data_ptr from the View Graph key which reduces the number of
graphs created significantly.

Don't wait when copying from MPS to MPS tensors

Pull Request resolved: #80491
Approved by: https://github.com/malfet

* [MPS] Add softplus backward (#79873)

Fixes #ISSUE_NUMBER

Pull Request resolved: #79873
Approved by: https://github.com/malfet

* [MPS] Add argmin (#80828)

This PR

1. adds argmin
2. refactors `reduction_type` in `ReduceOps.mm` with enum.

Co-authored by Kulin Seth <kulinseth@gmail.com>
Pull Request resolved: #80828
Approved by: https://github.com/malfet

* [MPS] Fix LSTM batch_first output transposed (#80597)

The output of LSTM with `batch_first` should be transposed back to batch first format.

Fixes #80306

Pull Request resolved: #80597
Approved by: https://github.com/kulinseth

* [MPS][BE] Introduce MPSUnaryCachedGraph (#81033)

I.e. CachedGraph that has input and output tensors
Also, add `MPSGraphCache::LookUpAs` template, which combines LookUp with
static_cast to target type

Pull Request resolved: #81033
Approved by: https://github.com/kulinseth

* [MPS] Add test consistency from OpInfo based tests from PR 78504 (#79532)

Pull Request resolved: #79532
Approved by: https://github.com/albanD, https://github.com/malfet

* [MPS] Add huber loss (#80163)

Fixes #ISSUE_NUMBER

Pull Request resolved: #80163
Approved by: https://github.com/kulinseth, https://github.com/malfet

* Remove two tests dependent on the MPS serialization checkin.

* Fix lint error (FLAKE8) F401

* Remove the serialization test from test_mps as its support is not there in 1.12.1.

Co-authored-by: Kulin Seth <kulinseth@gmail.com>
Co-authored-by: Nikita Shulga <nikita.shulga@gmail.com>
Co-authored-by: Kulin Seth <kulin_seth@apple.com>
Co-authored-by: Abhishek Pathak <abhipathak97@gmail.com>
Co-authored-by: Nikita Shulga <nshulga@fb.com>
Co-authored-by: qqaatw <qqaatw@gmail.com>
Co-authored-by: Ramin Azarmehr <razarmehr@apple.com>
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 cla signed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scalar add returns incorrect results for int32 MPS array
5 participants