-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add np.ndarray as a recognized type for TB histograms. #1635
Merged
Merged
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
fec692c
Add np.ndarray as a recognized type for TB histograms.
iwishiwasaneagle d37a952
Update changelog to reflect bug fix
iwishiwasaneagle f0620e3
Merge branch 'master' into master
araffin 185d63b
Merge branch 'master' into master
iwishiwasaneagle 253bb64
Merge branch 'master' into master
iwishiwasaneagle 523fe36
Merge branch 'master' into master
iwishiwasaneagle d101bcd
Merge branch 'master' into master
araffin 4386be5
fix: try/catch for if either np or torch aren't at the required versi…
iwishiwasaneagle 383ee76
fix: Add comment describing the test for when add_histogram should no…
iwishiwasaneagle 0343155
Merge branch 'master' into master
iwishiwasaneagle fca8112
Merge branch 'master' into master
iwishiwasaneagle 7fb3135
Merge branch 'master' into master
araffin 5121148
Merge branch 'master' into master
iwishiwasaneagle 880bd2d
Merge branch 'master' into master
iwishiwasaneagle e46a6d5
Cleanup
araffin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import functools | ||
import importlib.util | ||
import os | ||
import sys | ||
|
@@ -250,6 +251,62 @@ def test_report_video_to_unsupported_format_raises_error(tmp_path, unsupported_f | |
writer.close() | ||
|
||
|
||
_called = None | ||
|
||
|
||
def get_fail_first_then_pass_fn(fn, exception=Exception): | ||
_called = False | ||
|
||
@functools.wraps(fn) | ||
def _fn(*args, **kwargs): | ||
global _called | ||
if not _called: | ||
_called = True | ||
raise exception() | ||
return fn(*args, **kwargs) | ||
|
||
return _fn | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"histogram,fail_first_write", | ||
[ | ||
(th.rand(100), False), | ||
(np.random.rand(100), False), | ||
(np.random.rand(100), True), | ||
], | ||
) | ||
def test_report_histogram_to_tensorboard(tmp_path, read_log, fail_first_write, histogram): | ||
pytest.importorskip("tensorboard") | ||
|
||
writer = make_output_format("tensorboard", tmp_path) | ||
|
||
if fail_first_write: | ||
writer.writer.add_histogram = get_fail_first_then_pass_fn(writer.writer.add_histogram, TypeError) | ||
|
||
writer.write({"data": histogram}, key_excluded={"data": ()}) | ||
|
||
log = read_log("tensorboard") | ||
|
||
assert not log.empty | ||
assert any("data" in f for f in log.lines) | ||
assert any("Histogram" in f for f in log.lines) | ||
|
||
writer.close() | ||
|
||
|
||
@pytest.mark.parametrize("histogram", [list(np.random.rand(100)), tuple(np.random.rand(100)), "1 2 3 4"]) | ||
def test_report_unsupported_type_as_histogram_to_tensorboard(tmp_path, read_log, histogram): | ||
pytest.importorskip("tensorboard") | ||
|
||
writer = make_output_format("tensorboard", tmp_path) | ||
writer.write({"data": histogram}, key_excluded={"data": ()}) | ||
araffin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
assert all("Histogram" not in f for f in read_log("tensorboard").lines) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe add a comment, something like "check that the values were not logged as histogram" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See 383ee76 |
||
|
||
writer.close() | ||
|
||
|
||
def test_report_image_to_tensorboard(tmp_path, read_log): | ||
pytest.importorskip("tensorboard") | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 should not need that, just record the warnings with pytest and check that the correct warning is there (we have some examples in the tests)
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 I guess with the current CI setup this warning is always hit. However, this test will then fail for anyone with newer versions of np and/pr torch.
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 should be able to check the version of pytorch to know if a warning should be outputted or not?
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.
So would you propose a check before the add_histogram to see if a warning and conversion is needed?