-
Notifications
You must be signed in to change notification settings - Fork 184
[testing, CI] fix coverage statistics issue caused by test_common.py
tracer patching
#2237
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
Conversation
This reverts commit 5c602da.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Flags with carried forward coverage won't be shown. Click here to find out more. |
/intelci: run |
test_common.py
tracer patchingtest_common.py
tracer patching
test_common.py
tracer patchingtest_common.py
tracer patching
/intelci: run |
Is 1.2% increase what you would expect? In general, where does the other missing coverage come from? |
@ethanglaser good question! Its mainly 2 aspects: 1) The utils/validation.py tests coverage was not being recorded, 2) centralized testing (especially test_patching.py) was not being recorded, which covers all other methods of estimators (especially |
sklearnex/tests/test_common.py
Outdated
try: | ||
est = PATCHED_MODELS[estimator]() | ||
except KeyError: | ||
est = SPECIAL_INSTANCES[estimator] |
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.
try: | |
est = PATCHED_MODELS[estimator]() | |
except KeyError: | |
est = SPECIAL_INSTANCES[estimator] | |
estimator = (SPECIAL_INSTANCES | PATCHED_MODELS)[estimator_name] |
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 had to revert this, because SPECIAL_INSTANCES is a special dictionary of estimators which uses sklearn's clone (in order to guarantee that there is no hysteresis between uses of the instance). And the patched models are classes. To be honest, the difference is tech debt that I introduced at the beginning of 2024, as I was trying to unify the centralized testing. Hindsight I would structure things like SPECIAL_INSTANCES.
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.
Then I'd go with PATCHED_MODELS.get(estimator_name, None) or SPECIAL_INSTANCES[estimator_name]
. I don't want to waste 4 lines on something that doesn't contribute to the function logic.
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.
Took me some time to figure this out, turns out the ensemble algorithms of sklearn break the suggestion construction.
from sklearn.ensemble import RandomForestRegressor
RandomForestRegressor() or 3
will yield:
AttributeError: 'RandomForestRegressor' object has no attribute 'estimators_'. Did you mean: 'estimator'?
which means I cannot use this in this case, its definitely doing something with the or operator and checking if its an iterable. Its not something on our side, but comes from sklearn conformance. It comes from sklearn for whatever reason defining a __len__
for ensemble estimators thats only valid after fitting.
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.
Sorry for sending you down a rabbit hole. I would still prefer a different implementation because I think try/except
is a bit of an overkill
estimator = PATCHED_MODELS[estimator_name] if estimator_name in PATCHED_MODELS else SPECIAL_INSTANCES[estimator_name]
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.
no apologies necessary, it showed i hadnt handled a failure case properly and would lead to pytest hanging, which would have been a nightmare to debug. now it should error 'gracefully' in CI (testing it now)
Co-authored-by: Andreas Huber <[email protected]>
Co-authored-by: Andreas Huber <[email protected]>
test if new failure system works on last commit |
/intelci: run |
Description
Python code coverage has been introduced in #2222 and #2225. Some code, while properly covered with tests, was showing incorrect coverage. It was discovered that the tracing used in
test_common.py
interferes with the tracing collected by pytest-cov. Any tests alphabetically aftertest_common.py
have been neglected in codecov and by coverage.py. Correcting this can be done by tracing the estimators in a separate process and passing the data back to the pytest-cov parent process.This has been implemented using python multiprocessing due to the time overhead of loading sklearnex for each estimator and method. The process persists for the period of all
test_common.py
tests as a daemon process. The test passing/xfail/etc rate has been verified to match to main.No performance metrics are generated due to purely for testing and CI.
The effectiveness of this change can be observed by the ~1.2% improvement in code coverage (as indirect changes).
PR should start as a draft, then move to ready for review state after CI is passed and all applicable checkboxes are closed.
This approach ensures that reviewers don't spend extra time asking for regular requirements.
You can remove a checkbox as not applicable only if it doesn't relate to this PR in any way.
For example, PR with docs update doesn't require checkboxes for performance while PR with any change in actual code should have checkboxes and justify how this code change is expected to affect performance (or justification should be self-evident).
Checklist to comply with before moving PR from draft:
PR completeness and readability
Testing
Performance