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

Turn off debug assertions in benchmark configs; enable strings as steps based on cfg(test) #963

Merged

Conversation

andyleiserson
Copy link
Collaborator

@andyleiserson andyleiserson commented Feb 29, 2024

Usually !debug_assertions => compact-gate, but that is not the case when profiling.

Copy link

codecov bot commented Feb 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.23%. Comparing base (951bff3) to head (beca008).

❗ Current head beca008 differs from pull request most recent head c2cbeec. Consider uploading reports for the commit c2cbeec to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #963   +/-   ##
=======================================
  Coverage   89.23%   89.23%           
=======================================
  Files         158      158           
  Lines       21711    21718    +7     
=======================================
+ Hits        19374    19381    +7     
  Misses       2337     2337           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -6,12 +6,8 @@ members = ["ipa-core", "ipa-macros"]
incremental = true
lto = "thin"

[profile.bench]
debug-assertions = true
Copy link
Collaborator

Choose a reason for hiding this comment

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

iirc we added debug assertions to catch issues related to invariant violations while running the benches. We had a case where oneshot ipa hanged and we couldn't figure out why.

I don't think removing this will cause any issues and we can always enable them manually in command line, just wanted to provide an explanation why it was there in the first place

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If there's a need to have an optimized build with stricter sanity checks, then maybe we should add a dedicated config for that (something like dev-opt)? Or perhaps reconsider the safety / performance tradeoff for the sanity checks that are having escapes, i.e. consider converting to a regular assert rather than a debug assert.

I've actually been mostly using the release config for benchmarking -- removing this bit of config doesn't have much direct impact on what I've been doing, but it does seem to me like the right thing to do. Having to edit Cargo.toml to make the bench config actually produce accurate benchmark results seems confusing.

The other change I had considered making was splitting the PRSS used index tracking to a separate feature flag. I can see how that would make sense if we want to use debug-assertions for "small but non-negligible performance cost" and a separate flag(s) for "very significant performance cost".

Copy link
Collaborator

Choose a reason for hiding this comment

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

yea I think this change makes sense because we want to evaluate the performance. Just wanted to provide an explanation why it was added. It can always be enabled from command line, so I don't think it is an issue

@@ -36,10 +36,10 @@ pub trait StepNarrow<S: Step + ?Sized> {
pub trait Step: AsRef<str> {}

// In test code, allow a string (or string reference) to be used as a `Step`.
#[cfg(any(feature = "test-fixture", debug_assertions))]
#[cfg(feature = "descriptive-gate")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure if this is right. We want descriptive gates to match compact gate structure in production code. This may enable us to use strings inside MPC circuits that then fail to compile with compact-gate enabled. Maybe we just want cfg[test] here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As I understand things (and possibly this can change with @martinthomson's new compact gate implementation), the compact gate supports only the steps that are part of the "production" IPA protocol. So anything that's not the production protocol needs descriptive gate. (Which is counter to my claim in my other comment that bench should work out-of-the-box for benchmarks -- but better to enable just descriptive gate, than descriptive gate plus every debug assertion.)

I agree that we don't want a coverage gap in CI for steps added to the protocol without compact gate support -- but doesn't the "compact gate tests" (cargo test --no-default-features --features "cli web-app real-world-infra test-fixture compact-gate") step in CI protect us from that? Not using a string as a step is necessary but not sufficient for a protocol to work with compact gate -- it also needs to be listed in steps.txt.

Copy link
Collaborator

Choose a reason for hiding this comment

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

is there a strong reason why you want to use strings instead of enums outside of tests? I just feel like it introduces more friction working on the code where you compile everything just fine and rely on CI to catch those issues which delays the feedback loop unnecessarily.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, no good reason. I had been conflating strings as steps with descriptive gate in my head. It's totally reasonable to implement Step for benchmarks.

Your comment prompted me to wonder whether there's a compelling reason we need to support strings as steps at all... I took a quick look at this and it seems like maybe not. The list of places we do (post IPAv2 removal) is relatively short, and a bunch of those places we're narrowing the context unnecessarily, so the narrow can just be removed. Elsewhere we just need to add an enum with #[derive(Step)], which is a lot less work than when it required the enum definition plus a handful of impls for the enum.

Copy link
Collaborator

@akoshelev akoshelev left a comment

Choose a reason for hiding this comment

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

I'd suggest to look again at using test flag to guard against using string steps in prod code, otherwise it is good to go

@andyleiserson
Copy link
Collaborator Author

andyleiserson commented Mar 7, 2024

I pushed a new version that defines real steps in the few places where a string-as-step appeared outside cfg(test).

(This makes the description of the PR, and the first commit, inaccurate.)

* Enable strings as steps based on `cfg(test)` rather than based on
  `cfg(debug_assertions)`.
* Define real `Step` in the arithmetic circuit benchmark and TestWorld.
@andyleiserson andyleiserson changed the title Enable strings as steps based on descriptive-gate feature. Turn off debug assertions in benchmark configs; enable strings as steps based on cfg(test) Mar 7, 2024
@andyleiserson
Copy link
Collaborator Author

Rebased to make the commit message accurate. Code is unchanged.

@andyleiserson andyleiserson merged commit 603cebe into private-attribution:main Mar 7, 2024
10 checks passed
@andyleiserson andyleiserson deleted the debug-assertions branch March 7, 2024 22:46
akoshelev added a commit to akoshelev/raw-ipa that referenced this pull request Mar 15, 2024
PR private-attribution#963 changed the root step name, now our script is failing.

Would be great to add it to CI, but I have high hopes that private-attribution#961 is not
too far ahead.

Tested by manually running this script
akoshelev added a commit that referenced this pull request Mar 15, 2024
PR #963 changed the root step name, now our script is failing.

Would be great to add it to CI, but I have high hopes that #961 is not
too far ahead.

Tested by manually running this script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants