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

Add user guide: Defining and parametrizing benchmarks by applying decorators #34

Closed
1 task
Tracked by #27
Maciej818 opened this issue Jan 30, 2024 · 2 comments · Fixed by #36
Closed
1 task
Tracked by #27

Add user guide: Defining and parametrizing benchmarks by applying decorators #34

Maciej818 opened this issue Jan 30, 2024 · 2 comments · Fixed by #36
Assignees
Labels
documentation Improvements or additions to documentation urgent Needs to be worked on ASAP.
Milestone

Comments

@Maciej818
Copy link

Maciej818 commented Jan 30, 2024

Add user guide to the documentation:

  • Defining and parametrizing benchmarks by applying decorators (@benchmark,@parametrize,@product) - motivation, behavior, and one usage example for each.
@Maciej818 Maciej818 changed the title Defining and parametrizing benchmarks by applying decorators (@benchmark,@parametrize,@product) - motivation, behavior, and one usage example for each. Add user guide: Best practices on modularizing benchmark code Jan 30, 2024
@Maciej818 Maciej818 changed the title Add user guide: Best practices on modularizing benchmark code Add user guide: Defining and parametrizing benchmarks by applying decorators Jan 30, 2024
@maxmynter maxmynter self-assigned this Jan 30, 2024
@Maciej818 Maciej818 added this to the v0.1.0 milestone Jan 30, 2024
@Maciej818 Maciej818 added documentation Improvements or additions to documentation urgent Needs to be worked on ASAP. labels Jan 31, 2024
@Maciej818
Copy link
Author

To keep information complete I copy-paste here comments from #33 (which is an issue that duplicates this one):

msavinash commented 15 hours ago
I don't understand how parametrize is supposed to work. From my understanding its something like this:

parametrize_parameters = [
{"y_test": [1, 2, 3], "y_pred": [4, 5, 6]},
{"y_test": [1, 2, 3], "y_pred": [1, 2, 3]},
]

@nnbench.parametrize(parameters=parametrize_parameters)
def accuracy(model: base.BaseEstimator, y_test: np.ndarray, y_pred: np.ndarray) -> float:
accuracy = metrics.accuracy_score(y_test, y_pred)
return accuracy

Is this accurate?

nicholasjng commented 31 minutes ago
Is this accurate?

Yes.

(The arguments in the decorator dictionaries should match the parametrized benchmark function's typing, so the arguments should be np.array([1, 2, 3]), np.array([4, 5, 6]), ..., but you got it right conceptually.)

@msavinash
Copy link

msavinash commented Feb 1, 2024

I tried running this:

import nnbench
from sklearn import base
import numpy as np


parametrize_parameters = [
    {"y_test": np.array([1, 2, 3]), "y_pred": np.array([4, 5, 6])},
    {"y_test": np.array([1, 2, 3]), "y_pred": np.array([1, 2, 3])},
]

@nnbench.parametrize(parameters=parametrize_parameters)
def accuracy(model: base.BaseEstimator, y_test: np.ndarray, y_pred: np.ndarray) -> float:
    accuracy = metrics.accuracy_score(y_test, y_pred)
    return accuracy


from nnbench import runner
r = runner.BenchmarkRunner()
y_pred = model.predict(X_test)
result = r.run("__main__", params={"model": model})

r.report(to='console', result=result)

Got this error:

  File "C:\Users\Public\Documents\Avinash\Projects\OpenSource\nnbench\test.py", line 65, in <module>
    result = r.run("__main__", params={"model": model})#, "y_pred": y_pred, "y_test": y_test})
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Public\Documents\Avinash\Projects\OpenSource\nnbench\src\nnbench\runner.py", line 218, in run
    _check(dparams, self.benchmarks)
  File "C:\Users\Public\Documents\Avinash\Projects\OpenSource\nnbench\src\nnbench\runner.py", line 84, in _check
    raise ValueError(f"missing value for required parameter {name!r}")
ValueError: missing value for required parameter 'y_test'

I believe the code expects me to add y_pred and y_test as well, but they are defined for parameterize decorator. What is the expected behavior here?
result = r.run("__main__", params={"model": model, "y_pred": y_pred, "y_test": y_test})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation urgent Needs to be worked on ASAP.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants