Fix MNIST example not training (pointer to de-referenced stack memory) #12
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.
Fix MNIST example not training
We were referencing a stack allocated variable in the loop which just went to garbled memory after the loop ended (happened to reference the last item of the loop).
It would be nice if Zig could warn/error when we tried to reference and store a pointer to some stack-allocated object to avoid this type footgun (ziglang/zig#2301, ziglang/zig#5725, ziglang/zig#2646, https://www.openmymind.net/Zig-Danling-Pointers/).
Before
Before we fixed this bug, every labeled piece of data was using the image of the 8 (whatever the last training item happens to be).
(Notice how it's showing an
8
but it's labeled as5
❌)After
Now all of the images correctly line up with their labels ✅
Now training can make progress!!