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

elementwise_util: don't cast the result of compute_fun back to the common type #9385

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

swolchok
Copy link
Contributor

The compute function might return an entirely different type. For
example, if we were applying a trigonometric function like acos to an
input of type bool expecting an output of type float, we would get bad
results because acos(0) = 1.57, but casting through bool would
truncate that to 1.

Note that we don't need the pair of ET_CHECK_MSG I removed because we
already check tensor dtypes on entry to the elementwise util
functions; the checks were inconvenient because we now call
get_store_common_to_tensor_fn without the actual common type.

[ghstack-poisoned]
[ghstack-poisoned]
Copy link

pytorch-bot bot commented Mar 19, 2025

🔗 Helpful Links

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

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

❌ 1 Cancelled Job

As of commit f1c5429 with merge base 644b7dd (image):

CANCELLED JOB - The following job was cancelled. Please retry:

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

@swolchok
Copy link
Contributor Author

hmm, don't understand why unittest / macos is failing on CI but not locally. maybe PR is out of sync? rebasing

[ghstack-poisoned]
[ghstack-poisoned]
swolchok added a commit that referenced this pull request Mar 19, 2025
…mmon type

The compute function might return an entirely different type. For
example, if we were applying a trigonometric function like acos to an
input of type bool expecting an output of type float, we would get bad
results because acos(0) = 1.57, but casting through bool would
truncate that to 1.

Note that we don't need the pair of ET_CHECK_MSG I removed because we
already check tensor dtypes on entry to the elementwise util
functions; the checks were inconvenient because we now call
get_store_common_to_tensor_fn without the actual common type.

ghstack-source-id: cfcbe8b142102d2b028c44229c109fda63491b0d
ghstack-comment-id: 2735017325
Pull Request resolved: #9385
[ghstack-poisoned]
@swolchok
Copy link
Contributor Author

hmm, don't understand why unittest / macos is failing on CI but not locally. maybe PR is out of sync? rebasing

There was an ASAN failure, which is now fixed.

@swolchok swolchok requested a review from kimishpatel March 19, 2025 21:31
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@swolchok
Copy link
Contributor Author

need to add a regression test for acos case as well


template <typename CTYPE_COMMON, typename Op, typename... Args>
using op_call_result =
std::invoke_result_t<Op, ignore_first_yield_second<Args, CTYPE_COMMON>...>;
Copy link
Contributor

Choose a reason for hiding this comment

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

why do you need ignore_first_yield_second? why not use CTYPE_COMMON directly in here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because I need the ... to produce sizeof...(Args) instances of CTYPE_COMMON. If you have a suggestion for a better way to do that I would love to hear it; this is the best I could do.

@swolchok swolchok marked this pull request as draft March 26, 2025 21:19
@swolchok
Copy link
Contributor Author

this breaks mul(int8, int8, out=long). I think we need to add a notion of "float ops" to the elementwise_util functions corresponding to TensorIterator's notion of "float ops", which essentially just means "set promote_integer_inputs_to_float to true".

@swolchok
Copy link
Contributor Author

this diff has been removed from the stack it thinks it's in

Base automatically changed from gh/swolchok/379/head to main April 2, 2025 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants