-
Notifications
You must be signed in to change notification settings - Fork 3.5k
advanced profiler describe + cleaned up tests #837
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
advanced profiler describe + cleaned up tests #837
Conversation
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.
is it covered by tests?
tests/test_profiler.py
Outdated
@@ -26,6 +26,9 @@ def test_simple_profiler(): | |||
np.testing.assert_allclose(p.recorded_durations["b"], [2], rtol=0.2) | |||
np.testing.assert_allclose(p.recorded_durations["c"], [1], rtol=0.2) | |||
|
|||
# ensure this doesn't throw any errors | |||
description = p.describe() |
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 do not see description
to be used...
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.
yes i’m just making sure that it can successfully call the method without throwing an error. might be worth moving that line to a new test case test_simple_profiler_describe()
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.
you may just drop output _ = p.describe()
or just p.describe()
I would say that single letter variable is not good practice... :]
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.
agreed, i'll clean the tests up a bit
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.
Pls write a line about the philosophy behind using fixtures, it will be useful for future users...
time.sleep(2) | ||
@pytest.mark.parametrize("action,expected", [("a", [3, 1]), ("b", [2]), ("c", [1])]) | ||
def test_simple_profiler_durations(simple_profiler, action, expected): | ||
""" |
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.
just thinking if we shall start reasonable documentation also for tests, meaning at least add variable types...
if I would be perfectionist, doc requires Sentences start with a capital and ending by . :]
PROFILER_OVERHEAD_MAX_TOLERANCE = 0.0001 | ||
|
||
|
||
@pytest.fixture |
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.
just to clarify, this freeze the profiler object so all test are using the same instance...
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.
it depends on the scope of your fixture. by default, a new object is created for each function
https://docs.pytest.org/en/latest/reference.html#pytest-fixture
@pytest.mark.parametrize("action,expected", [("a", [3, 1]), ("b", [2]), ("c", [1])]) | ||
def test_simple_profiler_durations(simple_profiler, action, expected): | ||
""" | ||
ensure the reported durations are reasonably accurate |
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.
it took a mi sec to understand the idea behind, that is looping with the same instance... maybe it would be nice to write it in doc, in someone in future would need to change/update it...
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 think it might be a good idea to update the test/README.md
with testing philosophy and guidelines. introduce the usage of fixtures/parameterized tests, specify the desired level of documentation, etc.
what do you think?
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.
good point, just not README but CONTRIBUTION on docs - in another issue/PR?
still, please write the two lines about the holding instance for multiple runs (i assume it is a bit special case...) Thx :]
def test_advanced_profiler(): | ||
def _get_duration(profile): | ||
return sum([x.totaltime for x in profile.getstats()]) | ||
def test_simple_profiler_overhead(simple_profiler, n_iter=5): |
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.
👍
time.sleep(2) | ||
@pytest.mark.parametrize("action,expected", [("a", [3, 1]), ("b", [2]), ("c", [1])]) | ||
def test_advanced_profiler_durations(advanced_profiler, action, expected): | ||
def _get_total_duration(profile): |
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.
_get_total_duration
>> _sum_durations
?
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 think total_duration
is more explicit? as in, for a given action we're getting the total duration for all of the times the action was recorded. we're not actually summing over each invocation of the action, we're summing over the functions invoked within the action as recorded by the cProfiler
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.
ok for total, just think that sum is a better fit than get...
pass | ||
|
||
action_profile = advanced_profiler.profiled_actions["no-op"] | ||
total_duration = sum([x.totaltime for x in action_profile.getstats()]) |
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.
if you declare previous _get_total_duration(profile)
as module function you can just use it here...
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.
good point :)
@jeremyjordan really nice refactoring, just a minor comments 🚀 |
@jeremyjordan have made your last changes or @williamFalcon was faster with his merge? |
@Borda the latter. i had planned to extract |
@jeremyjordan sorry, i thought this was ready because there was no WIP. Can you open another PR to finish these changes? :) |
@williamFalcon yeah no worries that was my bad! sure thing :) |
* add py36 compatibility * add test case to capture previous bug * clean up tests * clean up tests
* add py36 compatibility * add test case to capture previous bug * clean up tests * clean up tests
* add more underline * fix LightningMudule import error * remove unneeded blank line * escape asterisk to fix inline emphasis warning * add PULL_REQUEST_TEMPLATE.md * add __init__.py and import imagenet_example * fix duplicate label * add noindex option to fix duplicate object warnings * remove unexpected indent * refer explicit LightningModule * fix minor bug * refer EarlyStopping explicitly * restore exclude patterns * change the way how to refer class * remove unused import * update badges & drop Travis/Appveyor (#826) * drop Travis * drop Appveyor * update badges * fix missing PyPI images & CI badges (#853) * docs - anchor links (#848) * docs - add links * add desc. * add Greeting action (#843) * add Greeting action * Update greetings.yml Co-authored-by: William Falcon <[email protected]> * add pep8speaks (#842) * advanced profiler describe + cleaned up tests (#837) * add py36 compatibility * add test case to capture previous bug * clean up tests * clean up tests * Update lightning_module_template.py * Update lightning.py * respond lint issues * break long line * break more lines * checkout conflicting files from master * shorten url * checkout from upstream/master * remove trailing whitespaces * remove unused import LightningModule * fix sphinx bot warnings * Apply suggestions from code review just to trigger CI * Update .github/workflows/greetings.yml Co-authored-by: Jirka Borovec <[email protected]> Co-authored-by: William Falcon <[email protected]> Co-authored-by: Jeremy Jordan <[email protected]>
* add more underline * fix LightningMudule import error * remove unneeded blank line * escape asterisk to fix inline emphasis warning * add PULL_REQUEST_TEMPLATE.md * add __init__.py and import imagenet_example * fix duplicate label * add noindex option to fix duplicate object warnings * remove unexpected indent * refer explicit LightningModule * fix minor bug * refer EarlyStopping explicitly * restore exclude patterns * change the way how to refer class * remove unused import * update badges & drop Travis/Appveyor (Lightning-AI#826) * drop Travis * drop Appveyor * update badges * fix missing PyPI images & CI badges (Lightning-AI#853) * docs - anchor links (Lightning-AI#848) * docs - add links * add desc. * add Greeting action (Lightning-AI#843) * add Greeting action * Update greetings.yml Co-authored-by: William Falcon <[email protected]> * add pep8speaks (Lightning-AI#842) * advanced profiler describe + cleaned up tests (Lightning-AI#837) * add py36 compatibility * add test case to capture previous bug * clean up tests * clean up tests * Update lightning_module_template.py * Update lightning.py * respond lint issues * break long line * break more lines * checkout conflicting files from master * shorten url * checkout from upstream/master * remove trailing whitespaces * remove unused import LightningModule * fix sphinx bot warnings * Apply suggestions from code review just to trigger CI * Update .github/workflows/greetings.yml Co-authored-by: Jirka Borovec <[email protected]> Co-authored-by: William Falcon <[email protected]> Co-authored-by: Jeremy Jordan <[email protected]>
Before submitting
What does this PR do?
Fixes #836
PR review
Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.