gsarch's picture
Add the Persistent Exploration VisualProbe training set
f423317 verified
Raw History Blame Contribute Delete
2.64 kB
#!/usr/bin/env python3
"""Restore portable VERL JSONL and original JPEGs from a downloaded dataset release."""
import argparse
import json
from pathlib import Path
from tempfile import TemporaryDirectory
import pyarrow.parquet as pq
CONFIG = "counting_grounding_search-visual_probe"
TRAIN_FILENAME = "chart_search_counting_visual_probe_train_rollout_score_leq05_all.verl.jsonl"
def training_row(row, image_path):
prompt = row["prompt"]
return {
"data_source": row["data_source"],
"prompt": [dict(role=role, content=text) for role, text in zip(prompt["role"], prompt["content"], strict=True)],
"images": [str(image_path)],
"ability": row["ability"],
"reward_model": row["reward_model"],
"extra_info": row["extra_info"],
"avg_pass_rate": row["avg_pass_rate"],
}
def export(dataset, destination):
shards = sorted((dataset / CONFIG).glob("train-*.parquet"))
if not shards:
raise ValueError(f"No training shards in {dataset / CONFIG}")
destination = destination.resolve()
if destination.exists():
raise FileExistsError(f"Choose a new output directory: {destination}")
destination.parent.mkdir(parents=True, exist_ok=True)
count = 0
with TemporaryDirectory(dir=destination.parent) as tmp:
stage = Path(tmp) / "dataset"
images = stage / "images"
images.mkdir(parents=True)
with (stage / TRAIN_FILENAME).open("w", encoding="utf-8") as out:
for shard in shards:
for batch in pq.ParquetFile(shard).iter_batches(batch_size=8):
for row in batch.to_pylist():
image = row["image"]
filename = image["path"]
if Path(filename).name != filename or filename != row["id"] + ".jpg":
raise ValueError(f"Unexpected JPEG name: {filename}")
with (images / filename).open("xb") as file:
file.write(image["bytes"])
native = training_row(row, destination / "images" / filename)
out.write(json.dumps(native, ensure_ascii=False) + "\n")
count += 1
if count != 2042:
raise ValueError(f"Expected 2042 training rows, got {count}")
stage.rename(destination)
return destination / TRAIN_FILENAME
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("output", type=Path)
args = parser.parse_args()
print(export(Path(__file__).resolve().parent, args.output))