-
Notifications
You must be signed in to change notification settings - Fork 4
feat: Add the OLMES variant of the MBPP task #186
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
Open
tfburns
wants to merge
3
commits into
main
Choose a base branch
from
mbpp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 hidden or 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,20 @@ | ||
| # MBPP_OLMES | ||
|
|
||
| ```` | ||
| NAME = MBPP_OLMES | ||
| DATASET_PATH = google-research-datasets/mbpp | ||
| SAMPLE_SPLIT = test | ||
| FEWSHOT_SPLIT = test | ||
| RESPONSE_TYPE = COMPLETION | ||
| METRICS = [CodeCompletionAssertion] | ||
| SUBJECTS = ['full'] | ||
| LANGUAGE = <Language.ENG: 'English'> | ||
| ```` | ||
|
|
||
| - Module: `eval_framework.tasks.benchmarks.mbpp` | ||
|
|
||
| - File: [src/eval_framework/tasks/benchmarks/mbpp.py](../../src/eval_framework/tasks/benchmarks/mbpp.py) | [View on GitHub](https://github.com/Aleph-Alpha-Research/eval-framework/blob/main/src/eval_framework/tasks/benchmarks/mbpp.py) | ||
|
|
||
| - Link to dataset: [https://huggingface.co/datasets/google-research-datasets/mbpp](https://huggingface.co/datasets/google-research-datasets/mbpp) | ||
|
|
||
| More detailed documentation, with prompt examples and ground truth completions, can be generated with `uv run -m eval_framework.utils.generate_task_docs --add-prompt-examples --only-tasks "MBPP_OLMES"`. |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -78,9 +78,13 @@ def generate_docs_for_task( | |
| try: | ||
| num_fewshot = 0 | ||
| task = task_class(num_fewshot=num_fewshot) | ||
| except Exception as e: | ||
| print(f"Failed to instantiate task {task_name}: {e}") | ||
| return | ||
| except Exception: | ||
|
Contributor
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. any chance we can make it more specific? |
||
| try: | ||
| task = task_class() | ||
| num_fewshot = task.num_fewshot | ||
| except Exception as e: | ||
| print(f"Failed to instantiate task {task_name}: {e}") | ||
| return | ||
|
|
||
| with open(f"{output_docs_directory}/{task_name}.md", "w") as f: | ||
| f.write(f"# {task_name}\n\n") | ||
|
|
||
This file contains hidden or 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 hidden or 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,104 @@ | ||
| import pytest | ||
|
|
||
| from eval_framework.tasks.benchmarks.mbpp import _OLMES_FEWSHOT_EXAMPLES, MBPP_OLMES | ||
| from eval_framework.tasks.utils import run_python_code | ||
| from template_formatting.formatter import ConcatFormatter | ||
| from tests.tests_eval_framework.utils import DatasetPatcher | ||
|
|
||
|
|
||
| class TestMBPP_OLMES: | ||
| @pytest.fixture | ||
| def task(self) -> MBPP_OLMES: | ||
| with DatasetPatcher(MBPP_OLMES, num_fewshot=3, num_samples=10) as patched_task: | ||
| return patched_task | ||
|
|
||
| def test_num_fewshot_must_be_3(self) -> None: | ||
| with pytest.raises(AssertionError, match="MBPP_OLMES requires exactly 3 fewshot examples"): | ||
| MBPP_OLMES(num_fewshot=1) | ||
|
|
||
| def test_stop_sequences(self) -> None: | ||
| task = MBPP_OLMES(num_fewshot=3) | ||
| assert task.stop_sequences == ["```", '\n"""', "\nassert", "\n#"] | ||
|
|
||
| def test_instruction_uses_evalplus_format(self, task: MBPP_OLMES) -> None: | ||
| task._load_dataset(task.SUBJECTS[0]) | ||
| item = task.dataset[task.SAMPLE_SPLIT][0] | ||
| item["subject"] = task.SUBJECTS[0] | ||
| instruction = task._get_instruction_text(item) | ||
|
|
||
| expected_prefix = ( | ||
| "Please provide a self-contained Python script that solves the following problem" | ||
| " in a markdown code block:\n```\n" | ||
| ) | ||
| assert instruction.startswith(expected_prefix) | ||
| assert instruction.endswith("\n```\n") | ||
| assert item["test_list"][0] in instruction | ||
|
|
||
| def test_instruction_contains_only_one_test(self, task: MBPP_OLMES) -> None: | ||
| task._load_dataset(task.SUBJECTS[0]) | ||
| item = task.dataset[task.SAMPLE_SPLIT][0] | ||
| item["subject"] = task.SUBJECTS[0] | ||
| instruction = task._get_instruction_text(item) | ||
|
|
||
| for test in item["test_list"][1:]: | ||
| assert test not in instruction | ||
|
|
||
| def test_cue_text(self, task: MBPP_OLMES) -> None: | ||
| task._load_dataset(task.SUBJECTS[0]) | ||
| item = task.dataset[task.SAMPLE_SPLIT][0] | ||
| cue = task._get_cue_text(item) | ||
| assert cue == "Here is the completed function:\n\n```python\n" | ||
|
|
||
| def test_fewshot_examples_are_hardcoded(self, task: MBPP_OLMES) -> None: | ||
| task._load_dataset(task.SUBJECTS[0]) | ||
| item = task.dataset[task.SAMPLE_SPLIT][0] | ||
|
|
||
| examples = task._sample_fewshot_examples(item) | ||
| assert len(examples) == 3 | ||
| assert examples[0]["text"] == _OLMES_FEWSHOT_EXAMPLES[0]["text"] | ||
| assert examples[1]["text"] == _OLMES_FEWSHOT_EXAMPLES[1]["text"] | ||
| assert examples[2]["text"] == _OLMES_FEWSHOT_EXAMPLES[2]["text"] | ||
|
|
||
| def test_fewshot_examples_are_deterministic(self, task: MBPP_OLMES) -> None: | ||
| task._load_dataset(task.SUBJECTS[0]) | ||
| item = task.dataset[task.SAMPLE_SPLIT][0] | ||
|
|
||
| examples_1 = task._sample_fewshot_examples(item) | ||
| examples_2 = task._sample_fewshot_examples(item) | ||
| assert examples_1 == examples_2 | ||
|
|
||
| def test_fewshot_target_is_code_with_newline(self) -> None: | ||
| task = MBPP_OLMES(num_fewshot=3) | ||
| for example in _OLMES_FEWSHOT_EXAMPLES: | ||
| target = task._get_fewshot_target_text(example) | ||
| assert target == example["code"] + "\n" | ||
| assert "```" not in target | ||
|
|
||
| def test_code_execution_with_canonical_solution(self, task: MBPP_OLMES) -> None: | ||
| task._load_dataset(task.SUBJECTS[0]) | ||
| for i, item in enumerate(task.dataset[task.SAMPLE_SPLIT][:5]): | ||
| # Verify that canonical code + test asserts execute correctly. | ||
| # We call _code_expander directly because in real usage the LLM | ||
| # engine truncates output at stop sequences (e.g. \n#) before it | ||
| # reaches post_process, and canonical solutions may contain those | ||
| # sequences (comments, asserts) that would corrupt the test. | ||
| code = MBPP_OLMES._code_expander(item["code"] + "\n", str(item["test_list"])) | ||
| result = run_python_code(code) | ||
| assert result.endswith("True"), f"Item {i} failed: {result}" | ||
|
|
||
| def test_prompt_format_matches_oe_eval(self, task: MBPP_OLMES) -> None: | ||
| """Verify the assembled prompt has the expected structure with ConcatFormatter.""" | ||
| task._load_dataset(task.SUBJECTS[0]) | ||
| item = task.dataset[task.SAMPLE_SPLIT][0] | ||
| item["subject"] = task.SUBJECTS[0] | ||
| sample = task._create_samples(item, 0, task.SUBJECTS[0])[0] | ||
|
|
||
| formatter = ConcatFormatter() | ||
| formatted = formatter.format(sample.messages, output_mode="string") | ||
|
|
||
| assert "Please provide a self-contained Python script" in formatted | ||
| assert "Here is the completed function:" in formatted | ||
| assert "```python" in formatted | ||
|
|
||
| fewshot_count = formatted.count("Please provide a self-contained Python script") | ||
| assert fewshot_count == 4, f"Expected 4 occurrences (3 fewshot + 1 eval), got {fewshot_count}" |
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.
This seems to contradict the type hint in the definition