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

Closed
ambroseautomation wants to merge 2 commits from upstream-pr/1261 into main
ambroseautomation commented 2026-11-24 21:01:47 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ambroseautomation on 2026-11-24T21:01:47Z.


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)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5480267180 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1261). Originally posted by [ambroseautomation](https://github.com/ambroseautomation) on 2026-11-24T21:01:47Z. --- 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 commented 2026-11-25 06:27:00 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-25T06:27:00Z.

Review: APPROVED


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6052823944 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1261#pullrequestreview-6052823944). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-25T06:27:00Z. **Review:** APPROVED --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by PierreEbele on 2026-11-25T14:39:51Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7165621895 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1261#issuecomment-7165621895). Originally posted by [PierreEbele](https://github.com/PierreEbele) on 2026-11-25T14:39:51Z. --- 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

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!1261
No description provided.