tools/rdna2spirv: balance --shard by file size and fail fast on stat error (OLD-9779) #1261

Closed
leonida/mandy
ambroseautomation wants to merge 0 commits from carry/old-9779-shard-size-balance into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

ambroseautomation commented 2026-11-24 21:01:47 +00:00

Claimed in the coordination issue as: OLD-9779 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7144358109)

What and why

Carries forward old-pr/9779 (draft #57, original commit author pes7 preserved across both commits; indexed in #17), rebased cleanly onto current main (0b45fdc21).

Replaces round-robin files[index::count] sharding in tools/rdna2spirv.py with deterministic size-balanced greedy bucketing (shard_bucket()):

  • Sorts input .asm files largest-first by os.path.getsize and assigns each to the lightest bucket so far, then returns the requested shard's bucket in name order — reducing parallel shader-stage makespan on skewed shader corpora while producing byte-identical output and requiring no inter-process coordination.
  • Fails fast with the failing file path if os.path.getsize raises OSError instead of silently substituting weight 0 (which could cause two shards to disagree on the partition and produce duplicates/holes on merge).
  • Adds tests/test_rdna2spirv_shard.py covering partition completeness/disjointness, cross-process determinism, single-shard passthrough, skewed-corpus balance vs. round-robin, and fail-fast behavior on unreadable file sizes.

Tested

  • python -I tests/test_rdna2spirv_shard.py -v: 5 tests, OK.
  • python -m compileall -q make_game.py tools tests: exit 0.
  • python -I tools/rdna2spirv.py --help: exit 0.
  • python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/test_rdna2spirv_shard.py: exit 0 (no game data).

GPUs tested: n/a (CLI sharding logic + stdlib unit tests on Windows 11 Pro 64-bit, Python 3.12.10)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — CLI sharding only, no codegen changes)
Claimed in the coordination issue as: OLD-9779 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7144358109) ### What and why Carries forward `old-pr/9779` (draft #57, original commit author `pes7` preserved across both commits; indexed in #17), rebased cleanly onto current `main` (`0b45fdc21`). Replaces round-robin `files[index::count]` sharding in `tools/rdna2spirv.py` with deterministic size-balanced greedy bucketing (`shard_bucket()`): - Sorts input `.asm` files largest-first by `os.path.getsize` and assigns each to the lightest bucket so far, then returns the requested shard's bucket in name order — reducing parallel shader-stage makespan on skewed shader corpora while producing byte-identical output and requiring no inter-process coordination. - Fails fast with the failing file path if `os.path.getsize` raises `OSError` instead of silently substituting weight 0 (which could cause two shards to disagree on the partition and produce duplicates/holes on merge). - Adds `tests/test_rdna2spirv_shard.py` covering partition completeness/disjointness, cross-process determinism, single-shard passthrough, skewed-corpus balance vs. round-robin, and fail-fast behavior on unreadable file sizes. ### Tested - `python -I tests/test_rdna2spirv_shard.py -v`: 5 tests, OK. - `python -m compileall -q make_game.py tools tests`: exit 0. - `python -I tools/rdna2spirv.py --help`: exit 0. - `python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/test_rdna2spirv_shard.py`: exit 0 (no game data). GPUs tested: n/a (CLI sharding logic + stdlib unit tests on Windows 11 Pro 64-bit, Python 3.12.10) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a — CLI sharding only, no codegen changes)
tiguan26 approved these changes 2026-11-25 06:27:00 +00:00
tiguan26 left a comment

Approving. Merged into current main (42537e7) with no conflicts. tests/test_rdna2spirv_shard.py passes (5 passed), and the full translator suite gives 487 files / 6,279 tests with only test_int32_to_f64 failing, as on main here (Linux, Python 3.13).

The partition is deterministic: largest first, ties broken by path, each file to the lightest bucket with ties broken by index. So every shard derives the same buckets and together they cover each file exactly once. Refusing on an unreadable size, rather than weighting it 0, is the right call for the reason the comment gives.

AI-assisted (Claude).

Approving. Merged into current main (42537e7) with no conflicts. `tests/test_rdna2spirv_shard.py` passes (5 passed), and the full translator suite gives 487 files / 6,279 tests with only `test_int32_to_f64` failing, as on main here (Linux, Python 3.13). The partition is deterministic: largest first, ties broken by path, each file to the lightest bucket with ties broken by index. So every shard derives the same buckets and together they cover each file exactly once. Refusing on an unreadable size, rather than weighting it 0, is the right call for the reason the comment gives. AI-assisted (Claude).
PierreEbele commented 2026-11-25 14:39:51 +00:00

Reviewed daf7362: ran tests/test_rdna2spirv_shard.py (5/5; errors on main without shard_bucket),
tests/test_rdna2spirv_cli.py (36, 2 skipped: no SPIRV-Tools here) and tests/test_rdna2spirv_merge.py
(30) on both trees, plus probes: the buckets partition exactly, agree across listing orders and
balance where files[i::n] did not (60 KB alone vs 60 KB plus tail at n=4); a 4-shard CLI run with
--merge publishes the full set on both trees; an unreadable size stops every shard before anything
is published, and the first commit's weight-0 guess, reproduced, would have published 6 duplicated

  • 1 missing. No finding. Nits if you want them: the OSError reaches the user as a traceback rather
    than the file's ERROR + exit-2 convention, and one unreadable file now stops all shards. AI-assisted
    review.

Recommendation: Merge

Reviewed daf7362: ran tests/test_rdna2spirv_shard.py (5/5; errors on main without shard_bucket), tests/test_rdna2spirv_cli.py (36, 2 skipped: no SPIRV-Tools here) and tests/test_rdna2spirv_merge.py (30) on both trees, plus probes: the buckets partition exactly, agree across listing orders and balance where files[i::n] did not (60 KB alone vs 60 KB plus tail at n=4); a 4-shard CLI run with --merge publishes the full set on both trees; an unreadable size stops every shard before anything is published, and the first commit's weight-0 guess, reproduced, would have published 6 duplicated + 1 missing. No finding. Nits if you want them: the OSError reaches the user as a traceback rather than the file's ERROR + exit-2 convention, and one unreadable file now stops all shards. AI-assisted review. **Recommendation:** Merge
Sign in to join this conversation.
No description provided.