Skip to content

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

Conversation

jeremyjordan
Copy link
Contributor

@jeremyjordan jeremyjordan commented Feb 14, 2020

Before submitting

  • Was this discussed/approved via a Github issue? (no need for typos, doc improvements)
  • Did you read the contributor guideline?
  • Did you make sure to update the docs?
  • Did you write any new necessary tests?

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.

Copy link
Member

@Borda Borda left a 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?

@@ -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()
Copy link
Member

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...

Copy link
Contributor Author

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()

Copy link
Member

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... :]

Copy link
Contributor Author

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

@jeremyjordan jeremyjordan changed the title Bugfix/advanced profiler describe WIP: bugfix/advanced profiler describe Feb 14, 2020
@jeremyjordan jeremyjordan changed the title WIP: bugfix/advanced profiler describe bugfix/advanced profiler describe + cleaned up tests Feb 15, 2020
@jeremyjordan jeremyjordan requested a review from Borda February 15, 2020 17:28
@Borda Borda changed the title bugfix/advanced profiler describe + cleaned up tests advanced profiler describe + cleaned up tests Feb 15, 2020
@Borda Borda added the bug Something isn't working label Feb 15, 2020
@Borda Borda added this to the 0.6.1 milestone Feb 15, 2020
Copy link
Member

@Borda Borda left a 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):
"""
Copy link
Member

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
Copy link
Member

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...

Copy link
Contributor Author

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
Copy link
Member

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...

Copy link
Contributor Author

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?

Copy link
Member

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):
Copy link
Member

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):
Copy link
Member

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 ?

Copy link
Contributor Author

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

Copy link
Member

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()])
Copy link
Member

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...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point :)

@Borda
Copy link
Member

Borda commented Feb 15, 2020

agreed, i'll clean the tests up a bit

@jeremyjordan really nice refactoring, just a minor comments 🚀

@Borda Borda added feature Is an improvement or enhancement need fix labels Feb 15, 2020
@williamFalcon williamFalcon merged commit 4ae31cd into Lightning-AI:master Feb 16, 2020
@Borda
Copy link
Member

Borda commented Feb 16, 2020

@jeremyjordan have made your last changes or @williamFalcon was faster with his merge?

@jeremyjordan
Copy link
Contributor Author

@Borda the latter. i had planned to extract _get_total_duration as a module function and update the docs to be sentences

@williamFalcon
Copy link
Contributor

@jeremyjordan sorry, i thought this was ready because there was no WIP. Can you open another PR to finish these changes? :)

@jeremyjordan
Copy link
Contributor Author

@williamFalcon yeah no worries that was my bad! sure thing :)

hanbyul-kim pushed a commit to hanbyul-kim/pytorch-lightning that referenced this pull request Feb 16, 2020
* add py36 compatibility

* add test case to capture previous bug

* clean up tests

* clean up tests
hanbyul-kim pushed a commit to hanbyul-kim/pytorch-lightning that referenced this pull request Feb 24, 2020
* add py36 compatibility

* add test case to capture previous bug

* clean up tests

* clean up tests
williamFalcon added a commit that referenced this pull request Feb 27, 2020
* 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]>
tullie pushed a commit to tullie/pytorch-lightning that referenced this pull request Apr 3, 2020
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feature Is an improvement or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

advanced profiler description fails for python 3.6
3 participants