Skip to content

SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]

Feat(run_batch): Add hook to evaluate with sb-cli

Kilian Lieret5dea9bac5f77
diff --git a/sweagent/run/batch_instances.py b/sweagent/run/batch_instances.py
index c0f01baa..55289a3f 100644
--- a/sweagent/run/batch_instances.py
+++ b/sweagent/run/batch_instances.py
@@ -272,6 +272,9 @@ class SWEBenchInstances(BaseModel, AbstractInstanceSource):
shuffle: bool = False
"""Shuffle the instances (before filtering and slicing)."""
+ evaluate: bool = True
+ """Run sb-cli to evaluate"""
+
def _get_huggingface_name(self) -> str:
if self.subset == "full":
return "princeton-nlp/SWE-Bench"
diff --git a/sweagent/run/hooks/swe_bench_evaluate.py b/sweagent/run/hooks/swe_bench_evaluate.py
new file mode 100644
index 00000000..a3a89dd7
--- /dev/null
+++ b/sweagent/run/hooks/swe_bench_evaluate.py
@@ -0,0 +1,17 @@
+import subprocess
+from pathlib import Path
+
+from sweagent.run.hooks.abstract import RunHook
+
+
+class SweBenchEvaluate(RunHook):
+ _SUBSET_MAP = {"lite": "swe-bench_lite"}
+
+ def __init__(self, output_dir: Path, subset: str, split: str) -> None:
+ super().__init__()
+ self.output_dir = output_dir
+ self.subset = subset
+ self.split = split
+
+ def on_end(self) -> None:
+ subprocess.run(["sb-cli", "submit", self._SUBSET_MAP[self.subset], self.split, self.output_dir.name])
diff --git a/sweagent/run/run_batch.py b/sweagent/run/run_batch.py
index 63f35044..07f85e49 100644
--- a/sweagent/run/run_batch.py
+++ b/sweagent/run/run_batch.py
@@ -24,7 +24,7 @@ from sweagent.agent.hooks.status import SetStatusAgentHook
from sweagent.environment.hooks.status import SetStatusEnvironmentHook
from sweagent.environment.swe_env import SWEEnv
from sweagent.run._progress import RunBatchProgressManager
-from sweagent.run.batch_instances import BatchInstance, BatchInstanceSourceConfig
+from sweagent.run.batch_instances import BatchInstance, BatchInstanceSourceConfig, SWEBenchInstances
from sweagent.run.common import BasicCLI, save_predictions
from sweagent.run.hooks.abstract import CombinedRunHooks, RunHook
from sweagent.run.hooks.apply_patch import SaveApplyPatchHook
@@ -148,7 +148,7 @@ class RunBatch:
)
raise ValueError(msg)
logger.debug("The first instance is %s", f"{instances[0]!r}")
- return cls(
+ rb = cls(
instances=instances,
agent_config=config.agent,
output_dir=config.output_dir,
@@ -157,6 +157,15 @@ class RunBatch:
num_workers=config.num_workers,
progress_bar=config.progress_bar,
)
+ if isinstance(config.instances, SWEBenchInstances) and config.instances.evaluate:
+ from sweagent.run.hooks.swe_bench_evaluate import SweBenchEvaluate
+
+ rb.add_hook(
+ SweBenchEvaluate(
+ output_dir=config.output_dir, subset=config.instances.subset, split=config.instances.split
+ )
+ )
+ return rb
def add_hook(self, hook: RunHook) -> None:
hook.on_init(run=self)