Download code/_bw2.py from ThuongBuiRVC/datariengcuathuongbui: direct link, hf CLI and curl.
- Browser
- Download file 1.35 kB
-
https://huggingface.co/datasets/ThuongBuiRVC/datariengcuathuongbui/resolve/main/code/_bw2.py
- Command line
-
hf download hf://datasets/ThuongBuiRVC/datariengcuathuongbui/code/_bw2.py
-
curl -L -o _bw2.py https://huggingface.co/datasets/ThuongBuiRVC/datariengcuathuongbui/resolve/main/code/_bw2.py
1.35 kB
| import os, time, requests, random | |
| from concurrent.futures import ThreadPoolExecutor | |
| ents = open('/home/db/ThuongBui/localization/vlr/val_entries.txt').read().split() | |
| s = requests.Session(); s.headers['Authorization'] = 'Bearer ' + os.environ['HF_TOKEN'] | |
| def cdn(e): | |
| r = s.get(f'https://huggingface.co/datasets/nureasoning/nuReasoning/resolve/main/data/{e}.tar', headers={'Range': 'bytes=0-0'}, allow_redirects=False, timeout=60) | |
| return r.headers['Location'] | |
| def pull(e, n=150 << 20): | |
| u = cdn(e); got = 0 | |
| with requests.get(u, headers={'Range': f'bytes=0-{n-1}'}, stream=True, timeout=60) as r: | |
| for ch in r.iter_content(1 << 20): | |
| got += len(ch) | |
| return got | |
| t = time.time() | |
| with ThreadPoolExecutor(24) as p: | |
| g = sum(p.map(pull, ents[20:44])) | |
| print('24 streams total MB/s', round(g / 1e6 / (time.time() - t), 1)) | |
| us = [cdn(e) for e in ents[50:114]] | |
| local = __import__('threading').local() | |
| def small(i): | |
| if not hasattr(local, 's'): local.s = requests.Session() | |
| u = us[i % 64]; o = random.randrange(0, 2 << 30) | |
| return len(local.s.get(u, headers={'Range': f'bytes={o}-{o+4095}'}, timeout=60).content) | |
| for c in (64, 192): | |
| t = time.time() | |
| with ThreadPoolExecutor(c) as p: | |
| list(p.map(small, range(c * 8))) | |
| print(c, 'concurrent 4KB requests/s', round(c * 8 / (time.time() - t), 1)) | |