Well, the code looks alright.
Regarding the validity of the code, it seems the PyTorch implementation uses the dot product and vector norms 29 to calculate the cosine while your code seems a bit more complicated.
Are you sure this line is correct:
torch.acos(torch.sum(torch.mul(input,target),dim=1,keepdim=True))

I have my doubts about the torch.acos as currently input and target are just normal vectors, i.e. both should be normalized with the product of both norms.
Could you check it and see if I’m mistaken?