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]
Enh: Flag to shuffle instances
Kilian Lieretb1e9288a4679
diff --git a/sweagent/run/batch_instances.py b/sweagent/run/batch_instances.pyindex 90a31004..6a3505d7 100644--- a/sweagent/run/batch_instances.py+++ b/sweagent/run/batch_instances.py@@ -1,4 +1,5 @@import json+import randomimport refrom abc import ABC, abstractmethodfrom pathlib import Path@@ -74,7 +75,12 @@ def _slice_spec_to_slice(slice_spec: str) -> slice:raise ValueError(msg)-def _filter_batch_items(instances: list[BatchInstance], *, filter_: str, slice_: str = "") -> list[BatchInstance]:+def _filter_batch_items(+ instances: list[BatchInstance], *, filter_: str, slice_: str = "", shuffle: bool = False+) -> list[BatchInstance]:+ if shuffle:+ instances = instances.copy()+ random.shuffle(instances)before_filter = len(instances)instances = [instance for instance in instances if re.match(filter_, instance.problem_statement.id)]after_filter = len(instances)@@ -158,6 +164,8 @@ class InstancesFromFile(BaseModel, AbstractInstanceSource):Possible values are stop or start:stop or start:stop:step(i.e., it behaves exactly like python's list slicing `list[slice]`)."""+ shuffle: bool = False+ """Shuffle the instances (before filtering and slicing)."""deployment: DeploymentConfig = Field(default_factory=lambda: DockerDeploymentConfig(image="sweagent/swe-agent:latest")@@ -174,7 +182,7 @@ class InstancesFromFile(BaseModel, AbstractInstanceSource):instance_dicts = _load_file(self.path)simple_instances = [SimpleBatchInstance.model_validate(instance_dict) for instance_dict in instance_dicts]instances = [instance.to_full_batch_instance(self.deployment) for instance in simple_instances]- return _filter_batch_items(instances, filter_=self.filter, slice_=self.slice)+ return _filter_batch_items(instances, filter_=self.filter, slice_=self.slice, shuffle=self.shuffle)@propertydef id(self) -> str:@@ -193,6 +201,8 @@ class InstancesFromHuggingFace(BaseModel, AbstractInstanceSource):Possible values are stop or start:stop or start:stop:step.(i.e., it behaves exactly like python's list slicing `list[slice]`)."""+ shuffle: bool = False+ """Shuffle the instances (before filtering and slicing)."""deployment: DeploymentConfig = Field(default_factory=lambda: DockerDeploymentConfig(image="sweagent/swe-agent:latest")@@ -208,7 +218,7 @@ class InstancesFromHuggingFace(BaseModel, AbstractInstanceSource):ds: list[dict[str, Any]] = load_dataset(self.dataset_name, split=self.split) # type: ignoresimple_instances: list[SimpleBatchInstance] = [SimpleBatchInstance.model_validate(instance) for instance in ds]instances = [instance.to_full_batch_instance(self.deployment) for instance in simple_instances]- return _filter_batch_items(instances, filter_=self.filter, slice_=self.slice)+ return _filter_batch_items(instances, filter_=self.filter, slice_=self.slice, shuffle=self.shuffle)@propertydef id(self) -> str:@@ -238,6 +248,8 @@ class SWEBenchInstances(BaseModel, AbstractInstanceSource):Possible values are stop or start:stop or start:stop:step.(i.e., it behaves exactly like python's list slicing `list[slice]`)."""+ shuffle: bool = False+ """Shuffle the instances (before filtering and slicing)."""def _get_huggingface_name(self) -> str:if self.flavor == "full":@@ -256,7 +268,7 @@ class SWEBenchInstances(BaseModel, AbstractInstanceSource):instances = [SimpleBatchInstance.from_swe_bench(instance).to_full_batch_instance(self.deployment) for instance in ds]- return _filter_batch_items(instances, filter_=self.filter, slice_=self.slice)+ return _filter_batch_items(instances, filter_=self.filter, slice_=self.slice, shuffle=self.shuffle)@propertydef id(self) -> str:@@ -276,6 +288,8 @@ class ExpertInstancesFromFile(BaseModel, AbstractInstanceSource):Possible values are stop or start:stop or start:stop:step.(i.e., it behaves exactly like python's list slicing `list[slice]`)."""+ shuffle: bool = False+ """Shuffle the instances (before filtering and slicing)."""type: Literal["expert_file"] = "expert_file""""Discriminator for (de)serialization/CLI. Do not change."""@@ -283,7 +297,7 @@ class ExpertInstancesFromFile(BaseModel, AbstractInstanceSource):def get_instance_configs(self) -> list[BatchInstance]:instance_dicts = _load_file(self.path)instances = [BatchInstance.model_validate(instance_dict) for instance_dict in instance_dicts]- return _filter_batch_items(instances, filter_=self.filter, slice_=self.slice)+ return _filter_batch_items(instances, filter_=self.filter, slice_=self.slice, shuffle=self.shuffle)@propertydef id(self) -> str: