mirror of
https://github.com/pytorch/pytorch.git
synced 2026-11-20 09:04:25 +08:00
19da3da3d3
The fix-cpp-build branch is a major restructuring that: - Drops Exhale (which auto-generated API docs but caused OOM in CI) in favor of hand-written RST pages using Breathe directives - Reorganizes notes into a hierarchical API reference with proper categories - Adds new content: XPU docs, stable ABI docs, DeviceGuard/Stream docs - Always runs Doxygen instead of gating on an env var Pull Request resolved: https://github.com/pytorch/pytorch/pull/174096 Approved by: https://github.com/janeyx99, https://github.com/seemethere, https://github.com/albanD
2.5 KiB
2.5 KiB
myst
| myst | ||||||
|---|---|---|---|---|---|---|
|
Recurrent Layers
Recurrent layers process sequential data by maintaining hidden state across time steps. They are essential for tasks involving sequences: language modeling, speech recognition, time series prediction, and more.
- RNN: Basic recurrent layer (simple but prone to vanishing gradients)
- LSTM: Long Short-Term Memory (gated architecture, handles long-range dependencies)
- GRU: Gated Recurrent Unit (simpler than LSTM, often similar performance)
- Cell variants: Single-step versions for custom loop implementations
Key parameters:
input_size: Number of features in inputhidden_size: Number of features in hidden statenum_layers: Number of stacked recurrent layersbatch_first: If true, input shape is[batch, seq, features]bidirectional: Process sequence in both directions
RNN
:members:
:undoc-members:
:members:
:undoc-members:
Example:
auto rnn = torch::nn::RNN(
torch::nn::RNNOptions(128, 256) // input_size, hidden_size
.num_layers(2)
.batch_first(true)
.bidirectional(false));
auto input = torch::randn({32, 10, 128}); // [batch, seq_len, input_size]
auto [output, hidden] = rnn->forward(input);
LSTM
:members:
:undoc-members:
:members:
:undoc-members:
Example:
auto lstm = torch::nn::LSTM(
torch::nn::LSTMOptions(128, 256)
.num_layers(2)
.batch_first(true)
.dropout(0.1)
.bidirectional(true));
auto input = torch::randn({32, 10, 128});
auto [output, state] = lstm->forward(input);
auto [h_n, c_n] = state; // hidden state, cell state
GRU
:members:
:undoc-members:
:members:
:undoc-members:
RNNCell
:members:
:undoc-members:
:members:
:undoc-members:
LSTMCell
:members:
:undoc-members:
:members:
:undoc-members:
GRUCell
:members:
:undoc-members:
:members:
:undoc-members: