Download tools/materialize_training_layout.py from KhalilGao/DynamicWAM-data: direct link, hf CLI and curl.
- Browser
- Download file 2.14 kB
-
https://huggingface.co/datasets/KhalilGao/DynamicWAM-data/resolve/main/tools/materialize_training_layout.py
- Command line
-
hf download hf://datasets/KhalilGao/DynamicWAM-data/tools/materialize_training_layout.py
-
curl -L -o materialize_training_layout.py https://huggingface.co/datasets/KhalilGao/DynamicWAM-data/resolve/main/tools/materialize_training_layout.py
2.14 kB
| #!/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() | |