-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(eval): misc SWE-Bench improvement - use different resources for …
…different instances (#6313) Co-authored-by: openhands <[email protected]>
- Loading branch information
1 parent
0661c69
commit 72af7bb
Showing
8 changed files
with
312 additions
and
128 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""Mapping instance_id to resource_factor. | ||
Different instances may have different resource requirements. | ||
e.g., some instances may require more memory/CPU to run inference. | ||
This file tracks the resource requirements of different instances. | ||
""" | ||
|
||
import json | ||
import os | ||
from openhands.core.logger import openhands_logger as logger | ||
|
||
CUR_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
DEFAULT_RUNTIME_RESOURCE_FACTOR = int( | ||
os.environ.get('DEFAULT_RUNTIME_RESOURCE_FACTOR', 1) | ||
) | ||
|
||
# dataset to resource mapping | ||
_global_resource_mapping: dict[str, dict[str, float]] = {} | ||
|
||
|
||
def get_resource_mapping(dataset_name: str) -> dict[str, float]: | ||
if dataset_name not in _global_resource_mapping: | ||
file_path = os.path.join(CUR_DIR, f'{dataset_name}.json') | ||
if not os.path.exists(file_path): | ||
logger.warning(f'Resource mapping for {dataset_name} not found.') | ||
return None | ||
|
||
with open(file_path, 'r') as f: | ||
_global_resource_mapping[dataset_name] = json.load(f) | ||
logger.info(f'Loaded resource mapping for {dataset_name}') | ||
return _global_resource_mapping[dataset_name] | ||
|
||
|
||
def get_instance_resource_factor(dataset_name: str, instance_id: str) -> int: | ||
resource_mapping = get_resource_mapping(dataset_name) | ||
if resource_mapping is None: | ||
return DEFAULT_RUNTIME_RESOURCE_FACTOR | ||
return int(resource_mapping.get(instance_id, DEFAULT_RUNTIME_RESOURCE_FACTOR)) |
1 change: 1 addition & 0 deletions
1
evaluation/benchmarks/swe_bench/resource/princeton-nlp__SWE-bench_Verified-test.json
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 @@ | ||
{"pydata__xarray-6721": 8, "pytest-dev__pytest-7236": 8, "matplotlib__matplotlib-24627": 4, "django__django-15561": 4, "django__django-15098": 4, "django__django-14771": 4, "sympy__sympy-21612": 4, "sympy__sympy-15345": 4, "psf__requests-5414": 4, "astropy__astropy-14508": 2, "django__django-11451": 2, "django__django-11477": 2, "django__django-10880": 2, "django__django-11163": 2, "django__django-11815": 2, "astropy__astropy-14369": 2, "django__django-10097": 2, "django__django-10554": 2, "django__django-12304": 2, "django__django-12325": 2, "django__django-11551": 2, "django__django-11734": 2, "django__django-13109": 2, "django__django-13089": 2, "django__django-13343": 2, "django__django-13363": 2, "django__django-13809": 2, "django__django-13810": 2, "django__django-13786": 2, "django__django-13807": 2, "django__django-14493": 2, "django__django-11820": 2, "django__django-11951": 2, "django__django-11964": 2, "astropy__astropy-14309": 2, "astropy__astropy-14365": 2, "astropy__astropy-12907": 2, "astropy__astropy-14182": 2, "django__django-15161": 2, "django__django-15128": 2, "django__django-14999": 2, "django__django-14915": 2, "django__django-14752": 2, "django__django-14765": 2, "django__django-14089": 2, "django__django-15252": 2, "django__django-15380": 2, "django__django-15382": 2, "django__django-15499": 2, "django__django-15467": 2, "django__django-15280": 2, "django__django-15315": 2, "django__django-15277": 2, "django__django-15268": 2, "django__django-15629": 2, "django__django-15695": 2, "django__django-15732": 2, "django__django-15863": 2, "django__django-16082": 2, "django__django-16145": 2, "django__django-16256": 2, "django__django-16429": 2, "django__django-16454": 2, "django__django-16493": 2, "matplotlib__matplotlib-13989": 2, "matplotlib__matplotlib-20488": 2, "django__django-15503": 2, "django__django-15525": 2, "django__django-15375": 2, "django__django-15278": 2, "matplotlib__matplotlib-21568": 2, "matplotlib__matplotlib-20859": 2, "matplotlib__matplotlib-20826": 2, "matplotlib__matplotlib-20676": 2, "matplotlib__matplotlib-23412": 2, "matplotlib__matplotlib-22719": 2, "matplotlib__matplotlib-23299": 2, "matplotlib__matplotlib-22865": 2, "matplotlib__matplotlib-24149": 2, "matplotlib__matplotlib-24177": 2, "matplotlib__matplotlib-24570": 2, "matplotlib__matplotlib-24637": 2, "matplotlib__matplotlib-24970": 2, "matplotlib__matplotlib-23476": 2, "matplotlib__matplotlib-24026": 2, "matplotlib__matplotlib-23314": 2, "matplotlib__matplotlib-25332": 2, "matplotlib__matplotlib-25311": 2, "matplotlib__matplotlib-25122": 2, "matplotlib__matplotlib-25479": 2, "matplotlib__matplotlib-26342": 2, "psf__requests-2317": 2, "matplotlib__matplotlib-25960": 2, "matplotlib__matplotlib-25775": 2, "pydata__xarray-4356": 2, "pydata__xarray-4075": 2, "pydata__xarray-6461": 2, "pydata__xarray-4687": 2, "pydata__xarray-6599": 2, "pylint-dev__pylint-4661": 2, "django__django-15554": 2, "django__django-15563": 2, "pytest-dev__pytest-5262": 2, "pytest-dev__pytest-10081": 2, "scikit-learn__scikit-learn-12973": 2, "scikit-learn__scikit-learn-13124": 2, "scikit-learn__scikit-learn-13779": 2, "scikit-learn__scikit-learn-14141": 2, "scikit-learn__scikit-learn-13439": 2, "scikit-learn__scikit-learn-13496": 2, "scikit-learn__scikit-learn-15100": 2, "scikit-learn__scikit-learn-25102": 2, "scikit-learn__scikit-learn-25232": 2, "scikit-learn__scikit-learn-25747": 2, "scikit-learn__scikit-learn-26323": 2, "scikit-learn__scikit-learn-9288": 2, "scikit-learn__scikit-learn-14496": 2, "scikit-learn__scikit-learn-14629": 2, "sphinx-doc__sphinx-8265": 2, "sphinx-doc__sphinx-8548": 2, "sphinx-doc__sphinx-8593": 2, "sphinx-doc__sphinx-8595": 2, "sphinx-doc__sphinx-8621": 2, "sphinx-doc__sphinx-8638": 2, "sphinx-doc__sphinx-9229": 2, "sphinx-doc__sphinx-9281": 2, "sphinx-doc__sphinx-9461": 2, "sphinx-doc__sphinx-9591": 2, "sphinx-doc__sphinx-9658": 2, "sphinx-doc__sphinx-9673": 2, "sympy__sympy-12096": 2, "sympy__sympy-12481": 2, "sphinx-doc__sphinx-10323": 2, "sphinx-doc__sphinx-7590": 2, "sympy__sympy-13877": 2, "sympy__sympy-12489": 2, "sympy__sympy-15809": 2, "sympy__sympy-14711": 2, "sympy__sympy-16597": 2, "sympy__sympy-16766": 2, "sympy__sympy-16792": 2, "sympy__sympy-15875": 2, "sympy__sympy-17655": 2, "sympy__sympy-18189": 2, "sympy__sympy-18763": 2, "sympy__sympy-19040": 2, "sympy__sympy-19495": 2, "sympy__sympy-19637": 2, "sympy__sympy-19783": 2, "sympy__sympy-17630": 2, "sympy__sympy-20428": 2, "sympy__sympy-20590": 2, "sympy__sympy-20801": 2, "sympy__sympy-21379": 2, "sympy__sympy-21847": 2, "sympy__sympy-22456": 2, "sympy__sympy-22714": 2, "sympy__sympy-22914": 2, "sympy__sympy-23262": 2, "sympy__sympy-23413": 2, "sympy__sympy-23534": 2, "sympy__sympy-24066": 2, "sympy__sympy-24213": 2, "sympy__sympy-24443": 2, "sympy__sympy-24562": 2, "sympy__sympy-24661": 2} |
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
69 changes: 69 additions & 0 deletions
69
evaluation/benchmarks/swe_bench/scripts/eval/combine_final_completions.py
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,69 @@ | ||
import argparse | ||
import gzip | ||
import json | ||
import os | ||
from glob import glob | ||
|
||
from tqdm import tqdm | ||
|
||
tqdm.pandas() | ||
|
||
|
||
# Load trajectories for resolved instances | ||
def load_completions(output_dir: str, instance_id: str): | ||
glob_path = os.path.join(output_dir, 'llm_completions', instance_id, '*.json') | ||
files = sorted(glob(glob_path)) # this is ascending order | ||
# pick the last file (last turn) | ||
try: | ||
file_path = files[-1] | ||
except IndexError: | ||
# print(f'No files found for instance {instance_id}: files={files}') | ||
return None | ||
with open(file_path, 'r') as f: | ||
result = json.load(f) | ||
# create messages | ||
messages = result['messages'] | ||
messages.append(result['response']['choices'][0]['message']) | ||
tools = result['kwargs']['tools'] | ||
return { | ||
'messages': messages, | ||
'tools': tools, | ||
} | ||
|
||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('jsonl_path', type=str) | ||
args = parser.parse_args() | ||
|
||
output_dir = os.path.dirname(args.jsonl_path) | ||
output_path = os.path.join(output_dir, 'output.with_completions.jsonl.gz') | ||
|
||
# Check if output would be different from input | ||
needs_update = False | ||
with open(args.jsonl_path, 'r') as f_in: | ||
for line in tqdm(f_in, desc='Checking for changes'): | ||
data = json.loads(line) | ||
new_completions = load_completions(output_dir, data['instance_id']) | ||
current_completions = data.get('raw_completions') | ||
if current_completions != new_completions: | ||
needs_update = True | ||
break | ||
|
||
if not needs_update: | ||
print('No updates required. Skipping file update.') | ||
exit(0) | ||
|
||
if os.path.exists(output_path): | ||
print(f'Output file already exists at {output_path}, overwriting? (y/n)') | ||
if input() != 'y': | ||
print('Exiting...') | ||
exit(0) | ||
|
||
# Process line by line | ||
with open(args.jsonl_path, 'r') as f_in, gzip.open(output_path, 'wt') as f_out: | ||
for line in tqdm(f_in): | ||
data = json.loads(line) | ||
data['raw_completions'] = load_completions(output_dir, data['instance_id']) | ||
f_out.write(json.dumps(data) + '\n') | ||
|
||
print(f'Saved compressed output to {output_path}') |
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
Oops, something went wrong.