You have two layers: i2h and i2o. In the first loop through, the loss only depends on i2o – the “hidden” output doesn’t affect the loss so it doesn’t get a gradient.
In general, you don’t want to call loss.backward() every time step of an RNN. You want to compute a few timesteps and the compute the loss across all the outputs