tools: --shard balances by file size, so the parallel stage waits for nobody (output byte-identical) #57
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/57"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by Andretuta on 2026-11-24T02:09:45Z.
Original description (mentions and
#Nreferences are disabled; the numbers refer to the old repository):The parallel translation stage waits for its slowest shard, and the split ignores size. This balances the shards on input size; on a real 247-listing run the shards come out level and every output stays byte-identical.
--shard i/ntookfiles[index::count]— round-robin over the name-sorted list, which balances nothing when shaders differ in size.shard_bucket()sorts by file size, largest first, and gives each file to the lightest bucket so far; a shard translates its own bucket. Every shard derives the same partition from the same directory listing, so the processes still do not talk to each other,make_game.pyand the--shard i/ninterface are unchanged, and each bucket is still handed out in name order.Measured
Independent run by
@nicolasaboschon 247 listings, four--shard i/4runs plus--mergeagainst one unsharded run:.spvfiles on both sides, all 258 byte-identical; merge has 247 entries;And on the real 26,503-listing corpus by
@exotiquee: round-robin is already within 2.6% of even at 8 shards and 6.8% at 16, so the honest expected gain there is 0-7%, growing with the shard count; the change levels the tail rather than rescaling the stage. That correction is in this description on purpose — the synthetic corpus I first measured on was skewed far more than the real one, and its 17-26% is not the claim.A size that cannot be read stops the shard
Reported by
@Zhenyettta: with a weight of 0 for one unreadable file, two shards can take the same shader while a third falls out of every bucket. Each shard derives the partition alone, so the one thing that must not happen is a shard placing a file by a number the others do not have.shard_bucket()now raises with the path and the advice to run the shard again.Tests
tests/test_rdna2spirv_shard.py(5): the buckets are disjoint and complete for 1/2/3/4/8/16 shards, the same partition in every process, name order inside a bucket, a skewed listing beatsfiles[::n]at 2/4/8 shards, one shard takes everything, and an unreadable size is refused.--mergeandtest_rdna2spirv_merge.pyare unchanged. Independent runs also confirm resume:make_game.translate's plan includestranslator_digest(), so parts from the old bucketing are never merged with new ones.cc
@ItsNotRexed@KoertLichtendonkChecklist
docs/design.md. (Not applicable: same shaders, translated by a different process.)Imported from ubiquitarianism/leonida. Originally posted by wavehs on 2026-11-24T02:38:25Z.
macOS arm64 verification (Apple M3 Pro) — the size-balanced partition is deterministic, measurably better on this repo's own listings, and the tests bite
Head
ff80152d2(2 commits, branch base1cc6e3c12: 1,250 commits behindmain), merged ontomain(9ec34cdff) asc6b46bfe4cleanly. 2 files +115/−3. Host: macOS 27.2.1, Apple M3 Pro (arm64), CPython 3.15.2, llvm-mc 23.1.5, MoltenVK 1.4.0, KosmicKrisp (Mesa 26.3.0).Because the branch predates a lot of
main, I checked that the merge did not smuggle anything back:git diff ubi/main c6b46bfe4 -- tools/rdna2spirv.pyis exactly the newshard_bucket, the two-line caller change and the help text — main's 1,250 later commits are intact in the merged tree.c6b46bfe4main9ec34cdfftests/test_rdna2spirv_shard.pyrdna2spirv.py: 5 errorsscripts/run_semantic_tests.py tests/semantictest_exec_computed,test_image_atomics_guardrun_gpu_tests.pyall cases, MoltenVKrun_gpu_tests.pyall cases, KosmicKrispThe GPU rows are identical to
mainline for line on both drivers after normalising work paths, as expected for a partitioning change; the disk build from the previous merge is reused, the translator is this merge's.Negative controls, two of them. (1) Main's
rdna2spirv.pywith the new test file: 5 errors, allAttributeError: module 'rdna2spirv' has no attribute 'shard_bucket'. (2) That only proves the name exists, so I substituted the oldfiles[index::count]into the same assertions the test makes, on its own skewed corpus: the size-based span is 6000 at 2, 4 and 8 shards, the round-robin span is 6300/6150/6120, and the test'sassertLess(span, round_robin)fails for the round-robin version at every shard count. So the test catches a regression to the old split, not just a missing function.Measured on real listings, not the synthetic ones. The repo's 104 semantic fixture listings (247,985 bytes, largest 9.1% of the total — close to the PR's 11% case):
At 12 shards the old split gives one process the 22,484-byte listing alone and another 6,000 bytes, which is exactly the "everyone waits for the biggest shard" case the PR describes; the new one is within 10%. The PR's 1.18x/1.30x at 4/8 shards is the same direction and magnitude.
Wiring checked end to end:
tools/rdna2spirv.py tests/semantic/fixtures/disasm --out … --shard i/4 --limit 40reports 9, 10, 10 and 11 shaders. That is exactlyshard_bucket's buckets over the same 40 files (18,572 / 18,449 / 18,270 / 18,393 bytes), wherefiles[i::4]would be 10/10/10/10 — so the call site really uses the partition, not only the function. (Those fixtures then fail to translate for an unrelated, expected reason: they have no FSSM or shader container, so I am quoting the counts, not translations.)The code is right for the way shards run. Every process re-lists the directory, sorts by
(-size, path), and breaks load ties by bucket index, so the partitions agree without the processes talking; the returned bucket is sorted again, keeping "handed out in name order".min(range(count), …)per file is O(files × shards): 26,503 × 12 is nothing next to the translation. RaisingOSErrorinstead of a 0 weight is the right call given that a disagreement silently produces a corpus with a file twice and one missing — and the message names the file and says to retry. One limit worth knowing: the CLI cannot easily reach that path (a dangling.ssymlink is dropped by the file discovery before the partition), so the unit test is the whole cover; that is fine, not a defect.Two small notes, neither blocking:
--limitis still applied before the partition (files = files[:a.limit]then shard), so--limit N --shard i/nmeans "the first N listings, split", which is what it meant before. Worth keeping that sentence in mind if the flag's help is ever expanded.make_game.pyrun at 4 and 8 shards before/after (the 80-minute figure indocs/pipeline_check.md:450) would turn the 1.18x/1.30x into a number from the 26k corpus.No game files. AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T18:00:09Z.
Maintainer review: this change does not appear to be superseded by current main, but it is not ready to merge. The PR remains a draft and all current CI checks were cancelled; the independent run is against a much older base. Please confirm ownership, update/merge main into the branch, rerun the focused test and required suite, then mark ready.
Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:15:22Z.
Review: COMMENTED
Confirmed
shard_bucket()has not landed onmainyet and the branch still merges cleanly, though it remains a carried-over draft with cancelled CI runs and a base over 1,250 commits behindmain. Echoing @MoonEyes: please confirm ownership, update onto currentmain, re-run CI (tests/test_rdna2spirv_shard.pyand the required suite), and mark ready for review.(AI-assisted review.)
Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T12:05:36Z.
Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review.
(AI-assisted triage.)
Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T13:02:08Z.
Review: APPROVED
Now ready for review and
MERGEABLE. Clean-room verified:shard_bucket()intools/rdna2spirv.pyproduces a deterministic, size-balanced partition with byte-identical outputs, refuses unreadable sizes cleanly, and is covered bytests/test_rdna2spirv_shard.py(independently verified by@wavehs).Approving — ready to merge once fresh CI runs green on current
main(existing Nov 24 checks were cancelled).(AI-assisted review.)