Datasets:
Commit ·
d9a31e2
1
Parent(s): 73a7963
Add launcher for parallel HPLT filtering
Browse files- src/launch_hplt_parallel.py +85 -0
src/launch_hplt_parallel.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Launch parallel European HPLT filtering workers.
|
| 3 |
+
|
| 4 |
+
The filter itself is intentionally single-process and shard-safe. This launcher
|
| 5 |
+
splits the actual HF train parquet file list across workers and starts each
|
| 6 |
+
worker in a detached screen session with its own output directory and log.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
import argparse
|
| 12 |
+
import subprocess
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
|
| 15 |
+
from huggingface_hub import list_repo_files
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def parse_args() -> argparse.Namespace:
|
| 19 |
+
ap = argparse.ArgumentParser()
|
| 20 |
+
ap.add_argument("--repo-id", default="ashtok897/european-hplt-v1")
|
| 21 |
+
ap.add_argument("--workers", type=int, default=4)
|
| 22 |
+
ap.add_argument("--out-dir", type=Path, default=Path("data/european_hplt_pl_parallel"))
|
| 23 |
+
ap.add_argument("--log-dir", type=Path, default=Path("logs"))
|
| 24 |
+
ap.add_argument("--screen-prefix", default="hplt")
|
| 25 |
+
ap.add_argument("--target-total-tokens", type=int, default=500_000_000)
|
| 26 |
+
ap.add_argument("--max-records-per-worker", type=int, default=200_000)
|
| 27 |
+
ap.add_argument("--shard-records", type=int, default=25_000)
|
| 28 |
+
ap.add_argument("--shard-tokens", type=int, default=25_000_000)
|
| 29 |
+
ap.add_argument("--progress-every", type=int, default=100_000)
|
| 30 |
+
ap.add_argument("--dry-run", action="store_true")
|
| 31 |
+
return ap.parse_args()
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def main() -> None:
|
| 35 |
+
args = parse_args()
|
| 36 |
+
if args.workers < 1:
|
| 37 |
+
raise SystemExit("--workers must be >= 1")
|
| 38 |
+
|
| 39 |
+
files = sorted(
|
| 40 |
+
path
|
| 41 |
+
for path in list_repo_files(args.repo_id, repo_type="dataset")
|
| 42 |
+
if path.startswith("data/train/") and path.endswith(".parquet")
|
| 43 |
+
)
|
| 44 |
+
if not files:
|
| 45 |
+
raise SystemExit(f"No train parquet files found in {args.repo_id}")
|
| 46 |
+
|
| 47 |
+
args.out_dir.mkdir(parents=True, exist_ok=True)
|
| 48 |
+
args.log_dir.mkdir(parents=True, exist_ok=True)
|
| 49 |
+
target_tokens = max(1, args.target_total_tokens // args.workers)
|
| 50 |
+
|
| 51 |
+
chunks = [files[idx:: args.workers] for idx in range(args.workers)]
|
| 52 |
+
print(f"repo={args.repo_id} train_files={len(files)} workers={args.workers}")
|
| 53 |
+
for worker, chunk in enumerate(chunks):
|
| 54 |
+
if not chunk:
|
| 55 |
+
continue
|
| 56 |
+
out_dir = args.out_dir / f"worker_{worker}"
|
| 57 |
+
out_dir.mkdir(parents=True, exist_ok=True)
|
| 58 |
+
log_path = args.log_dir / f"filter_european_hplt_{args.screen_prefix}_w{worker}.log"
|
| 59 |
+
data_files = ",".join(chunk)
|
| 60 |
+
cmd = (
|
| 61 |
+
"python3 src/filter_european_hplt.py "
|
| 62 |
+
f"--repo-id {args.repo_id} "
|
| 63 |
+
f"--data-files '{data_files}' "
|
| 64 |
+
f"--out-dir '{out_dir}' "
|
| 65 |
+
f"--source-name european_hplt_pl_w{worker} "
|
| 66 |
+
f"--max-records {args.max_records_per_worker} "
|
| 67 |
+
f"--max-tokens {target_tokens} "
|
| 68 |
+
f"--shard-records {args.shard_records} "
|
| 69 |
+
f"--shard-tokens {args.shard_tokens} "
|
| 70 |
+
f"--progress-every {args.progress_every} "
|
| 71 |
+
f"> '{log_path}' 2>&1"
|
| 72 |
+
)
|
| 73 |
+
print(
|
| 74 |
+
f"worker_{worker}: files={len(chunk)} target_tokens={target_tokens:,} "
|
| 75 |
+
f"first={chunk[0]} last={chunk[-1]} log={log_path}"
|
| 76 |
+
)
|
| 77 |
+
if not args.dry_run:
|
| 78 |
+
subprocess.run(
|
| 79 |
+
["screen", "-dmS", f"{args.screen_prefix}_w{worker}", "zsh", "-lc", cmd],
|
| 80 |
+
check=True,
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
if __name__ == "__main__":
|
| 85 |
+
main()
|