-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CLI entrypoints for module and program invocation (#152)
* Add CLI entrypoints for module and program invocation Supports `nnbench <benchmark> <options>` as well as `python -m nnbench <benchmark> <options>`. Like pytest, we give the option to omit the target location, in which case it becomes a directory named "benchmarks". Supports a very rudimentary context building from switches method, and tag filtering via switch.
- Loading branch information
1 parent
b66d484
commit 7532f99
Showing
4 changed files
with
68 additions
and
1 deletion.
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 sys | ||
|
||
from nnbench.cli import main | ||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |
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,49 @@ | ||
import argparse | ||
from typing import Any | ||
|
||
from nnbench import default_reporter, default_runner | ||
|
||
|
||
def main() -> int: | ||
parser = argparse.ArgumentParser("nnbench") | ||
# can be a directory, single file, or glob | ||
parser.add_argument( | ||
"benchmarks", | ||
nargs="?", | ||
metavar="<benchmarks>", | ||
help="Python file or directory of files containing benchmarks to run.", | ||
default="benchmarks", | ||
) | ||
parser.add_argument( | ||
"--context", | ||
action="append", | ||
metavar="<key>=<value>", | ||
help="Additional context values giving information about the benchmark run.", | ||
default=list(), | ||
) | ||
parser.add_argument( | ||
"-t", | ||
"--tag", | ||
action="append", | ||
metavar="<tag>", | ||
dest="tags", | ||
help="Only run benchmarks marked with one or more given tag(s).", | ||
default=tuple(), | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
runner = default_runner() | ||
reporter = default_reporter() | ||
|
||
context: dict[str, Any] = {} | ||
for val in args.context: | ||
try: | ||
k, v = val.split("=") | ||
except ValueError: | ||
raise ValueError("context values need to be of the form <key>=<value>") | ||
context[k] = v | ||
|
||
record = runner.run(args.benchmarks, tags=tuple(args.tags)) | ||
reporter.display(record) | ||
return 0 |