Skip to content

local functions missed when optimizing a model #136

@AlexHJH

Description

@AlexHJH

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
}
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions