A for loop on gr.nodes() should work on a graph gr:
import torch
import torchvision
scripted=torch.jit.script(torchvision.models.resnet18().eval())
frozen_module = torch.jit.freeze(scripted)
gr = frozen_module.inlined_graph
for n in gr.nodes():
    print(n)

Note that it is easy into trouble

if you change the graph while it is iterated over,
if the graph goes out of scope and disappears (e.g. that’s why I assign it to a variable).
I tried to make disappearing nodes not crash but I don’t exactly recall the state of the iterator implementation here.

Best regards
Thomas