How to write a RNN with RNNCell in pytorch?
I am trying to rewrite a code from this simple Vanilla RNN to RNNCell format in pytorch. This is the full code
import torch
import torch.nn as nn
from torch.autograd import Variable

torch.manual_seed(777)


class SimpleRNN(nn.Module):
    def __init__(self,inputs,hiddens,n_class):
        super().__init__()
        self.rnn = nn.RNNCell(inputs,hiddens)
        self.linear = nn.Linear(hiddens,n_class)
        self.hiddens = hiddens
    def forward(self,x):
        hx = torch.zeros((x.shape[1],hiddens))
        rnn_out = []
        for i in x:
            hx = self.rnn(i,hx)
            rnn_out.append(hx)
        linear_out =  self.linear(rnn_out.view(-1, hiddens))
        return linear_out


# hyperparameters
seq_len = 6      # |hihell| == 6, equivalent to time step
input_size = 5   # one-hot size
batch_size = 1   # one sentence per batch
num_layers = 1   # one-layer rnn
num_classes = 5  # predicting 5 distinct character
hidden_size = 4  # output from the RNN


# create an index to character mapping
idx2char = ['h', 'i', 'e', 'l', 'o']

# Teach hihell -&gt; ihello
x_data = [[0, 1, 0, 2, 3, 3]]    # hihell
x_one_hot = [[[1, 0, 0, 0, 0],   # h 0
              [0, 1, 0, 0, 0],   # i 1
              [1, 0, 0, 0, 0],   # h 0
              [0, 0, 1, 0, 0],   # e 2
              [0, 0, 0, 1, 0],   # l 3
              [0, 0, 0, 1, 0]]]  # l 3

x_one_hot = torch.Tensor(x_one_hot)
y_data = torch.Tensor([1, 0, 2, 3, 3, 4])  # ihello

rnn = SimpleRNN(input_size,hidden_size,num_classes)

# train the model
num_epochs = 15
criterion = nn.CrossEntropyLoss()
optimizer = torch.optim.Adam(rnn.parameters(), lr = 0.1)
for epoch in range(1, num_epochs + 1):
    optimizer.zero_grad()
    outputs = rnn(inputs)
    loss = criterion(outputs, labels)
    loss.backward()
    optimizer.step()

    # check the current predicted string
    # max gives the maximum value and its
    # corresponding index, we will only
    # be needing the index
    _, idx = outputs.max(dim = 1)
    idx = idx.data.numpy()
    result_str = [idx2char[c] for c in idx]
    print('epoch: {}, loss: {:1.3f}'.format(epoch, loss.item()))
    print('Predicted string: ', ''.join(result_str))

I am trying to emulate the original RNN + fully connected class object from the tutorial and reusing many of its code. I computed the rnn_out and appended its value in a python list
        rnn_out = []
        for i in x:
            hx = rnn(i,hx)
            rnn_out.append(hx)

because its a python list I cant further execute the code and it will result in this error

AttributeError: 'list' object has no attribute 'view'

How should I write a RNN using RNNCell?

I am not sure the rest of your code is alright, but in order to fix this error, you can convert your rnn_out list to a torch tensor by adding the following line after the ending of your for loop:
rnn_out = torch.stack(rnn_out)

