_lstm_impl Class — pytorch Architecture
Architecture documentation for the _lstm_impl class in RNN.cpp from the pytorch codebase.
Entity Profile
Source Code
aten/src/ATen/native/RNN.cpp lines 1148–1175
template<template<typename,typename> class LayerT, template<typename,typename> class BidirLayerT, typename cell_params, typename io_type>
std::tuple<io_type, Tensor, Tensor> _lstm_impl(
const io_type& input,
const std::vector<cell_params>& params, const Tensor& hx, const Tensor& cx,
int64_t num_layers, double dropout_p, bool train, bool bidirectional) {
// It's much more useful for us to work on lists of pairs of hx and cx for each layer, so we need
// to transpose a pair of those tensors.
auto layer_hx = hx.unbind(0);
auto layer_cx = cx.unbind(0);
int64_t total_layers = layer_hx.size();
std::vector<typename LSTMCell<cell_params>::hidden_type> hiddens;
hiddens.reserve(total_layers);
for (const auto i : c10::irange(total_layers)) {
hiddens.emplace_back(std::move(layer_hx[i]), std::move(layer_cx[i]));
}
auto result = _rnn_impl<LSTMCell<cell_params>, LayerT, BidirLayerT>(input, params, hiddens, num_layers, dropout_p, train, bidirectional);
// Now, we need to reverse the transposed we performed above.
std::vector<Tensor> hy, cy;
hy.reserve(total_layers); cy.reserve(total_layers);
for (auto & hidden : result.final_hidden) {
hy.push_back(std::move(std::get<0>(hidden)));
cy.push_back(std::move(std::get<1>(hidden)));
}
return std::make_tuple(std::move(result.outputs), at::stack(hy, 0), at::stack(cy, 0));
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free