-
Notifications
You must be signed in to change notification settings - Fork 123
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
Simplify error estimation by removing _EERepl_ and _delta_ #773
Conversation
edda5ac
to
22be703
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #773 +/- ##
==========================================
- Coverage 94.89% 94.83% -0.07%
==========================================
Files 49 49
Lines 7478 7333 -145
==========================================
- Hits 7096 6954 -142
+ Misses 382 379 -3
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
639fafb
to
80052c5
Compare
clang-tidy review says "All clean, LGTM! 👍" |
@grimmmyshini, could you take a look? |
e1b3715
to
dd15512
Compare
clang-tidy review says "All clean, LGTM! 👍" |
1 similar comment
clang-tidy review says "All clean, LGTM! 👍" |
clang-tidy review says "All clean, LGTM! 👍" |
1 similar comment
clang-tidy review says "All clean, LGTM! 👍" |
//CHECK-NEXT: * _d_x; | ||
//CHECK-NEXT: } | ||
//CHECK-NEXT: * _d_y += _d_z; | ||
//CHECK-NEXT: _delta_x += std::abs(* _d_x * _EERepl_x0 * {{.+}}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am making a comment here, but this applies to all the other tests that have been changed similarly.
1.) You cannot get rid of the EERepl vars (at least to my understanding) so easily. In error estimation, we need to "replay" the value of the variable of interest as it was when we started. (Essentially, every variable is a unique instantiation and is never overwritten). For e.g. the following program:
x = x + 1;
x = y;
y = 20 + x;
Essentially means this to the error estimator:
x_1 = x_0 + 1;
x_2 = y_0;
y_1 = 20 + x_2;
Then, the final error estimation is essentially this:
final_error = dx_0 * x_0 + dx_1 * x_1 + dx_2 * x_2 + ...
So, you cannot simply replace the eerepl objects with 'x' because most functions will overwrite values multiple times.
2.) You cannot just get rid of the delta vars as you may require them while printing/logging. Sure, we can change this but it makes it significantly easier for us to identify errors through these names in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1.) You cannot get rid of the EERepl vars...
Since 1.3, we started reusing the original variables (x
and y
) in the reverse sweep. We now restore their values in the reverse sweep. So at every point in the reverse sweep, x
has the same value it had in the corresponding point in the forward sweep, not the last value it was equal to (like it was previously). This is why the error estimation statement has been moved to the top of the enclosing reverse-sweep block (because we want the value of x
after the assignment). Hopefully, I understand your concern correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2.) You cannot just get rid of the delta vars...
Can't we instead rely on custom error evaluation here (getErrorVal
)? I think we can get the same information this way without adding excessive code. Anyway, this seems like something we could discuss in more detail in Slack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
Oh I see! In that case it's fine, you can ignore that comment.
-
Yeah I mean it's probably okay to get rid of it if you see a worthwhile performance boost. I don't have a strong opinion against it.
I have left a comment in the code addressing one of my major concerns with this PR. That comment applies to every test that has been changed. This PR should also be run on the benchmarks we have for the paper. The resulting error values should also be cross-checked because, as this PR stands, I do not think it is correct and should not be merged. |
4673c5d
to
950512b
Compare
clang-tidy review says "All clean, LGTM! 👍" |
1 similar comment
clang-tidy review says "All clean, LGTM! 👍" |
//CHECK-NEXT: * _d_x += _d_m * x; | ||
//CHECK-NEXT: * _d_x += x * _d_m; | ||
//CHECK-NEXT: _d_m = 0; | ||
//CHECK-NEXT: m = clad::pop(_t1); | ||
//CHECK-NEXT: float _r0 = clad::pop(_EERepl_m0); | ||
//CHECK-NEXT: _delta_m += std::abs(_d_m * _r0 * {{.+}}); | ||
//CHECK-NEXT: } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should notice that before this PR, we used _d_m after it was set to 0. This is clearly not intended because we should use the old derivative value. This happens every time we declare a variable inside a loop. On the other hand, moving the error statement to the top solves the problem.
@grimmmyshini @vgvassilev {
double _r57 = clad::pop(_t125);
double _r58 = _d_beta / _r57;
_d_rtrans += _r58;
double _r59 = _d_beta * -clad::pop(_t126) / (_r57 * _r57);
_d_oldrtrans += _r59;
_d_beta = 0; <-- _d_beta is set to 0
double _r60 = clad::pop(_EERepl_beta0);
_delta_beta += clad::getErrorVal(_d_beta, _r60, "beta"); <-- the error is 0
} After the PR: {
_final_error += clad::getErrorVal(_d_beta, beta, "beta"); <-- the old value of _d_beta is used
_d_rtrans += _d_beta / oldrtrans;
double _r1 = _d_beta * -rtrans / (oldrtrans * oldrtrans);
_d_oldrtrans += _r1;
_d_beta = 0;
beta = clad::pop(_t48);
} From what I understand, the new behavior is correct here. You can also see my comment above describing the same in one of the tests. Luckily, this doesn't affect the conclusions drawn in the article. |
clang-tidy review says "All clean, LGTM! 👍" |
@grimmmyshini, ping. |
I see! Well, it's weird that we missed it in the first go but no issue. If you have verified all the error results from the tests, then this PR is ready to go. 👍 |
760e3c2
to
66e00c2
Compare
66e00c2
to
6d32ee5
Compare
clang-tidy review says "All clean, LGTM! 👍" |
@PetroZarytskyi, any chances to increase the testing coverage of this patch? |
I looked into the CodeDev report. At first, I was confused how it was possible that the coverage of every single test either increased or didn't change. Then I realized that I made ErrorEstimator.cpp way smaller and that decreased the average project coverage. This happened because the coverage of ErrorEstimator.cpp is higher than average. So I think making the coverage higher again would involve doing that for lines unrelated to the PR. |
That was my take as well. Thanks for the explanation. Let's move forward. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done! Thank you! We can ignore the codecov as we reduced the code significantly and that's what makes codecov unhappy but makes everybody else happy...
This PR simplifies error estimation by removing variables with prefixes
_EERepl_
and_delta_
. This became possible since we started reusing cloned forward pass variables in the reverse pass. Merging this PR will also unlock #758.Fixes #757.