Implement LSTMCell(input_size, hidden_size) as an nn.Module. The constructor creates two weight matrices and two bias vectors:
self.W_ih: nn.Parameter of shape (4 * hidden_size, input_size).self.W_hh: nn.Parameter of shape (4 * hidden_size, hidden_size).self.b_ih: nn.Parameter of shape (4 * hidden_size,).self.b_hh: nn.Parameter of shape (4 * hidden_size,).These match torch.nn.LSTMCell's parameter layout exactly. The 4x in the first dim packs the input, forget, cell-candidate, and output gates into one tensor.
The forward(x, state) method takes input x of shape (N, input_size) and a tuple state = (h_prev, c_prev) each of shape (N, hidden_size), and returns (h_new, c_new). Use this PyTorch-compatible gate order:
Initialize parameters however you like - the test cases override them.
Tensor.uniform_(-k, k) with k = 1 / sqrt(hidden_size), matching PyTorch.tensor.chunk(4, dim=1) to split the pre-activations into the four gate tensors in one call.