Download code/vlr_hub_index.py from ThuongBuiRVC/datariengcuathuongbui: direct link, hf CLI and curl.
- Browser
- Download file 3.51 kB
-
https://huggingface.co/datasets/ThuongBuiRVC/datariengcuathuongbui/resolve/main/code/vlr_hub_index.py
- Command line
-
hf download hf://datasets/ThuongBuiRVC/datariengcuathuongbui/code/vlr_hub_index.py
-
curl -L -o vlr_hub_index.py https://huggingface.co/datasets/ThuongBuiRVC/datariengcuathuongbui/resolve/main/code/vlr_hub_index.py
3.51 kB
| """Tar member tables (name -> [data offset, size]) of nuReasoning Hub clips, so later fetches read only the wanted | |
| members with HTTP Range requests. One 4 KB Range request per tar header (fetch_clips.tar_index), cached as | |
| <NUR_WORK>/tar_index/<entry>.json; existing tables are skipped. | |
| --list validation writes the entries of data/validation/* (Hub listing) to --entries first | |
| --list supplement writes the entries of the db supplement clips (their _acquisition.json path) | |
| Run (db): HF_TOKEN=... NUR_WORK=/mnt/10TB_HDD/nuReasoning/vljepa_testmatch/hub_tar_index \ | |
| python vlr_hub_index.py --list validation --entries val_entries.txt --workers 24 | |
| """ | |
| import argparse | |
| import json | |
| import os | |
| import sys | |
| import time | |
| from concurrent.futures import ThreadPoolExecutor, as_completed | |
| from pathlib import Path | |
| import requests | |
| sys.path.insert(0, '/home/db/ThuongBui/localization/vljepa_testmatch/tools') | |
| import fetch_clips as fc # noqa: E402 | |
| import paths # noqa: E402 | |
| fc.BLOCK = 1 << 12 | |
| SUPP = Path('/mnt/10TB_HDD/nuReasoning/data_supplement_20261022') | |
| def list_entries(kind): | |
| if kind == 'supplement': | |
| out = [] | |
| for c in sorted(os.listdir(SUPP)): | |
| p = SUPP / c / '_acquisition.json' | |
| if p.is_file(): | |
| out.append(json.loads(p.read_text())['path'][len('data/'):-len('.tar')]) | |
| return out | |
| from huggingface_hub import HfApi | |
| api = HfApi(token=os.environ['HF_TOKEN']) | |
| files = api.list_repo_files('nureasoning/nuReasoning', repo_type='dataset') | |
| pre = f'data/{kind}/' | |
| return sorted(f[len('data/'):-len('.tar')] for f in files if f.startswith(pre) and f.endswith('.tar')) | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument('--entries', required=True); ap.add_argument('--list', default='') | |
| ap.add_argument('--workers', type=int, default=24); ap.add_argument('--limit', type=int, default=0) | |
| a = ap.parse_args() | |
| if a.list: | |
| ents = list_entries(a.list) | |
| Path(a.entries).write_text('\n'.join(ents) + '\n') | |
| print('listed', len(ents), 'entries ->', a.entries, flush=True) | |
| ents = [e for e in Path(a.entries).read_text().split() if e] | |
| todo = [e for e in ents if not (paths.WORK / 'tar_index' / f'{e}.json').is_file()] | |
| if a.limit: | |
| todo = todo[:a.limit] | |
| print(f'{len(ents)} entries, {len(todo)} without a table', flush=True) | |
| sess = requests.Session(); sess.headers['Authorization'] = f'Bearer {os.environ["HF_TOKEN"]}' | |
| t0, done, fail = time.time(), 0, [] | |
| def one(e): | |
| for attempt in range(3): | |
| try: | |
| idx, _ = fc.tar_index(e, sess) | |
| return e, len(idx) | |
| except Exception as ex: # noqa: BLE001 | |
| err = ex | |
| time.sleep(5 * (attempt + 1)) | |
| raise RuntimeError(f'{e}: {err!r}') | |
| with ThreadPoolExecutor(a.workers) as pool: | |
| futs = [pool.submit(one, e) for e in todo] | |
| for f in as_completed(futs): | |
| try: | |
| f.result(); done += 1 | |
| except Exception as ex: # noqa: BLE001 | |
| fail.append(str(ex)[:200]) | |
| if (done + len(fail)) % 50 == 0: | |
| el = time.time() - t0 | |
| print(f'{done} done {len(fail)} failed {el / 60:.1f} min, eta {el / max(done, 1) * (len(todo) - done) / 60:.0f} min', flush=True) | |
| print(f'finished: {done} tables, {len(fail)} failed', flush=True) | |
| for x in fail[:20]: | |
| print('FAIL', x) | |
| if __name__ == '__main__': | |
| main() | |