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

local functions missed when optimizing a model #136

Open
AlexHJH opened this issue Jul 31, 2023 · 0 comments
Open

local functions missed when optimizing a model #136

AlexHJH opened this issue Jul 31, 2023 · 0 comments

Comments

@AlexHJH
Copy link

AlexHJH commented Jul 31, 2023

ONNX模型优化时,使用PrepareOutput创建输入model的副本,并在优化后将Graph更新到model proto内,这两个接口在onnx内,都未将functions复制到结果模型上,onnxsim也未考虑优化model.functions的情况,同时也直接丢失了functions内的全部FunctionProto定义
此类情况,在使用torch.onnx.export开启export_modules_as_functions时出现,可以通过以下代码获得一个问题模型

import timm
import torch
import torch.nn as nn
module = timm.create_model("vit_tiny_r_s16_p8_224")

torch.onnx.export(
module,
(torch.ones([1, 3, 224, 224], dtype=torch.float32), ),
"test.onnx",
opset_version=15,
export_modules_as_functions={
timm.models.vision_transformer_hybrid.HybridEmbed,
nn.GELU
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant