Why does PyTorch use a different formula for the cross-entropy? In my understanding, the formula to calculate the cross-entropy is

$$
H(p,q) = - \sum p_i \log(q_i)
$$

But in PyTorch nn.CrossEntropyLoss is calculated using this formula:

$$
loss = -\log\left( \frac{\exp(x[class])}{\sum_j \exp(x_j)} \right)
$$

that I think it only addresses the $\log(q_i)$ part in the first formula. 

Why does PyTorch use a different formula for the cross-entropy?
When you one-hot-encode your labels with $p_i \in \{0,1\}$ you get $p_i = 0$ iff $i$ is not correct and, equivalently, $p_i =1$ iff $i$ is correct. 

Hence, $p_i \log(q_i) = 0 \log(q_i) = 0 $ for all classes except the "truth" and $p_i \log(q_i) = 1 \log(q_i) = \log(q_i) $ for the correct prediction. 

Therefore, your loss reduces to:
$$
H(p,q) = - \sum p_i \log(q_i) = - \log(q_{truth})
$$