Skip to content

Add regression test for graceful error for wrong number of activities #139591

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vayunbiyani
Copy link
Contributor

@vayunbiyani vayunbiyani commented Apr 9, 2025

Fix for: #139590

  • Added graceful error message instead of an ICE
  • Blessed tests

Edit: one of @ZuseZ4 's commits fixed it. This PR just adds the test case to avoid regressions.

@rustbot
Copy link
Collaborator

rustbot commented Apr 9, 2025

r? @BoxyUwU

rustbot has assigned @BoxyUwU.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 9, 2025
@vayunbiyani
Copy link
Contributor Author

r? @oli-obk
cc: @ZuseZ4

@rustbot rustbot assigned oli-obk and unassigned BoxyUwU Apr 9, 2025
@ZuseZ4
Copy link
Member

ZuseZ4 commented Apr 9, 2025

You'll need to rebase it, since there are some conflicts.
Also, we already have an error message for that which you can use, AutoDiffInvalidNumberActivities so let's not duplicate it. In general, can you please add a testcase which is fixed by this change? Adding your zulip example should work.

@vayunbiyani
Copy link
Contributor Author

@ZuseZ4 My solution is actually flawed as the error is already detected earlier here but your comment says that // This is not the right signature, but we can continue parsing. Could you please help me understand why we'd want to do so?

@ZuseZ4
Copy link
Member

ZuseZ4 commented Apr 9, 2025

The high-level idea is that if we have multiple functions and multiple autodiff macros per function, then we want to continue parsing all other macros and functions, even if one is incorrect. This way we can report errors in multiple autodiff macros in a single cargo invocation.

To achieve that we only use emit_err instead of emit_fatal_err. Also, if we have to return a dummy function from an incorrect autodiff macro, then we just return any (parsing) body and stop caring if it follows enzyme/autodiff rules. After all we'll never reach our llvm backend if there is any autodiff error in the frontend.

Where possible, we also try to find multiple bugs in a broken autodiff macro, even beyond the first error.
So for example, if someone writes `#[autodiff(df, Reversee, Aactive)], then we want to point out that the Mode is unrecognized (has an extra e) and that the Activity is unrecognized (has an extra a). So we really work hard on not raising a fatal error.

That's also what's motivating the comment. If you look at your example, this is an incorrect application (missing one activity).

#[autodiff(d_ignore, Forward, Dual, Dual)]
fn ignore_one_arg(x: i32, _y: i32) -> i32 {
    x
}

So we don't try to rewrite the function header of d_ignore at all, we just copy the one from ignore_one_arg. This would completely break at the enzyme/llvm backend, but as said we'll never reach it since we raised an error, so that's fine. We just want to finish parsing.

#[rustc_autodiff]
#[inline(never)]
fn ignore_one_arg(x: i32, _y: i32) -> i32 {
    x
}
#[rustc_autodiff(Forward, 1, Dual, Dual)]
#[inline(never)]
fn d_ignore(x: i32, _y: i32) -> i32 {
    unsafe {
        asm!("NOP", options(pure, nomem));
    };
    ::core::hint::black_box(());
    ::core::hint::black_box(<i32>::default())
}

@vayunbiyani vayunbiyani force-pushed the graceful_error branch 2 times, most recently from dee4857 to 78e17e7 Compare April 10, 2025 19:16
@vayunbiyani
Copy link
Contributor Author

@rustbot ready

@vayunbiyani vayunbiyani marked this pull request as ready for review April 10, 2025 20:34
@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 10, 2025
@rustbot

This comment has been minimized.

@rustbot rustbot removed has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 10, 2025
@ZuseZ4
Copy link
Member

ZuseZ4 commented Apr 10, 2025

@vayunbiyani This doesn't include any changes to autodiff files, only to tests. Did you forget to include the fix?

@vayunbiyani
Copy link
Contributor Author

Yes, it's intentional. One of your commits handled this(I'm not exactly sure at what point tho) leading to no ICEs for the updated case.

@vayunbiyani
Copy link
Contributor Author

@rustbot ready

@rustbot
Copy link
Collaborator

rustbot commented Apr 12, 2025

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@rust-log-analyzer

This comment has been minimized.

@ZuseZ4
Copy link
Member

ZuseZ4 commented Apr 12, 2025

oh interesting. Sure, then it's fine to just add the test to make sure we don't regress.
Can you undo the lock file change, though? That was likely just some CI noise, rerunning it should fix it.

For the future, just force-pushing the same code with a different hash should trigger a CI re-run if you have unrelated failures. We try to have a reliable CI, but every once in a while random failures happen, just due to the size of the rust CI.

@vayunbiyani
Copy link
Contributor Author

Hmm, I didn't change anything in the lock file. The commit just reverted to the cargo in the master since it was showing up as a change

@ZuseZ4
Copy link
Member

ZuseZ4 commented Apr 13, 2025

Can you squash your two commits, instead of adding and undoing the changes in the cargo.lock?

Blessed tests
Comment on lines +34 to +39
#[autodiff(df5, Forward, Dual, Dual)]
fn f5(x: f32, y: f32) -> f32 {
//~^^ ERROR expected 3 activities, but found 2
x + y
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Please avoid such churn, if you want to insert it here in between and keep the naming scheme use something like f4_1

@oli-obk oli-obk changed the title Graceful error for wrong number of activities Add regression test for graceful error for wrong number of activities Apr 15, 2025
@oli-obk oli-obk added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants