Open siahuat0727 opened 8 months ago
Can you test with the torch.onnx.dynamo_export API, which will preserve the names? Thanks.
Can you test with the torch.onnx.dynamo_export API, which will preserve the names? Thanks.
@justinchuby Thank you so much for your reply!
Yes, I tried the torch.onnx.dynamo_export and obtained the following result:
When I flattened it using onnx.inliner.inline_local_functions, I got:
Both results are significantly different from those obtained with torch.onnx.export. For example, neither of them contains the "Conv" node.
Do you know how to export an ONNX model with "Conv" nodes using torch.onnx.dynamo_export?
The conv nodes are likely in the If sub-graphs. We are developing a tool to simplify this graph. @BowenBao may be able to comment more
You may now use onnxscript.optimizer.optimize()
to clean up the model.
You may now use
onnxscript.optimizer.optimize()
to clean up the model.
Thank you so much for the information!
I'm working on a project where I need to map FX node names to their corresponding ONNX node names, particularly after exporting an FX
GraphModule
to ONNX. The naive approach I've been using involves iterating through node types and maintaining a counter to track node names, as shown in the pseudo-code below:However, certain FX nodes like
GELU
are decomposed into multiple nodes during ONNX conversion. This decomposition results in inaccurate mappings, particularly for nodes likeAdd
that cannot be correctly mapped with this straightforward solution.Additionally, other FX nodes like
aten.linear
may convert to eitherGemm
orMatmul
in ONNX, depending on conditions that are currently unclear to me.Here's an example using a simple model that illustrates the issue:
The FX tabular output for this model is as follows:
And the corresponding ONNX graph shows that the last
Add
node is namedAdd_2
instead ofAdd
, due to the decomposition ofGELU
into additional nodes. So I get a wrong mapping fromadd_tensor
toAdd
.I am seeking advice on how to enhance the robustness of this mapping process. Is there an established method for accurately mapping FX node names to ONNX node names, especially in cases where nodes are decomposed or have conditional mappings?