-
Notifications
You must be signed in to change notification settings - Fork 3
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 Parameters to Benchmarks #103
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a130498
Add Parameters to Benchmarks
maxmynter bf72378
Update Readme to include parameter summary
maxmynter 70dde07
Add test for filtering via parameters
maxmynter 525ddea
Update src/nnbench/runner.py
maxmynter 0c0a107
Inline benchmark into test, use update syntax on dict
nicholasjng 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import nnbench | ||
|
||
|
||
@nnbench.parametrize([{"a": 1}, {"a": 2}], tags=("parametrized",)) | ||
def double(a: int) -> int: | ||
return 2 * 2 |
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
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.
Does this ensure that the defaults are overwritten by the
bmparams
?I think something like
bmdefaults.update(bmparams)
would be easier to read.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, the entires are unpacked in order with the latter overwriting the former in case of colliding keys.
dict.update
does not return the merged dict, but just updates inplace.We couid do
dict(bmdefaults, **bmparams)
, though I don't think that is easier to read.Alternatively, do an update on
bmdefaults
and then pass only that. That is an extra line though and we have a bmdefaults flying around that does not contain the defaults.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 this does what it needs to do: For any variable, if the default is used, it's not in
bmparams
, so the update does nothing - and for every overridden default, theupdate()
overwrites with the argument given in the params dict.So the order should be "use defaults, then update with params", which is what I suggested (you can also write
bmdefaults | bmparams
).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 need a mental model, it helps to think about what happens once the
params
are passed into the function - its default keyword arguments are already there, and everything else gets overridden by the incoming parameters. So it is indeedbmdefault.update(bmparams)
we're looking for here (you can even use that as the dict value, since we do not explicitly use it again afterwards).