feat(examples): mnist_cnn — PyTorch + C MNIST 1D-CNN parity demo#254
Merged
Conversation
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.
What
Adds
examples/mnist_cnn/— the 1D-CNN twin of the mergedmnist_mlpexample, on the same MNIST data and harness. Together they showcase the framework across two architectures (dense vs convolutional) on one canonical dataset, with everything else held constant.The framework is 1D-only (no Conv2d), so the CNN treats each
[1,28,28]image as a length-784 single-channel 1D signal. Sinceflattenonly emits 2D and there is no view/reshape layer, the[1,28,28]→[1,1,784]reinterpretation is a loader-sideshape_tsurgery (reshapeItemsToConv1d) — documented in the README as a known framework gap.Model (~600 params):
reshape→Conv1d(1→8,K3,SAME)→ReLU→MaxPool(2)→Conv1d(8→16,K3,SAME)→ReLU→MaxPool(2)→global AvgPool1d(196)→Flatten→Linear(16→10)→Softmax, CrossEntropy.Verification
padding=1for K=3/stride=1), MaxPool, global AvgPool, Flatten, and Linear all reproduce PyTorch exactly.train_c.cclang-format-21 clean.Notes
compare.pyis informational (not a gate) and slow (~75 min on full MNIST, framework trains one sample at a time); the README points at the fast bit-parity check.docs/superpowers/{specs,plans}/2026-06-26-mnist-examples*(gitignored scratch).🤖 Generated with Claude Code