Skip to content

Commit 3b39644

Browse files
kmheckelclaude
andcommitted
Add spyx.experimental.onnx: ONNX export of spiking step functions
to_onnx(model, input_shape, *, batch, dtype, opset, sequence_length) -> bytes exports a spiking model's single-timestep (x, state) -> (out, new_state) forward to an ONNX ModelProto via jax2tf -> tf2onnx. ONNX reaches phones (ONNX Runtime Mobile, NNAPI/CoreML), servers, and edge from one export. tensorflow/tf2onnx imported lazily (module imports without them; 'pip install tensorflow tf2onnx onnx onnxruntime' to convert); NOT a declared extra, so the lock/Python-3.14 stay clean. - Verified: the onnxruntime output matches the JAX single step (out + every new-state tensor) at atol/rtol 1e-4 (zero and nonzero state). - Honest limitation: full-sequence export (sequence_length=T, an ONNX Scan/Loop of the whole time loop) does NOT convert here — jax2tf emits a StableHLO XlaCallModule that tf2onnx's TF-graph importer can't parse. Documented, test skipped (not faked). Per- step export + an external loop is the shipped capability (same shape as LiteRT). Experimental / unstable API. Third export leg alongside NIR (neuromorphic) and LiteRT. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 3202e91 commit 3b39644

3 files changed

Lines changed: 538 additions & 1 deletion

File tree

src/spyx/experimental/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
- :mod:`spyx.experimental.compress` — bit-packed activation storage for
2121
memory-efficient BPTT (``packed_spike_dense``, ``pack_spikes``,
2222
``unpack_spikes``).
23+
- :mod:`spyx.experimental.onnx` — export a spiking model to ONNX: the
24+
per-timestep step ``(x_t, state) -> (out, new_state)`` (flat tensor I/O), or,
25+
when a sequence length is given, the whole ``spyx.nn.run`` temporal loop as a
26+
native ONNX ``Scan``/``Loop``. Conversion deps (tensorflow/tf2onnx/onnx) are
27+
imported lazily.
2328
- :mod:`spyx.experimental.stochastic` — stochastic (Bernoulli-spiking) and
2429
parallelizable prototypes: ``SPSN``, ``StochasticAssociativeLIF``,
2530
``StochasticAssociativeCuBaLIF`` and the ``sigmoid_bernoulli`` activations.
@@ -31,7 +36,7 @@
3136
# here so the experimental surface is discoverable in one place.
3237
from ..nn import PSU_LIF
3338
from ..phasor import ResonateFire
34-
from . import compress, raven, stochastic
39+
from . import compress, onnx, raven, stochastic
3540
from .compress import pack_spikes, packed_spike_dense, unpack_spikes
3641
from .raven import RavenRSM, SlotRouter, SpikingSlotMemory, make_recall_batch
3742
from .stochastic import (
@@ -44,6 +49,7 @@
4449

4550
__all__ = [
4651
"compress",
52+
"onnx",
4753
"raven",
4854
"stochastic",
4955
"PSU_LIF",

0 commit comments

Comments
 (0)