From Tensors to other structure and back

Hi,
I’m trying to incorporate graphical structure in to my model. Specifically, I’m trying to convert an out_tensors to a graph in networkx package (there’re graph algorithms that aren’t expressible as operations on tensors) and then go back to tensors. In my understanding, autograd won’t work here and I’m unsure of a suitable way to go on. This is non-trivial to me and I hope you all can help me with this.
Thanks in advance!