@James_Reed  Thank you very much for your answer, you saved my life!
Yes, I want to do something similar like profiler. However, the profiler requires to truly run the model, while I just want to get a rough prediction of the cost based on its input/output size (just as tf’s grappler 1 does). Then using torch’s profiler along seems not working.
I want to implement a custom cost estimator based on every op , and finally get the final model cost.
In this way, I want to get the graph and use the code like your suggestion:
Costs totalcost ;
for (Node * n : forward_method.graph()->nodes()) {
     totalcost += predictCost(n);
}

Thank you again, your reply really helps!