I guess you should first inspect if a pre-compiled pytorch is already using mkldnn:
import torch
print(*torch.__config__.show().split("\n"),sep="\n")

If USE_MKLDNN=ON, then you are already using it. Otherwise, the other simplest way I have in mind if you want to bind Pytorch and mkldnn is to build it from source.