Skip to content

Add backward ops for spatial nodes and spiking neurons - #51

Merged
w4ffl35 merged 1 commit into
masterfrom
fix/nir-backward-ops
Oct 14, 2026
Merged

w4ffl35 merged 1 commit into
masterfrom
fix/nir-backward-ops

Conversation

@w4ffl35

@w4ffl35 w4ffl35 commented Oct 14, 2026

Copy link
Copy Markdown
Member

Closes #40, closes #41.

Backward ops following the existing _backward conventions in ops.h:

  • conv2d/conv1d: transposed grad_input, accumulating grad_weight (flat, same linear order as params->weight) and grad_bias; grad_bias NULL iff no bias, mirroring affine_backward.
  • flatten: reshape the flat gradient to the retained input shape.
  • avgpool2d/sumpool2d: scatter over each window (count-include-pad divisor for avg).
  • scale: grad_input = gy*s plus an opt-in accumulating grad_scale (scale stays a fixed graph constant by default).
  • lif/if/cuba: surrogate through the spike output, zero gradient through the hard-reset branch (grad_stored accepted for tape wiring, contributes nothing); membrane recomputed from retained input/prev state. Reset convention documented in ops.h.

Tests: new tests/test_backward.c with hand closed forms, a central-difference sweep of the conv forward ops (stride/pad/dilation/multi-channel), both spike branches pinned by the forward op, and wiring rejections. Debug, Release, and ASan/UBSan ctest runs pass 36/36 locally.

Conv2d/Conv1d backward (transposed grad_input, accumulating
grad_weight/grad_bias), Flatten/pool/Scale backward (opt-in
accumulating grad_scale), and LIF/IF/CubaLIF backward with the
surrogate through the spike output and zero gradient through the
hard-reset branch. Tests are hand closed forms plus a
central-difference sweep of the conv forward ops.
@w4ffl35
w4ffl35 force-pushed the fix/nir-backward-ops branch from 844b211 to 6436af0 Compare October 14, 2026 11:19
@w4ffl35
w4ffl35 merged commit aedf10c into master Oct 14, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant