Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizing Node Ordering in ONNX Graphs: Ensuring Correct Sequence for Model Generation #6017

Open
kumar-utkarsh0317 opened this issue Mar 12, 2024 · 1 comment
Labels
question Questions about ONNX

Comments

@kumar-utkarsh0317
Copy link

I am working on generating an ONNX converter for some framework, and previously, I was iterating through the nodes of the ONNX model to generate a feed-forward network corresponding to each node of the ONNX model. However, after analyzing several ONNX models and the order of their nodes, I realized that I can't simply iterate in the order they were loaded because their order was pretty random.

So, I think I have to pick one node and to get the subsequent node in the model, I have to check which node is taking the output of the previous node. By doing this, I could get the next node in the model.

I think to get the first node of the model, I have to check which has such input with no initializer for that, and that node will be the first one.

I am using this approach to generate a model from an ONNX model. Is the way I am following correct, or if there is any other optimized way, then please do tell me.

@kumar-utkarsh0317 kumar-utkarsh0317 added the question Questions about ONNX label Mar 12, 2024
@gramalingam
Copy link
Contributor

ONNX standard requires that the nodes be topologically sorted. If the input model satisfies this, then you can just iterate through them in order. However, some model generators may not created topologically sorted nodes. If so, it is best solved by doing a topological sort of the nodes (with respect to data dependences encoded in the input/outputs).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Questions about ONNX
Projects
None yet
Development

No branches or pull requests

2 participants