@Ben_Nicholl, may I suggest that this question probably better belongs to Issues · huggingface/transformers · GitHub or https://discuss.huggingface.co/ 1 as this doesn’t have much to do with pytorch.
You will be able to see quickly in modeling_xlnet.py that some parameters don’t always participate in the graph and then, of course, they won’t have the grad set. There are quire a few conditionals, so unless you hit the right combination that includes those, this is what you get. I hope it makes sense.
I am not familiar with this particular model myself, but quickly searching for the params @ptrblck identified all appeared enclosed in some if.