So when dim=1 it compute it along dimension 1 and consider all the channels together basically. That part makes sense. Though the output is still the size of [ 20, 20] not [1, 20, 20] 
maybe it is because im using pytorch 0.3.0? 
input1 = torch.abs(torch.randn(1,2,10, 10))
input2 = torch.abs(torch.randn(1,2,10, 10))
res1 = F.cosine_similarity(input1, input2, 1)
print(res1)
print(res1.size())

output:

 0.9249  0.9581  0.9964  0.9384  1.0000  0.7050  0.7339  0.6200  0.3887  0.8247
 0.8397  0.9821  0.8112  0.9300  0.9955  0.9970  0.9599  0.9871  0.9546  0.2274
 0.9980  0.9903  0.9990  0.9977  0.5832  0.7850  0.9049  0.8266  0.9084  0.9682
 0.9949  0.9895  0.8929  0.8659  0.7442  0.5848  0.9990  0.8466  0.9778  1.0000
 0.9786  0.9972  0.5892  0.2555  0.6968  0.7367  0.9168  0.8906  0.8962  0.0922
 0.8235  0.5739  0.5015  0.9879  0.5706  0.9696  0.9995  0.7057  0.9877  0.8018
 0.8789  0.9820  0.7538  0.9882  0.9999  0.2345  0.7596  0.9877  0.9749  0.9463
 0.9243  0.9671  0.7078  0.3916  1.0000  0.9979  0.9256  1.0000  0.9740  0.7148
 0.9987  0.9342  0.2270  0.8224  0.9970  0.9744  0.8185  0.9213  0.8891  0.9911
 0.9607  0.9490  0.9766  0.9463  0.7205  0.9997  0.9150  0.7641  0.5461  0.7848
[torch.FloatTensor of size 10x10]

torch.Size([10, 10])

but the second part that i put dim=0 gives me all values equal to 1 and it does not make sense yet:
i looked at the code, but can you please tell me one more time why it gives output of 1?
res1 = F.cosine_similarity(input1, input2, 0)
print(res1)
print(res1.size())

output:
(0 ,.,.) = 
   1   1   1   1   1   1   1   1   1   1
   1   1   1   1   1   1   1   1   1   1
   1   1   1   1   1   1   1   1   1   1
   1   1   1   1   1   1   1   1   1   1
   1   1   1   1   1   1   1   1   1   1
   1   1   1   1   1   1   1   1   1   1
   1   1   1   1   1   1   1   1   1   1
   1   1   1   1   1   1   1   1   1   1
   1   1   1   1   1   1   1   1   1   1
   1   1   1   1   1   1   1   1   1   1

(1 ,.,.) = 
   1   1   1   1   1   1   1   1   1   1
   1   1   1   1   1   1   1   1   1   1
   1   1   1   1   1   1   1   1   1   1
   1   1   1   1   1   1   1   1   1   1
   1   1   1   1   1   1   1   1   1   1
   1   1   1   1   1   1   1   1   1   1
   1   1   1   1   1   1   1   1   1   1
   1   1   1   1   1   1   1   1   1   1
   1   1   1   1   1   1   1   1   1   1
   1   1   1   1   1   1   1   1   1   1
[torch.FloatTensor of size 2x10x10]

torch.Size([2, 10, 10])