Repository navigation
Add C-side training math: surrogate hook, backward ops, loss, optimizers - #35
Merged
Merged
Conversation
Forward spikes stay strict Heavisides; the backward pass substitutes a named surrogate derivative (fast_sigmoid/atan, snnTorch formulas) with no silent default. New train.h/train.c provide name resolution, softmax cross-entropy, SGD/Adam over raw weight buffers, and a local STDP rule ported from STDPSynapse with decay-before-update ordering. Layer backward ops cover Threshold, LI, Affine, and Linear; test_train checks each primitive plus one Adam step on a two-layer topology against float64 closed-form references and a 300-step convergence run. Also fix two Conv2d groups set_error call sites left with a stale third argument after #24 (same fix as the loader PR; master did not compile). A graph-level backprop-through-time tape and a committed torch fixture generator remain follow-ups. Fixes #26.
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 #26. Training-model decision (work-list item 1): option (c), both paths behind separate APIs — a surrogate-gradient path (named surrogate + CE loss + SGD/Adam + layer backward ops) and a local STDP port. Recorded on the epic in #25.
What this adds:
nir_surrogate_from_name(train.h) resolves only fast_sigmoid/atan and fails on anything else — no silent default, mirroring resolve_surrogate's KeyError.Follow-ups (out of this worker's scope): graph-level backprop-through-time tape retaining per-step activations (runtime.c), and a committed tools/ torch fixture generator (tools owner) to replace the throwaway float64 reference script.
Note: includes the same two-line set_error arity fix as PR #34 (master does not compile without it); the hunks are identical so they merge cleanly.
Tests: ctest 31/31 green in Debug, Release, and the ASan/UBSan configure from ci.yml.