Repository navigation
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #488 +/- ##
=======================================
Coverage 68.94% 68.94%
=======================================
Files 15 15
Lines 1755 1755
=======================================
Hits 1210 1210
Misses 545 545 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
(moved this reply into a review comment) |
brews
left a comment
There was a problem hiding this comment.
Hey @C1587S, my immediate reaction is to consider that if the test is sensitive enough to be influenced by this kind of low level implementation choice, might this be more of a code smell? It might also mean that the tests are "wound too tight", so to speak.
For example, rather than asserting for exact matches as part of the test, instead use np.testing.assert_allclose and have it check for a precision that is practically significant, but not so tight that it gets caught up on hardware differences.
It might also be that you're asking for a level of precision that float point math cannot legitimately sustain and we need to find an alternative way of doing things.
Part of the purpose of tests is to check that you get consistent and replaceable behavior across multiple machines and users. Are we sure you're not masking a deeper methods problem by forcing this?
It also feels like something that is a pain to maintain. It makes it hard for users to clone the repo on their local machines and run tests to ensure things just run correctly. We really should avoid this as much as possible. Smells like trouble.
Again, this is my immediate reaction. I don't know the problem space as well as you so please feel free to tell me if I'm off.
On hosts where numpy 1.26.4 dispatches its AVX512 code paths, np.power runs through the SVML bundled with numpy and the float32 certainty equivalents differ from the AVX2 path in the last bits. Damages are the difference of two nearly equal certainty equivalents, so this reaches 5.9e-2 relative on the smallest damage values and 3.0e-5 on values at or above the median. With the old tolerances six test functions fail on such hosts, 30 parametrizations: equity points, coefficients and fit for all seven discount types, and risk-aversion points, coefficients and fit for the three gwr types. Each of the six asserts now sets rtol and atol to ten times the largest deviation from the fixture measured on an Intel Xeon Gold 6448Y with AVX512 dispatch on, pooled over the seven discount types and rounded up to one significant figure: rtol from values at or above the median, atol from values below it. Each atol is stated in the test as a fraction of the median absolute value it applies to. test rtol atol atol / median test_equity_points 3e-4 2e7 7.6e-4 test_risk_aversion_points 6e-4 1e7 5.1e-4 test_equity_coefficients 5e-6 8e5 9.6e-6 to 1.2e-5 test_risk_aversion_coefficients 9e-6 1e6 2.0e-5 to 2.8e-5 test_equity_fit 3e-5 2e8 4.1e-5 test_risk_aversion_fit 7e-5 4e8 1.1e-4 Both coefficients tests end up with a tighter rtol than the xarray default of 1e-5 they used before. Nothing in src/ changes.
ubuntu-latest now resolves to ubuntu-26.04. Pinning the image keeps the toolchain the same from one run to the next. The host CPU is still assigned by the runner pool; the test tolerances no longer depend on it.
1f7a0fb to
82a25b1
Compare
|
hi @brews! agreed, and thanks for pushing back on it!!! I went and measured it, and two things came out. The tolerance turned out to be the problem rather than the comparison, since the points tests already allowed rtol 1e-4 and their atol of 1e-4 means nothing against damages of order 1e10. And the noise floor is real in the damage function points, since damages is the difference of two nearly equal certainty equivalents read from float32 stores, so it does show up there, but it doesn't reach the SCC. The regression attenuates it, so the SCC tests pass on an AVX512 host under the tolerance they already had. So what I did was modify the tests instead. Each tolerance comes from the measured spread, ten times the deviation, one pair per test, measured with numpy's AVX512 path on and off on the same node. Two of the six end up stricter than before. The env variable and the guard step are gone, so the only workflow change left is pinning the runner image, which i think is worth having on its own. The six tests pass three times in a row on an AVX512 node with nothing set in the env PS: I retitled the PR and rewrote the description to match the new approach, and force-pushed the branch rather than stacking revert commits on top, so your line comments will show up as outdated. |
|
I'm not totally following this, but why is |
Six tests in
tests/test_equity.pyandtests/test_risk_aversion.pyfail on CI hosts with AVX512 and pass on the rest. numpy 1.26.4 sendsnp.powerto its bundled SVML kernels on those hosts and to a generic path elsewhere, and the two differ in the last bit. Damages are the difference of two nearly equal certainty equivalents read from float32 stores, so that last bit gets amplified. 30 parametrizations fail.This sets the tolerances from a measurement of that spread, instead of pinning numpy's dispatch path in CI. Nothing in
src/changes.Measured on an Intel Xeon Gold 6448Y with numpy 1.26.4, over every recipe, discount type and product the tests compare, once with AVX512 dispatch on and once with
NPY_DISABLE_CPU_FEATURESset on the same host as the control.rtol is ten times the largest relative deviation, atol ten times the largest absolute one on values below the median, both rounded up. Each atol works out to a small share of the median it is compared against, from 7.6e-4 of the median damage down to 9.6e-6 of the median coefficient. The old
atol=1e-4meant nothing against damages of order 1e10. Both coefficients tests end up with a tighter rtol than they had.The spread does not reach the SCC. On the same host the SCC moves by 5.8e-7 with dispatch on and 6.6e-12 with it off, while the points it is built from move by up to 3.0e-5.
test_equity_sccandtest_risk_sccpass there with their existing rtol of 1e-4.Both workflow jobs move from
ubuntu-latest, which now resolves to 26.04, toubuntu-24.04, so the toolchain stays the same between runs.With the old tolerances the six assertions applied to that host's outputs fail on exactly the 30 parametrizations that fail in CI. With the new ones none fail, and both pass on the control.
On an Intel Xeon Gold 6448Y, with numpy dispatching through AVX512_ICL and no environment variables set, both test modules pass three times in a row, 72 tests each.