File size: 2,136 Bytes
3650c7a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Materialize the flat language-shard view expected by DynamicWAM training."""

from __future__ import annotations

import argparse
import os
from pathlib import Path


def main() -> None:
    parser = argparse.ArgumentParser(
        description=(
            "Create flat lang/shards/shard_* links from the Hub-safe bucketed "
            "layout. The operation is idempotent and does not duplicate payload data."
        )
    )
    parser.add_argument(
        "dataset_root",
        type=Path,
        help="Path to the downloaded dynamicwam_wo_motion directory",
    )
    parser.add_argument(
        "--mode",
        choices=("symlink", "hardlink"),
        default="symlink",
        help="Link type for the flat compatibility view (default: symlink)",
    )
    args = parser.parse_args()

    dataset_root = args.dataset_root.resolve()
    shard_root = dataset_root / "lang" / "shards"
    bucket_directories = sorted(path for path in shard_root.glob("bucket_*") if path.is_dir())
    if not bucket_directories:
        raise FileNotFoundError(f"No bucket directories found under {shard_root}")

    created = 0
    existing = 0
    for bucket in bucket_directories:
        for source in sorted(path for path in bucket.iterdir() if path.is_file()):
            destination = shard_root / source.name
            if destination.exists() or destination.is_symlink():
                try:
                    same_file = destination.samefile(source)
                except FileNotFoundError:
                    same_file = False
                if not same_file:
                    raise RuntimeError(f"Conflicting compatibility path: {destination}")
                existing += 1
                continue
            if args.mode == "symlink":
                destination.symlink_to(Path(bucket.name) / source.name)
            else:
                os.link(source, destination)
            created += 1

    print(
        f"Materialized flat language-shard view: created={created}, "
        f"already_present={existing}, total={created + existing}"
    )


if __name__ == "__main__":
    main()