onnx: LSTM / GRU / RNN, unrolled over the static sequence length - #94
Merged
Conversation
Each layer unrolls into the single fused program: per timestep, one linear over the stacked input-side gate weights and one over the recurrent side (iofc order for LSTM, zrh for GRU), sliced per gate. Forward, reverse, and bidirectional directions; both GRU linear_before_reset forms (the before-reset form reuses the fused recurrent matmul, the after-reset form takes one extra linear over the h-gate slice). Weights, biases, and initial states must be constants; default activations only; clip, peepholes, per-sample sequence_lens, and layout=1 raise. Importer hardening required by these ops: ONNX marks omitted optional inputs and unused optional outputs with empty-string names - inputs now resolve '' to None and outputs named '' are not stored (previously a skipped output would have polluted the value table under the key ''). 165 tests pass on-device (M5): LSTM forward/bidirectional/Y_h, GRU in both reset forms, reverse RNN - all against onnxruntime at fp16 tolerance - plus the peephole reject.
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.
The last big compositional tier: the recurrent family, unrolled the same way Loop (#91) proved out — the whole recurrence becomes one fused program.
What
LSTM— per timestep, one fused linear over the stacked input-side gate weights and one over the recurrent side (iofcorder), sliced per gate. Forward, reverse, and bidirectional;Y,Y_h,Y_coutputs.GRU—zrhorder, bothlinear_before_resetforms (the before-reset form reuses the fused recurrent matmul; the after-reset form takes one extra linear over the h-gate slice).RNN— vanilla tanh.clip, LSTM peepholes, per-samplesequence_lens,layout=1, tensor-valued weights/initial states.""inputs now resolve to None and""outputs are no longer stored (previously they'd pollute the value table under the key"").Geluentries onnx: support tanh-approximate Gelu #92 made stale (exact + tanh-approximate now).Verification (on-device, M5)
pytest tests/test_onnx.py: 166 passed — LSTM forward/bidirectional/Y_h, GRU in both reset forms, reverse RNN, all against onnxruntime at fp16 tolerance, plus the peephole reject. One test bug caught during rebase verification: the weight seeds used Python's saltedhash(), making the numerics nondeterministic across processes — nowzlib.crc32, verified stable across three consecutive runs.ruff, 2-space pylint,pyright(0 errors) clean.