Datasets:
Download src/launch_hplt_parallel.py from SlayerLab/polish-dynaword: direct link, hf CLI and curl.
- Browser
- Download file 3.31 kB
-
https://huggingface.co/datasets/SlayerLab/polish-dynaword/resolve/503c9db5d79c4b2f7fb9ebbfb40bfd3b679e2526/src/launch_hplt_parallel.py
- Command line
-
hf download hf://datasets/SlayerLab/polish-dynaword@503c9db5d79c4b2f7fb9ebbfb40bfd3b679e2526/src/launch_hplt_parallel.py
-
curl -L -o launch_hplt_parallel.py https://huggingface.co/datasets/SlayerLab/polish-dynaword/resolve/503c9db5d79c4b2f7fb9ebbfb40bfd3b679e2526/src/launch_hplt_parallel.py
3.31 kB
| #!/usr/bin/env python3 | |
| """Launch parallel European HPLT filtering workers. | |
| The filter itself is intentionally single-process and shard-safe. This launcher | |
| splits the actual HF train parquet file list across workers and starts each | |
| worker in a detached screen session with its own output directory and log. | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import subprocess | |
| from pathlib import Path | |
| from huggingface_hub import list_repo_files | |
| def parse_args() -> argparse.Namespace: | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--repo-id", default="ashtok897/european-hplt-v1") | |
| ap.add_argument("--workers", type=int, default=4) | |
| ap.add_argument("--out-dir", type=Path, default=Path("data/european_hplt_pl_parallel")) | |
| ap.add_argument("--log-dir", type=Path, default=Path("logs")) | |
| ap.add_argument("--screen-prefix", default="hplt") | |
| ap.add_argument("--target-total-tokens", type=int, default=500_000_000) | |
| ap.add_argument("--max-records-per-worker", type=int, default=200_000) | |
| ap.add_argument("--shard-records", type=int, default=25_000) | |
| ap.add_argument("--shard-tokens", type=int, default=25_000_000) | |
| ap.add_argument("--progress-every", type=int, default=100_000) | |
| ap.add_argument("--dry-run", action="store_true") | |
| return ap.parse_args() | |
| def main() -> None: | |
| args = parse_args() | |
| if args.workers < 1: | |
| raise SystemExit("--workers must be >= 1") | |
| files = sorted( | |
| path | |
| for path in list_repo_files(args.repo_id, repo_type="dataset") | |
| if path.startswith("data/train/") and path.endswith(".parquet") | |
| ) | |
| if not files: | |
| raise SystemExit(f"No train parquet files found in {args.repo_id}") | |
| args.out_dir.mkdir(parents=True, exist_ok=True) | |
| args.log_dir.mkdir(parents=True, exist_ok=True) | |
| target_tokens = max(1, args.target_total_tokens // args.workers) | |
| chunks = [files[idx:: args.workers] for idx in range(args.workers)] | |
| print(f"repo={args.repo_id} train_files={len(files)} workers={args.workers}") | |
| for worker, chunk in enumerate(chunks): | |
| if not chunk: | |
| continue | |
| out_dir = args.out_dir / f"worker_{worker}" | |
| out_dir.mkdir(parents=True, exist_ok=True) | |
| log_path = args.log_dir / f"filter_european_hplt_{args.screen_prefix}_w{worker}.log" | |
| data_files = ",".join(chunk) | |
| cmd = ( | |
| "python3 src/filter_european_hplt.py " | |
| f"--repo-id {args.repo_id} " | |
| f"--data-files '{data_files}' " | |
| f"--out-dir '{out_dir}' " | |
| f"--source-name european_hplt_pl_w{worker} " | |
| f"--max-records {args.max_records_per_worker} " | |
| f"--max-tokens {target_tokens} " | |
| f"--shard-records {args.shard_records} " | |
| f"--shard-tokens {args.shard_tokens} " | |
| f"--progress-every {args.progress_every} " | |
| f"> '{log_path}' 2>&1" | |
| ) | |
| print( | |
| f"worker_{worker}: files={len(chunk)} target_tokens={target_tokens:,} " | |
| f"first={chunk[0]} last={chunk[-1]} log={log_path}" | |
| ) | |
| if not args.dry_run: | |
| subprocess.run( | |
| ["screen", "-dmS", f"{args.screen_prefix}_w{worker}", "zsh", "-lc", cmd], | |
| check=True, | |
| ) | |
| if __name__ == "__main__": | |
| main() | |