You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add debug-only assert(modelOutput->shape->dimensions[0] >= 1) at the entry of each loss family's forward and backward (MSE, CrossEntropy, plus future loss types). The assert documents the microbatch-shape contract executably and protects against 1/0 divisions when MEAN reduction encounters an empty microbatch.
Under B = 1 only, the assert is effectively a no-op: today every caller passes a shape with dimensions[0] = 1 either implicitly or explicitly. The protective value materialises only when B > 1 becomes real, alongside the rest of #152's work. Bundling here keeps the doc-side microbatch contract (already shipped with #135 in docs/CONVENTIONS.md) and the runtime enforcement together.
Implementation sketch
#include <assert.h> in src/loss_functions/MSE.c and src/loss_functions/CrossEntropy.c
Sub-issue of #152.
Add debug-only
assert(modelOutput->shape->dimensions[0] >= 1)at the entry of each loss family's forward and backward (MSE, CrossEntropy, plus future loss types). The assert documents the microbatch-shape contract executably and protects against1/0divisions when MEAN reduction encounters an empty microbatch.Why deferred from #135
Under B = 1 only, the assert is effectively a no-op: today every caller passes a shape with
dimensions[0] = 1either implicitly or explicitly. The protective value materialises only when B > 1 becomes real, alongside the rest of #152's work. Bundling here keeps the doc-side microbatch contract (already shipped with #135 indocs/CONVENTIONS.md) and the runtime enforcement together.Implementation sketch
#include <assert.h>insrc/loss_functions/MSE.candsrc/loss_functions/CrossEntropy.cmseLossForwardFloat,mseLossForwardSymInt32mseLossBackwardFloat,mseLossBackwardSymInt32crossEntropyForwardFloatcrossEntropySoftmaxBackwardFloat,crossEntropySoftmaxBackwardAsymOut of scope
The umbrella's other sub-issues (DataLoader B > 1, layer batched ops, etc.).