onnx / onnx/optimizer

local functions missed when optimizing a model

Open
#136 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
834
Forks
109
Avg merge
6h 55m
Merged PRs (30d)
2

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing ONNX's PrepareOutput and Graph update paths, then inspect how onnxsim processes model.functions and FunctionProto definitions. Reproduce the issue with the provided torch.onnx.export example using export_modules_as_functions. Done means optimized models retain their functions and remain valid.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python, pytorch
Domain
machine-learning, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.