Skip to content
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

Some tweaks related to context ingestion #168

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/nnbench/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Any

from nnbench import BenchmarkRunner, ConsoleReporter, __version__
from nnbench.reporter.file import FileReporter
from nnbench.reporter import FileReporter

_VERSION = f"%(prog)s version {__version__}"

Expand Down Expand Up @@ -122,18 +122,16 @@ def main() -> int:
default=list(),
help="Additional record data to display in the comparison table.",
)
# TODO: Add customization option for rich table displays

try:
args = parser.parse_args()
if args.command == "run":
context: dict[str, Any] = {}
for val in args.context:
try:
k, v = val.split("=")
k, v = val.split("=", 1)
except ValueError:
raise ValueError("context values need to be of the form <key>=<value>")
# TODO: Support builtin providers in the runner
context[k] = v

record = BenchmarkRunner(typecheck=args.typecheck).run(
Expand All @@ -159,8 +157,7 @@ def main() -> int:
parameters=args.parameters,
contextvals=args.contextvals,
)

return 0
except Exception as e:
sys.stderr.write(f"error: {e}")
sys.exit(1)
return 1
5 changes: 2 additions & 3 deletions src/nnbench/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ class PythonInfo:

Parameters
----------
*packages: str
packages: tuple[str, ...]
Names of the requested packages under which they exist in the current environment.
For packages installed through ``pip``, this equals the PyPI package name.
"""

key = "python"

def __init__(self, *packages: str):
def __init__(self, packages: tuple[str, ...]):
self.packages = packages

def __call__(self) -> dict[str, Any]:
Expand Down Expand Up @@ -191,5 +191,4 @@ def __call__(self) -> dict[str, Any]:
# result is in bytes, so no need for base conversion.
result["total_memory"] = mem_struct.total / mem_conversion
result["memory_unit"] = self.memunit
# TODO: Lacks CPU cache info, which requires a solution other than psutil.
return {self.key: result}