-
Notifications
You must be signed in to change notification settings - Fork 80
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
python[patch]: evaluators can return primitives #1203
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
388764f
rfc: evaluators can return primitives
baskaryan a18c139
fmt
baskaryan 73c5d5b
Merge branch 'main' into bagatur/rfc_eval_simple_returns
baskaryan 7ea4897
undo
baskaryan 9601d89
Merge branch 'main' into bagatur/rfc_eval_simple_returns
baskaryan cf80a82
fmt
baskaryan 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
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 |
---|---|---|
|
@@ -196,11 +196,26 @@ def score_value_first(run, example): | |
ordering_of_stuff.append("evaluate") | ||
return {"score": 0.3} | ||
|
||
def eval_float(run, example): | ||
ordering_of_stuff.append("evaluate") | ||
return 0.2 | ||
|
||
def eval_str(run, example): | ||
ordering_of_stuff.append("evaluate") | ||
return "good" | ||
|
||
def eval_list(run, example): | ||
ordering_of_stuff.append("evaluate") | ||
return [ | ||
{"score": True, "key": "list_eval_bool"}, | ||
{"score": 1, "key": "list_eval_int"}, | ||
] | ||
|
||
results = evaluate( | ||
predict, | ||
client=client, | ||
data=dev_split, | ||
evaluators=[score_value_first], | ||
evaluators=[score_value_first, eval_float, eval_str, eval_list], | ||
num_repetitions=NUM_REPETITIONS, | ||
blocking=blocking, | ||
) | ||
|
@@ -231,14 +246,14 @@ def score_value_first(run, example): | |
assert fake_request.created_session | ||
_wait_until(lambda: fake_request.runs) | ||
N_PREDS = SPLIT_SIZE * NUM_REPETITIONS | ||
_wait_until(lambda: len(ordering_of_stuff) == N_PREDS * 2) | ||
_wait_until(lambda: len(ordering_of_stuff) == N_PREDS * 5) | ||
_wait_until(lambda: slow_index is not None) | ||
# Want it to be interleaved | ||
assert ordering_of_stuff != ["predict"] * N_PREDS + ["evaluate"] * N_PREDS | ||
assert ordering_of_stuff[:N_PREDS] != ["predict"] * N_PREDS | ||
|
||
# It's delayed, so it'll be the penultimate event | ||
# Will run all other preds and evals, then this, then the last eval | ||
assert slow_index == (N_PREDS * 2) - 2 | ||
assert slow_index == (N_PREDS - 1) * 5 | ||
|
||
def score_value(run, example): | ||
return {"score": 0.7} | ||
|
@@ -260,6 +275,22 @@ def score_value(run, example): | |
assert r["run"].reference_example_id in dev_xample_ids | ||
assert not fake_request.should_fail | ||
|
||
# Returning list of non-dicts not supported. | ||
def bad_eval_list(run, example): | ||
ordering_of_stuff.append("evaluate") | ||
return ["foo", 1] | ||
|
||
results = evaluate( | ||
predict, | ||
client=client, | ||
data=dev_split, | ||
evaluators=[bad_eval_list], | ||
num_repetitions=NUM_REPETITIONS, | ||
blocking=blocking, | ||
) | ||
for r in results: | ||
assert r["evaluation_results"]["results"][0].extra == {"error": True} | ||
|
||
|
||
def test_evaluate_raises_for_async(): | ||
async def my_func(inputs: dict): | ||
|
@@ -366,11 +397,26 @@ async def score_value_first(run, example): | |
ordering_of_stuff.append("evaluate") | ||
return {"score": 0.3} | ||
|
||
async def eval_float(run, example): | ||
ordering_of_stuff.append("evaluate") | ||
return 0.2 | ||
|
||
async def eval_str(run, example): | ||
ordering_of_stuff.append("evaluate") | ||
return "good" | ||
|
||
async def eval_list(run, example): | ||
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 good to confirm that a list of ints, for example, doesn't work? |
||
ordering_of_stuff.append("evaluate") | ||
return [ | ||
{"score": True, "key": "list_eval_bool"}, | ||
{"score": 1, "key": "list_eval_int"}, | ||
] | ||
|
||
results = await aevaluate( | ||
predict, | ||
client=client, | ||
data=dev_split, | ||
evaluators=[score_value_first], | ||
evaluators=[score_value_first, eval_float, eval_str, eval_list], | ||
num_repetitions=NUM_REPETITIONS, | ||
blocking=blocking, | ||
) | ||
|
@@ -406,14 +452,14 @@ async def score_value_first(run, example): | |
assert fake_request.created_session | ||
_wait_until(lambda: fake_request.runs) | ||
N_PREDS = SPLIT_SIZE * NUM_REPETITIONS | ||
_wait_until(lambda: len(ordering_of_stuff) == N_PREDS * 2) | ||
_wait_until(lambda: len(ordering_of_stuff) == N_PREDS * 5) | ||
_wait_until(lambda: slow_index is not None) | ||
# Want it to be interleaved | ||
assert ordering_of_stuff != ["predict"] * N_PREDS + ["evaluate"] * N_PREDS | ||
assert ordering_of_stuff[:N_PREDS] != ["predict"] * N_PREDS | ||
assert slow_index is not None | ||
# It's delayed, so it'll be the penultimate event | ||
# Will run all other preds and evals, then this, then the last eval | ||
assert slow_index == (N_PREDS * 2) - 2 | ||
assert slow_index == (N_PREDS - 1) * 5 | ||
|
||
assert fake_request.created_session["name"] | ||
|
||
|
@@ -431,3 +477,19 @@ async def score_value(run, example): | |
assert r["evaluation_results"]["results"][0].score == 0.7 | ||
assert r["run"].reference_example_id in dev_xample_ids | ||
assert not fake_request.should_fail | ||
# Returning list of non-dicts not supported. | ||
|
||
async def bad_eval_list(run, example): | ||
ordering_of_stuff.append("evaluate") | ||
return ["foo", 1] | ||
|
||
results = await aevaluate( | ||
predict, | ||
client=client, | ||
data=dev_split, | ||
evaluators=[bad_eval_list], | ||
num_repetitions=NUM_REPETITIONS, | ||
blocking=blocking, | ||
) | ||
async for r in results: | ||
assert r["evaluation_results"]["results"][0].extra == {"error": True} |
Oops, something went wrong.
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.
So if I have four categories that are numbers for some reason (I'm classifying college class levels and they're 100 level, 200 level, 300 level, etc), then I should do
str(value)
to explicitly use categorical scores?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.
or return as
{"value": 200}
(something for us to clearly document)