Skip to content

Conversation

Conarnar
Copy link
Contributor

Summary

We want to minimize the scenarios where ET fails fatally. If we need to check a precondition inside a kernel rather then calling ET_CHECK which internally dispatches to ABORT we should call ET_KERNEL_CHECK which sets an error state and returns.

Test plan

Replaced TestNegScalarWithTensorDies with TestNegScalarWithTensorFails. Before, it would expect an abort when negating a tensor. The new test expects a failure state instead.

The test can be run with test/run_oss_cpp_tests.sh

Copy link

pytorch-bot bot commented Jun 25, 2025

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ No Failures

As of commit bd272f6 with merge base 9c9f665 (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 Jun 25, 2025
@Conarnar
Copy link
Contributor Author

@pytorchbot label "release notes: none"

@pytorch-bot pytorch-bot bot added the release notes: none Do not include this in the release notes label Jun 25, 2025
ET_CHECK_MSG(false, "%zu, %zu", (size_t)a.tag, (size_t)b.tag); \
#define __ET_PRIM_OP_ERROR_IMPL(a, b, context) \
else { \
ET_KERNEL_CHECK(context, false, InvalidType, /* void */); \
Copy link
Contributor

@lucylq lucylq Jun 26, 2025

Choose a reason for hiding this comment

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

Could we use ET_KERNEL_CHECK_MSG to keep the format string/error message?

e.g.

ET_KERNEL_CHECK_MSG(context, false, InvalidType, "%zu, %zu", (size_t)a.tag, (size_t)b.tag); 

// Try to negate a tensor, which should cause a runtime error.
ET_EXPECT_DEATH(getOpsFn("executorch_prim::neg.Scalar")(context_, stack), "");
ET_EXPECT_KERNEL_FAILURE(
context_,
Copy link
Contributor

Choose a reason for hiding this comment

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

Linter failure here - can you try run lintrunner -a?

See: https://github.com/pytorch/executorch/blob/main/CONTRIBUTING.md#lintrunner

@lucylq lucylq requested a review from JacobSzwejbka June 26, 2025 17:22
@Conarnar Conarnar requested a review from lucylq June 26, 2025 21:52
Copy link
Contributor

@lucylq lucylq left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for adding this!

@JacobSzwejbka JacobSzwejbka merged commit a2b620a into pytorch:main Jun 27, 2025
96 checks passed
@Conarnar Conarnar deleted the prim-ops-replace-abort-with-error-code branch June 27, 2025 16:40
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: none Do not include this in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants