File size: 2,864 Bytes
2af6df2
 
05fecb0
 
 
 
 
 
 
2af6df2
 
05fecb0
2af6df2
 
 
 
 
 
 
 
 
 
 
05fecb0
2af6df2
 
 
 
 
 
 
 
 
05fecb0
2af6df2
 
 
05fecb0
 
 
 
 
 
 
 
 
 
 
 
 
 
2af6df2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""Stage 0: guarded clean command -- start the destination dataset from scratch.

Deletes generated files from the destination repo. Guarded: does nothing unless
CONFIRM_WIPE=1. Flags:
  WIPE_BANNED_LIST=1  also delete _banned/ (the tiered list)
  WIPE_STRIPPED=1     also delete the footer-stripped layer (stripped/, strip_*)

By default a wipe removes the FINAL filter outputs (shards/stats/hits/report) but
KEEPS the stripped layer, so you can re-run just the filter without re-stripping.

Run:  CONFIRM_WIPE=1 python scripts/wipe.py
      CONFIRM_WIPE=1 WIPE_STRIPPED=1 WIPE_BANNED_LIST=1 python scripts/wipe.py
"""
import os
import re

from huggingface_hub import CommitOperationDelete

import config
from common import api, ensure_dst_repo, list_repo_files_safe

CONFIRM_WIPE = os.environ.get("CONFIRM_WIPE", "0") == "1"
WIPE_BANNED_LIST = os.environ.get("WIPE_BANNED_LIST", "0") == "1"
WIPE_STRIPPED = os.environ.get("WIPE_STRIPPED", "0") == "1"


def main():
    ensure_dst_repo()
    if not CONFIRM_WIPE:
        print("CONFIRM_WIPE not set; leaving destination repo untouched.")
        print("Re-run with  CONFIRM_WIPE=1 python scripts/wipe.py  to delete generated files.")
        return

    strip_pref = config.STRIP_PREFIX.rstrip("/") + "/"
    files = list_repo_files_safe(config.DST_REPO)
    delete_paths = []
    for path in files:
        # Stripped layer + its sidecars are gated behind WIPE_STRIPPED.
        is_stripped = (
            path.startswith(strip_pref)
            or path.startswith("strip_stats/")
            or path.startswith("strip_samples/")
        )
        if is_stripped:
            if WIPE_STRIPPED:
                delete_paths.append(path)
            continue
        # Final filter outputs (at repo root).
        is_shard = re.match(r"^shard_\d+\.parquet$", path) is not None
        is_stat = re.match(r"^stats/shard_\d+\.json$", path) is not None
        is_hits = re.match(r"^hits/shard_\d+\.jsonl$", path) is not None
        is_report = path == "cleaning_report_1930s.json"
        is_banned = path.startswith("_banned/") if WIPE_BANNED_LIST else False
        if is_shard or is_stat or is_hits or is_report or is_banned:
            delete_paths.append(path)

    if not delete_paths:
        print("No generated files found to delete.")
        return

    print(f"Deleting {len(delete_paths):,} generated files from {config.DST_REPO}...")
    for start in range(0, len(delete_paths), 100):
        batch = delete_paths[start:start + 100]
        api.create_commit(
            repo_id=config.DST_REPO, repo_type="dataset",
            operations=[CommitOperationDelete(path_in_repo=p) for p in batch],
            commit_message=f"wipe generated 1930s outputs {start // 100 + 1}",
        )
        print(f"  deleted {start + len(batch):,}/{len(delete_paths):,}")


if __name__ == "__main__":
    main()