Download code/ref15_fullft/rowgroup_plan.py from laion/Humaneness-Voice-Small: direct link, hf CLI and curl.
- Browser
- Download file 1.81 kB
-
https://huggingface.co/laion/Humaneness-Voice-Small/resolve/main/code/ref15_fullft/rowgroup_plan.py
- Command line
-
hf download hf://laion/Humaneness-Voice-Small/code/ref15_fullft/rowgroup_plan.py
-
curl -L -o rowgroup_plan.py https://huggingface.co/laion/Humaneness-Voice-Small/resolve/main/code/ref15_fullft/rowgroup_plan.py
1.81 kB
| """Balance packed Parquet row groups over GPU ranks without duplicating data. | |
| The 128 source shards are *not* equal-sized. Assigning four complete shards | |
| to each of 32 ranks gave the slowest rank ~38.5k steps versus ~28.8k expected, | |
| and left some ranks idle at the tail. Row groups are ~4096 records and can be | |
| partitioned by metadata without creating any per-example files. | |
| """ | |
| from __future__ import annotations | |
| import pyarrow.parquet as pq | |
| from build_worklist import OUT, SHARDS | |
| SAMPLER_VERSION = 'hvs-rowgroup-balance-v1' | |
| def plan(world: int): | |
| assert world > 0 | |
| groups = [] | |
| for shard in range(SHARDS): | |
| metadata = pq.read_metadata(OUT / f'part-{shard:03d}.parquet') | |
| for group in range(metadata.num_row_groups): | |
| n = metadata.row_group(group).num_rows | |
| if n: | |
| groups.append((n, shard, group)) | |
| assignments = [[] for _ in range(world)] | |
| loads = [0] * world | |
| for n, shard, group in sorted(groups, key=lambda x: (-x[0], x[1], x[2])): | |
| rank = min(range(world), key=lambda r: (loads[r], r)) | |
| assignments[rank].append((shard, group)) | |
| loads[rank] += n | |
| assert sum(loads) == sum(n for n, _, _ in groups) | |
| assert len({item for rank_groups in assignments for item in rank_groups}) == len(groups) | |
| return assignments, loads | |
| def read_rank_rows(rank: int, world: int): | |
| assignments, loads = plan(world) | |
| by_shard = {} | |
| for shard, group in assignments[rank]: | |
| by_shard.setdefault(shard, []).append(group) | |
| rows = [] | |
| for shard, groups in sorted(by_shard.items()): | |
| source = pq.ParquetFile(OUT / f'part-{shard:03d}.parquet') | |
| for group in groups: | |
| rows.extend(source.read_row_group(group).to_pylist()) | |
| assert len(rows) == loads[rank] | |
| return rows, loads | |