I think fot size_average=True you have to sum the weighted loss and divide by the sum of the used weights:
CE = torch.sum(weights.index_select(0, target)*(-torch.log(p_t))) / torch.sum(weights.index_select(0, target))

This should yield the same result.