interop foldins - Capsize-Games/spikeforge GitHub Wiki

Interop fold-ins (WS-F)

Event-dataset training

training/event_engine.py and training/event_batches.py batch an event stream through the existing bridge into the [T, B, โ€ฆ] contract the training loop already consumes, so the loss/optimizer/metrics/ checkpointing path is shared. A checkpoint records modality: event; without tonic the engine raises the typed EventsExtraMissingError, and a synthetic stream is never presented as a recording.

ONNX bridge

onnx_bridge/ exports a topology's single forward step to ONNX (the time loop stays in the simulator) with the spec in metadata, and imports a third-party graph by mapping ops to stage kinds โ€” or failing with a typed error naming the op. The onnx extra provides onnx/onnxruntime; imports are confined to onnx_bridge/api.py.

spikeforge-verify onnx-export    --topology conv_net --out build/model.onnx
spikeforge-verify onnx-import    --file build/model.onnx
spikeforge-verify onnx-roundtrip --topology conv_net

nirtorch extraction

nir_bridge/extract.py lifts an arbitrary torch.nn.Module into NIR through the isolated nirtorch wrapper, then runs it on the independent interpreter:

spikeforge-targets extract --module model.pt

torch_map.NODE_MAP maps only nn.Linear and nn.Flatten; any other module raises the typed UnsupportedNodeError naming the class โ€” no silent truncation.

Quantization

targets/quantize.py applies a target's declared weight scheme (none, weight_int8, weight_uint8) to a graph's weights, reporting per-layer before/after ranges and the induced drift. The drift check can also simulate activation/membrane quantization (activation_membrane_int8, activation_int8, membrane_int8) by snapping the reference interpreter's node outputs and carried state onto a calibrated fixed-point grid (activation_quant_graph.py); drift.includes names which roundings a figure covers. No shipped target declares an activation scheme, a none target is a reported no-op, an unknown scheme is reported unapplied, and nothing here is a device result โ€” see Implications and boundaries ยง3.

Non-square geometry and input_size

data/image_size.py normalises a geometry declared as an int side or an explicit (H, W) pair, and EncodeConfig.input_size propagates it. Presets keep 28ร—28 by default, so every shipped preset is byte-identical until a shape is requested.

Hidden-layer animation

EncodeConfig.animate_hidden (default off) streams a per-step hidden-layer frame over the existing spike_frame/animation_state channel; network/hidden_frames.py caps the width so an oversized layer cannot flood the socket. With the flag unset, the payload stream is identical to before.