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

Inductor cpp wrapper: fix dtype of ShapeAsConstantBuffer #122297

Closed
wants to merge 3 commits into from

Conversation

chunyuan-w
Copy link
Collaborator

@chunyuan-w chunyuan-w commented Mar 20, 2024

Stack from ghstack (oldest at bottom):

For at::scalar_tensor the default dtype will be float (link to scalar_tensor, link to default dtype) if we don't set the dtype value. However, the input scalar value is not necessarily a float value. With torch::tensor(x), the dtype of the tensor will be decided according to the dtype of the scalar.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @peterbell10 @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @aakhundov @ColinPeppler @amjames @desertfire @chauhang

Copy link

pytorch-bot bot commented Mar 20, 2024

🔗 Helpful Links

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

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

✅ No Failures

As of commit ab42345 with merge base 6502c88 (image):
💚 Looks good so far! There are no failures yet. 💚

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

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler amjames desertfire chauhang

[ghstack-poisoned]
chunyuan-w added a commit that referenced this pull request Mar 21, 2024
ghstack-source-id: e19c495456e5649156745577281628076878e4d9
Pull Request resolved: #122297
@chunyuan-w chunyuan-w marked this pull request as ready for review March 22, 2024 06:29
@chunyuan-w chunyuan-w requested a review from jgong5 March 22, 2024 06:29
test/inductor/test_torchinductor.py Outdated Show resolved Hide resolved
For `at::scalar_tensor` the default dtype will be `float` ([link to scalar_tensor](https://github.com/pytorch/pytorch/blob/0d8e960f74acd359358e0b729c4803d2b71849e5/aten/src/ATen/native/TensorFactories.cpp#L856), [link to default dtype](https://github.com/pytorch/pytorch/blob/0d8e960f74acd359358e0b729c4803d2b71849e5/c10/core/TensorOptions.h#L551)) if we don't set the `dtype` value. However, the input scalar value is not necessarily a `float` value. With `torch::tensor(x)`, the dtype of the tensor will be decided according to the dtype of the scalar.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler amjames desertfire chauhang

[ghstack-poisoned]
chunyuan-w added a commit that referenced this pull request Mar 25, 2024
ghstack-source-id: 42a8a0537bff727c38f82af6e0aebe0707e5e09b
Pull Request resolved: #122297
@chunyuan-w
Copy link
Collaborator Author

@desertfire I just noticed that #118024 changed torch::tensor to at::scalar_tensor. May I know if there's a specific reason for this? I found that with at::scalar_tensor, the scalar type of the tensor might be inconsistent with the scalar value and will cause regression issue of several models in #122292.

@desertfire
Copy link
Contributor

@desertfire I just noticed that #118024 changed torch::tensor to at::scalar_tensor. May I know if there's a specific reason for this? I found that with at::scalar_tensor, the scalar type of the tensor might be inconsistent with the scalar value and will cause regression issue of several models in #122292.

It is related to https://github.com/pytorch/pytorch/pull/118024/files/bba213c151f2c8e7a29635d273a73a6c98d24393#r1463364631. at::scalar_tensor is more accurate in this use case. Is it a dtype propagation problem here?

@chunyuan-w
Copy link
Collaborator Author

@desertfire I just noticed that #118024 changed torch::tensor to at::scalar_tensor. May I know if there's a specific reason for this? I found that with at::scalar_tensor, the scalar type of the tensor might be inconsistent with the scalar value and will cause regression issue of several models in #122292.

It is related to https://github.com/pytorch/pytorch/pull/118024/files/bba213c151f2c8e7a29635d273a73a6c98d24393#r1463364631. at::scalar_tensor is more accurate in this use case. Is it a dtype propagation problem here?

Considering an int scalar value 2, at::scalar_tensor(2) becomes a Float type tensor.
The issues in #122292 is that this scalar value output is later used as a size which requires it to be an int instead of a float.

I tried to get the dtype of the scalar value and pass it to at::scalar_tensor as the dtype input argument during the codegen time but sometimes the scalar value is a Symbol and I failed to find a good way to infer the dtype of this Symbol, while with torch::tensor, the dtype of the output tensor will match the dtype of the scalar input value, so I changed at::scalar_tensor back to torch::tensor in non abi compatible mode. May I know if you have other suggestions for the fix of this issue?

@chunyuan-w
Copy link
Collaborator Author

Hi @desertfire this issue will cause regression against the PyTorch 2.2 release and we're trying to see if it's possible to fix it in 2.3. May I know if you have other suggestions regarding the current fix approach?

@chunyuan-w chunyuan-w added the topic: not user facing topic category label Mar 29, 2024
Copy link
Contributor

@desertfire desertfire left a comment

Choose a reason for hiding this comment

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

ok for the non abi-compatible mode, although we will have to come back to fix once I turned on the abi-compatible mode as default.

@chunyuan-w chunyuan-w added the ciflow/trunk Trigger trunk jobs on your pull request label Mar 31, 2024
@chunyuan-w
Copy link
Collaborator Author

@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

@chunyuan-w
Copy link
Collaborator Author

ok for the non abi-compatible mode, although we will have to come back to fix once I turned on the abi-compatible mode as default.

Oh okay. Btw, when do we plan to turn on the abi-compatible mode as default?

chunyuan-w added a commit to chunyuan-w/pytorch that referenced this pull request Apr 1, 2024
)

For `at::scalar_tensor` the default dtype will be `float` ([link to scalar_tensor](https://github.com/pytorch/pytorch/blob/0d8e960f74acd359358e0b729c4803d2b71849e5/aten/src/ATen/native/TensorFactories.cpp#L856), [link to default dtype](https://github.com/pytorch/pytorch/blob/0d8e960f74acd359358e0b729c4803d2b71849e5/c10/core/TensorOptions.h#L551)) if we don't set the `dtype` value. However, the input scalar value is not necessarily a `float` value. With `torch::tensor(x)`, the dtype of the tensor will be decided according to the dtype of the scalar.

Pull Request resolved: pytorch#122297
Approved by: https://github.com/jgong5, https://github.com/desertfire
@desertfire
Copy link
Contributor

ok for the non abi-compatible mode, although we will have to come back to fix once I turned on the abi-compatible mode as default.

Oh okay. Btw, when do we plan to turn on the abi-compatible mode as default?

We do, once its coverage has reached a reasonable level.

atalman pushed a commit that referenced this pull request Apr 2, 2024
…#122297) (#123064)

For `at::scalar_tensor` the default dtype will be `float` ([link to scalar_tensor](https://github.com/pytorch/pytorch/blob/0d8e960f74acd359358e0b729c4803d2b71849e5/aten/src/ATen/native/TensorFactories.cpp#L856), [link to default dtype](https://github.com/pytorch/pytorch/blob/0d8e960f74acd359358e0b729c4803d2b71849e5/c10/core/TensorOptions.h#L551)) if we don't set the `dtype` value. However, the input scalar value is not necessarily a `float` value. With `torch::tensor(x)`, the dtype of the tensor will be decided according to the dtype of the scalar.

Pull Request resolved: #122297
Approved by: https://github.com/jgong5, https://github.com/desertfire
sanketpurandare pushed a commit to sanketpurandare/pytorch that referenced this pull request Apr 22, 2024
)

For `at::scalar_tensor` the default dtype will be `float` ([link to scalar_tensor](https://github.com/pytorch/pytorch/blob/0d8e960f74acd359358e0b729c4803d2b71849e5/aten/src/ATen/native/TensorFactories.cpp#L856), [link to default dtype](https://github.com/pytorch/pytorch/blob/0d8e960f74acd359358e0b729c4803d2b71849e5/c10/core/TensorOptions.h#L551)) if we don't set the `dtype` value. However, the input scalar value is not necessarily a `float` value. With `torch::tensor(x)`, the dtype of the tensor will be decided according to the dtype of the scalar.

Pull Request resolved: pytorch#122297
Approved by: https://github.com/jgong5, https://github.com/desertfire
@github-actions github-actions bot deleted the gh/chunyuan-w/3/head branch May 2, 2024 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants