Add float scalar input support (#18751)#18751
Add float scalar input support (#18751)#18751digantdesai wants to merge 1 commit intopytorch:mainfrom
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/18751
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ✅ You can merge normally! (2 Unrelated Failures)As of commit b3dce6d with merge base 75ba558 ( BROKEN TRUNK - The following jobs failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
There was a problem hiding this comment.
Pull request overview
Adds Python float scalar input support to the ExecuTorch Python bindings by converting float → double and wrapping it in EValue, addressing runtime failures for exported models that take floating-point scalar parameters (e.g., alpha/beta).
Changes:
- Convert Python
floatinputs toEValue(double)inPyModule::run_methodinput processing. - Convert Python
floatinputs toEValue(double)inPyMethod::set_inputsinput processing.
Comments suppressed due to low confidence (2)
extension/pybindings/pybindings.cpp:815
- The exception message says inputs must be a flat list of tensors, but this code path explicitly supports non-tensor inputs (None/bool/int/float). Consider updating the message to reflect the actually supported scalar types to avoid confusing users when they pass an unsupported input type.
} else {
throw std::runtime_error(
"Unsupported python type " + type_str +
". Ensure that inputs are passed as a flat list of tensors.");
extension/pybindings/pybindings.cpp:1145
- The exception message says inputs must be a flat list of tensors, but this conversion logic supports non-tensor inputs (None/bool/int/float). Consider updating the message to mention the supported scalar types to make debugging unsupported inputs clearer.
} else {
throw std::runtime_error(
"Unsupported python type " + type_str +
". Ensure that inputs are passed as a flat list of tensors.");
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
31f410e to
dbd4966
Compare
Summary: The pybindings code handled bool and int scalar inputs but was missing support for float (Python float → C++ double). This caused failures when running models like Addmm that take float alpha/beta parameters, throwing 'Unsupported python type <class float>'. Added py::isinstance<py::float_> handling to convert Python floats to EValue(double) in both the portable and XNNPACK input processing paths. Differential Revision: D99845426
Summary: Pull Request resolved: pytorch#18751 The pybindings code handled bool and int scalar inputs but was missing support for float (Python float → C++ double). This caused failures when running models like Addmm that take float alpha/beta parameters, throwing 'Unsupported python type <class float>'. Added py::isinstance<py::float_> handling to convert Python floats to EValue(double) in both the portable and XNNPACK input processing paths. Differential Revision: D99845426
dbd4966 to
20d6e88
Compare
|
@digantdesai has exported this pull request. If you are a Meta employee, you can view the originating Diff in D99845426. |
20d6e88 to
3cf840b
Compare
Summary: The pybindings code handled bool and int scalar inputs but was missing support for float (Python float → C++ double). This caused failures when running models like Addmm that take float alpha/beta parameters, throwing 'Unsupported python type <class float>'. Added py::isinstance<py::float_> handling to convert Python floats to EValue(double) in both the portable and XNNPACK input processing paths. Reviewed By: 3l1 Differential Revision: D99845426
Summary: The pybindings code handled bool and int scalar inputs but was missing support for float (Python float → C++ double). This caused failures when running models like Addmm that take float alpha/beta parameters, throwing 'Unsupported python type <class float>'. Added py::isinstance<py::float_> handling to convert Python floats to EValue(double) in both the portable and XNNPACK input processing paths. Reviewed By: 3l1 Differential Revision: D99845426
Summary: Pull Request resolved: pytorch#18751 The pybindings code handled bool and int scalar inputs but was missing support for float (Python float → C++ double). This caused failures when running models like Addmm that take float alpha/beta parameters, throwing 'Unsupported python type <class float>'. Added py::isinstance<py::float_> handling to convert Python floats to EValue(double) in both the portable and XNNPACK input processing paths. Reviewed By: 3l1 Differential Revision: D99845426
3cf840b to
b3dce6d
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (2)
extension/pybindings/pybindings.cpp:815
- The fallback error message says to "Ensure that inputs are passed as a flat list of tensors", but this function now explicitly accepts non-tensor inputs (None/bool/int/float). Consider updating the message to reflect the actual supported scalar types (and that the list must be flat, but not tensor-only), so users aren’t misled when they pass an unsupported scalar/object.
throw std::runtime_error(
"Unsupported python type " + type_str +
". Ensure that inputs are passed as a flat list of tensors.");
extension/pybindings/pybindings.cpp:1145
- The fallback error message says to "Ensure that inputs are passed as a flat list of tensors", but this method now supports non-tensor scalar inputs (None/bool/int/float). Updating the message to mention the supported scalar types (and/or pointing to documentation) would make debugging unsupported inputs easier.
throw std::runtime_error(
"Unsupported python type " + type_str +
". Ensure that inputs are passed as a flat list of tensors.");
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } else if (py::isinstance<py::float_>(python_input)) { | ||
| cpp_inputs.push_back(EValue(py::cast<double>(python_input))); |
There was a problem hiding this comment.
Float scalar inputs are now converted to EValue(double), but there doesn’t appear to be pybindings coverage that exercises a program with a double/float scalar input (existing tests mainly use tensor-only inputs). Adding an end-to-end pybindings test that exports a module taking a float scalar input (e.g., alpha/beta in addmm, or a simple x * alpha) would prevent regressions across both ExecuTorchModule.run_method and ExecuTorchMethod.set_inputs paths.
Summary:
The pybindings code handled bool and int scalar inputs but was missing
support for float (Python float → C++ double). This caused failures when
running models like Addmm that take float alpha/beta parameters, throwing
'Unsupported python type '.
Added py::isinstancepy::float_ handling to convert Python floats to
EValue(double) in both the portable and XNNPACK input processing paths.
Reviewed By: 3l1
Differential Revision: D99845426