My similar issue had appeared after setting the torch default device to cuda… it seems that torch.onnx.export depends on that.
So to workaround it, i have changed the default device to cpu right before the export, then changed it back to cuda after the export. Hope this helps.