Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/185507
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
There was a problem hiding this comment.
FullLayer and PackedLayer are modified to do the pre-compute for xpu, do we need to modify the code in the GRUCell as well similar to what you did in LSTMCell for pre-compute?
There was a problem hiding this comment.
I have updated this PR, now it depends on intel/torch-xpu-ops#3826 and torch-xpu-ops pin update
On XPU, add a separate LSTMCell path that supports pre_compute_input with the fused lstm cell kernel. The Layer/PackedLayer classes now use linear_ih to batch-compute igates (with bias) for the entire sequence, and pass empty b_ih to _thnn_fused_lstm_cell since bias is already included. CUDA and CPU paths are unchanged. Depends on intel/torch-xpu-ops#3770 for correct handling of (None, b_hh) in the fused LSTM cell kernel.
|
@jianyizh , I suppose this PR is not necessary now, right? |
This pr is not urgent. We may review and merge it later. oneDNN LSTM cannot cover all cases. This PR optimize the fallback path. |
|
Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as |
Summary
On XPU, batch-compute input gates (
linear_ih) for the entire sequence upfront, then pass pre-computed results to_thnn_fused_lstm_cellper time step. This reduces kernel launch overhead from O(T) GEMM launches to a single large GEMM.Correctness
Standard LSTM formula per time step:
The input transform
W_ih @ x_t + b_ihdepends only onx_t, not on the hidden stateh_{t-1}. Since allx_tare known at sequence start, we can batch them:Then per step:
This is mathematically equivalent. Since
b_ihis already inigates, we passb_ih=Noneandb_hh=b_hhto the fused cell kernel.Dependencies
(None, b_hh)bias combination in the fused LSTM cell kernel.Scope
FullLayer,FullBidirectionalLayer,PackedLayer, andReversedPackedLayer.cc @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10 @aditew01