This question is not related to the distributed package so please change the category.
But I think this is the logic for log_prob that you are looking for: pytorch/categorical.py at master · pytorch/pytorch · GitHub