Repository navigation
Eliminate runtime output-shape computation in LSTM and GRU - #3111
Justin Chu (justinchuby) with Copilot wants to merge 2 commits into
Conversation
Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
❌ 4 Tests Failed:
View the top 2 failed test(s) by shortest run time
View the full list of 8 ❄️ flaky test(s)
To view more test analytics, go to the Test Analytics Dashboard |
There was a problem hiding this comment.
🟢 Approval recommended
The conversions preserve dimension ordering and dynamic sizes, with no blocking issues identified in static review; tests were not executed.
No open issues 🎉
What changed in this PR
Simplifies LSTM and GRU output conversion to remove per-layer runtime shape computation while preserving dynamic batch dimensions.
Changes:
- Shares a conversion helper using
Squeezeor constant-shapeReshape. - Adds multilayer regression coverage for both directions, layouts, sequence lengths, and varying batch sizes.
| File | Description |
|---|---|
| tests/function_libs/torch_lib/e2e_ops_tests.py | Checks graph structure and numerical correctness across RNN configurations. |
| onnxscript/function_libs/torch_lib/ops/core.py | Replaces runtime shape arithmetic with simplified shared conversion. |
Review effort: Balanced
LSTM and GRU exports compute output shapes at runtime after every layer, adding kernels that cannot be constant-folded with dynamic batches. The reported four-layer LSTM workload incurs roughly 10% overhead.
Squeeze(Y, [1])for unidirectional outputs; useTransposefollowed byReshape([0, 0, 2 * hidden_size])for bidirectional outputs.The four-layer LSTM export drops from 104 to 68 nodes, eliminating all output-conversion
ShapeandReshapenodes.