Update README.md
Browse files
README.md
CHANGED
@@ -48,3 +48,180 @@ configs:
|
|
48 |
- split: test
|
49 |
path: problem_files/test-*
|
50 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
- split: test
|
49 |
path: problem_files/test-*
|
50 |
---
|
51 |
+
|
52 |
+
# SWE-Bench Verified
|
53 |
+
|
54 |
+
|
55 |
+
|
56 |
+
```python
|
57 |
+
import argparse
|
58 |
+
from dataclasses import dataclass, asdict
|
59 |
+
import datasets
|
60 |
+
from pathlib import Path
|
61 |
+
import subprocess
|
62 |
+
from typing import Dict, List
|
63 |
+
|
64 |
+
import tqdm
|
65 |
+
|
66 |
+
from datasets import Dataset
|
67 |
+
|
68 |
+
import hashlib
|
69 |
+
|
70 |
+
from dataclasses import dataclass
|
71 |
+
|
72 |
+
|
73 |
+
@dataclass
|
74 |
+
class CodebaseFile:
|
75 |
+
path: str
|
76 |
+
content: str
|
77 |
+
|
78 |
+
|
79 |
+
class SWEBenchProblem:
|
80 |
+
def __init__(self, row):
|
81 |
+
self._row = row
|
82 |
+
|
83 |
+
@property
|
84 |
+
def repo(self) -> str:
|
85 |
+
return self._row["repo"]
|
86 |
+
|
87 |
+
@property
|
88 |
+
def base_commit(self) -> str:
|
89 |
+
return self._row["base_commit"]
|
90 |
+
|
91 |
+
|
92 |
+
@property
|
93 |
+
def instance_id(self) -> str:
|
94 |
+
return self._row["instance_id"]
|
95 |
+
|
96 |
+
VALID_EXTENSIONS = {"py"}
|
97 |
+
|
98 |
+
|
99 |
+
def hash_file_content(file_content: str) -> str:
|
100 |
+
return hashlib.sha256(file_content.encode()).hexdigest()
|
101 |
+
|
102 |
+
|
103 |
+
@dataclass
|
104 |
+
class FileInCodebase:
|
105 |
+
file_path: str
|
106 |
+
content_hash: str
|
107 |
+
|
108 |
+
|
109 |
+
@dataclass
|
110 |
+
class CodebaseContent:
|
111 |
+
instance_id: str
|
112 |
+
files: List[FileInCodebase]
|
113 |
+
|
114 |
+
|
115 |
+
def clone_repos(problems: list[SWEBenchProblem], repos_dir: Path):
|
116 |
+
repos_dir.mkdir(exist_ok=False, parents=True)
|
117 |
+
|
118 |
+
if len(list(repos_dir.iterdir())):
|
119 |
+
raise ValueError("Repos dir should be empty")
|
120 |
+
|
121 |
+
repos = {problem.repo for problem in problems}
|
122 |
+
for repo in tqdm.tqdm(repos, desc="Cloning repos"):
|
123 |
+
output = subprocess.run(
|
124 |
+
["git", "clone", f"https://github.com/{repo}.git"],
|
125 |
+
cwd=repos_dir,
|
126 |
+
capture_output=True,
|
127 |
+
)
|
128 |
+
assert output.returncode == 0
|
129 |
+
|
130 |
+
|
131 |
+
def get_codebase_content(
|
132 |
+
problem: SWEBenchProblem, repos_dir: Path, hash_to_content: Dict[str, str]
|
133 |
+
) -> CodebaseContent:
|
134 |
+
repo = problem.repo.split("/")[-1]
|
135 |
+
repo_path = repos_dir / repo
|
136 |
+
|
137 |
+
subprocess.run(
|
138 |
+
["git", "checkout", problem.base_commit], cwd=repo_path, capture_output=True
|
139 |
+
)
|
140 |
+
|
141 |
+
contexts = []
|
142 |
+
|
143 |
+
for file_path in repo_path.rglob("*"):
|
144 |
+
if not file_path.is_file:
|
145 |
+
continue
|
146 |
+
|
147 |
+
if file_path.suffix[1:] not in VALID_EXTENSIONS: # [1:] excludes the '.'
|
148 |
+
continue
|
149 |
+
|
150 |
+
try:
|
151 |
+
content = file_path.read_text()
|
152 |
+
except UnicodeDecodeError:
|
153 |
+
# Ignore these files.
|
154 |
+
continue
|
155 |
+
|
156 |
+
content_hash = hash_file_content(content)
|
157 |
+
if content_hash not in hash_to_content:
|
158 |
+
hash_to_content[content_hash] = content
|
159 |
+
|
160 |
+
contexts.append(
|
161 |
+
FileInCodebase(
|
162 |
+
file_path=str(file_path.relative_to(repo_path)),
|
163 |
+
content_hash=content_hash,
|
164 |
+
)
|
165 |
+
)
|
166 |
+
|
167 |
+
return CodebaseContent(instance_id=problem.instance_id, files=contexts)
|
168 |
+
|
169 |
+
|
170 |
+
@dataclass
|
171 |
+
class ContentDatasetElement:
|
172 |
+
hash: str
|
173 |
+
content: str
|
174 |
+
|
175 |
+
|
176 |
+
def main():
|
177 |
+
parser = argparse.ArgumentParser()
|
178 |
+
parser.add_argument(
|
179 |
+
"--repo_directory",
|
180 |
+
type=Path,
|
181 |
+
default=Path("/scr/ryanehrlich/swebench_verified_repos"),
|
182 |
+
)
|
183 |
+
parser.add_argument(
|
184 |
+
"--output_dataset_name",
|
185 |
+
type=str,
|
186 |
+
default="ScalingIntelligence/swe-bench-verified-codebase-content-staging",
|
187 |
+
)
|
188 |
+
|
189 |
+
args = parser.parse_args()
|
190 |
+
|
191 |
+
dataset = datasets.load_dataset("princeton-nlp/SWE-bench_Verified", split="test")
|
192 |
+
problems = [SWEBenchProblem(row) for row in dataset]
|
193 |
+
|
194 |
+
clone_repos(problems, args.repo_directory)
|
195 |
+
hash_to_content = {}
|
196 |
+
codebase_content_per_problem = [
|
197 |
+
get_codebase_content(problem, args.repo_directory, hash_to_content)
|
198 |
+
for problem in tqdm.tqdm(problems, desc="Fetching codebase content")
|
199 |
+
]
|
200 |
+
|
201 |
+
hash_to_content_in_hf_form = [
|
202 |
+
{
|
203 |
+
"hash": hash_,
|
204 |
+
"content": content,
|
205 |
+
}
|
206 |
+
for (hash_, content) in hash_to_content.items()
|
207 |
+
]
|
208 |
+
|
209 |
+
codebase_content_in_hf_form = [
|
210 |
+
asdict(problem) for problem in codebase_content_per_problem
|
211 |
+
]
|
212 |
+
|
213 |
+
file_content_dataset = Dataset.from_list(hash_to_content_in_hf_form, split="test")
|
214 |
+
problems_dataset = Dataset.from_list(codebase_content_in_hf_form, split="test")
|
215 |
+
|
216 |
+
file_content_dataset.push_to_hub(
|
217 |
+
args.output_dataset_name, "file_content", private=True, max_shard_size="256MB"
|
218 |
+
)
|
219 |
+
problems_dataset.push_to_hub(
|
220 |
+
args.output_dataset_name, "problem_files", private=True, max_shard_size="256MB"
|
221 |
+
)
|
222 |
+
|
223 |
+
|
224 |
+
if __name__ == "__main__":
|
225 |
+
main()
|
226 |
+
```
|
227 |
+
|