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

Add support for the default float, int and bool types for executorch::runtime::etensor::Scalar to` method #10040

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ahbpp
Copy link

@ahbpp ahbpp commented Apr 10, 2025

Summary

  • Added support for float, ::executorch::runtime::etensor::Half, and ::executorch::runtime::etensor::BFloat16 for to method of ExecuTorch's Scalar
  • Replaced separate to methods with to##name() macros (same as PyTorch c10::Scalar).
  • Added constructor for float type.
  • This PR does not cover uint16/32/64_t types (since 'uint64_t' can overflow' int64_t', separate logic is required) and does not include executorch::runtime::etensor::complex.
  • I haven’t added overflow checks before because I'm not sure if I can copy (c10 dir in executorch) c10::overflows.h from torch. (I will add an overflow check after I figure out what is the right way to do this :))

I need a bit further guidance related to adding support for more complex types and handling overflows:

  1. I'm thinking about whether it’s better to create a separate TypeCast.h for typecasting (similar to PyTorch c10). Would this be better than having the casting code in the Scalar class?
  2. Can I copy and use c10::overflows.h from pytorch c10 to handle overflows?

Fixes #9500

P.S. If you have any concerns about this PR, please let me know, I will fix :)

Test plan

I added tests in' runtime/core/portable_type/test/scalar_test.cpp' for additional types types.

ahbpp and others added 2 commits April 9, 2025 01:32
…::runtime::etensor::Scalar` to` method

* move all default float, int and bool to ET_FORALL_FLOAT_INT_BOOL_TYPES macros
* replace all to with `to##name` macros
* add additional checks in `ScalarTest.ToScalarType` test
Copy link

pytorch-bot bot commented Apr 10, 2025

🔗 Helpful Links

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

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

✅ No Failures

As of commit 59e213e with merge base 4bd7798 (image):
💚 Looks good so far! There are no failures yet. 💚

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

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 10, 2025
@ahbpp
Copy link
Author

ahbpp commented Apr 10, 2025

@pytorchbot label "Release notes: runtime"

Copy link

pytorch-bot bot commented Apr 10, 2025

Didn't find following labels among repository labels: Release notes: runtime

@ahbpp
Copy link
Author

ahbpp commented Apr 10, 2025

@pytorchbot label "release notes: runtime"

@pytorch-bot pytorch-bot bot added the release notes: runtime Changes related to the core runtime which loads the program methods, initializes delegates, and runs label Apr 10, 2025
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. release notes: runtime Changes related to the core runtime which loads the program methods, initializes delegates, and runs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ExecuTorch Scalar to() supports fewer types than c10::Scalar, breaking source compatibility
2 participants