ASKabalan's picture
Squash history (post parquet re-encode)
8b829ee
|
Raw
History Blame Contribute Delete
3.4 kB
# tools — HF dataset maintenance scripts
Bookkeeping copies of the scripts used to maintain the HuggingFace dataset
`ASKabalan/jax-fli-experiments` (this repo is a local clone of it). These tools
are **not** part of the dataset itself — they're versioned here for reference.
Run with `uv` so deps are available, e.g.
`uv run --with pyarrow --with huggingface_hub python3 tools/<script>.py`.
## reencode_parquet.py — probe / dry-run / re-encode parquet (dictionary + codec)
Losslessly re-encodes parquet to dictionary + a chosen codec to shrink it. Data
is preserved **bit-for-bit** (verified per file: full-table `equals` + the
`huggingface` schema metadata + the `array` column's Array2D extension metadata),
so `load_dataset` features and config bundling are unaffected.
`PATH` may be a single `.parquet` file **or** a folder (recursed for `**/*.parquet`).
Three modes (positional):
| mode | verifies | writes in place | what it's for |
|------------|----------|-----------------|--------------------------------------------|
| `probe` | no | no | just measure & print the size table |
| `dryrun` | yes | no | full safe pipeline, report would-change |
| `reencode` | yes | yes (if >2% win)| actually shrink files in place |
`reencode` is atomic (temp + `os.replace`) and idempotent — files already
dictionary-encoded in the target codec are skipped, so a run is resumable.
```bash
cd /home/wassim/Projects/NBody/jax-fli-experiments
uv run --with pyarrow python3 tools/reencode_parquet.py probe 06-cosmogrid-shells
uv run --with pyarrow python3 tools/reencode_parquet.py dryrun 06-cosmogrid-shells --codec ZSTD
uv run --with pyarrow python3 tools/reencode_parquet.py reencode 06-cosmogrid-shells
```
`--codec` defaults to `SNAPPY` (pyarrow's default; what the dataset already uses).
Every mode ends with a per-file + per-folder + grand-total table of
current / uncompressed / target / savings sizes.
After `reencode`, commit + push (one commit) from the clone:
```bash
git add -A && git commit -m "Re-encode parquet to dictionary+<codec> (lossless)"
git -c credential.helper='!f(){ echo username=ASKabalan; echo "password=$HF_TOKEN"; }; f' push origin main
git lfs prune # reclaim local .git/lfs space from the old (now unreferenced) objects
```
## squash_hf_history.py — reclaim HF storage after re-encoding
Re-encoding + push makes downloads smaller, but the **old uncompressed LFS blobs
stay referenced by the old commits**, so HF keeps billing for them. This collapses
the whole remote history into one commit so HF can GC the old blobs (storage drops
to ~HEAD size).
**Irreversible on the remote — destroys all commit history.** The script always
takes a local `git bundle --all` backup first (written next to the script), and
only squashes with `--yes`.
```bash
# backup + dry-run
uv run --with huggingface_hub python3 tools/squash_hf_history.py REPO_ID LOCAL_CLONE
# actually squash
uv run --with huggingface_hub python3 tools/squash_hf_history.py REPO_ID LOCAL_CLONE --yes
# then re-align the local clone:
git -C LOCAL_CLONE fetch origin && git -C LOCAL_CLONE reset --hard origin/main
```
`REPO_ID` e.g. `ASKabalan/jax-fli-experiments`; `LOCAL_CLONE` is the local git
clone path (used only for the safety bundle). Needs `HF_TOKEN` (write) in the env.