Repository navigation
Add mini-batch accumulation, mean reduction, and seeded shuffling (closes #42) - #53
Merged
Merged
Conversation
…oses #42) minibatch.h/minibatch.c: caller-loop helpers over batch-1 tensors -- zero, per-sample gradient accumulation, 1/B scaling, and float64-accumulated mean loss -- plus seeded Fisher-Yates epoch shuffling over nir_rng_t. Documents the mean-reduction contract (batch loss/grad = mean of per-sample values, optimizers always see the mean gradient) and records the #42 decision against a batch axis on nir_tensor_t. test_minibatch.c: accumulation matches summed affine-backward per-sample grads (float64 reference and the op's own repeated-call path), mean loss/grad match single-sample cross-entropy, and shuffling is seeded-reproducible with a pinned order on the tiny-MNIST fixture.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #42.
No-ABI-break path from the issue: the caller keeps looping over batch-1 tensors, and this module owns the reduction bookkeeping.
minibatch.h/minibatch.c: zero / per-sample gradient accumulate / 1/B scale over caller buffers, float64-accumulated mean loss, and seeded Fisher-Yates epoch shuffling (nir_sampler_arange+nir_sampler_shuffle) overnir_rng_t. Failure leaves accumulators untouched; NULL/empty/non-finite inputs fail.minibatch.hand pointed at fromtrain.h/data.h(plus the stale Mini-batch training (gradient accumulation, batched loss reduction, seeded shuffling) #42 pointer inloss.h): batch loss/grad = mean of per-sample values, optimizers always see the mean gradient.minibatch.h: no batch axis onnir_tensor_t; revisit only with measured evidence.test_minibatch.c: accumulation matches summed affine-backward per-sample grads (float64 reference, plus the op's own repeated-call path bit-exact); mean loss/grad match single-sample cross-entropy; shuffling is seeded-reproducible with a pinned order on the tiny-MNIST fixture (seed 7 -> [1,2,0], labels read 3,9,7).Ownership: minibatch module + tests + CMake registration only. No tape, checkpoint, driver, or example changes.
Local verification: Debug, Release, and ASan/UBSan builds each pass the full suite, 42/42 ctest.