daquexian / onnx-simplifier

Simplify your onnx model
Apache License 2.0
3.79k stars 380 forks source link

[BUG] crash with big model file #291

Open suhaifeng6666 opened 1 year ago

suhaifeng6666 commented 1 year ago

Describe the bug Trying on a working model, simplifier crashes.

Model https://drive.google.com/file/d/108ism8iz21sDw8hP-NgX4B-rRk1ZmNFV/view?usp=sharing

PINTO0309 commented 1 year ago

onnxsim==0.4.17

$ onnxsim model.onnx model.onnx
Your model contains "Tile" ops or/and "ConstantOfShape" ops. Folding these ops can make the simplified model much larger. If it is not expected, please specify "--no-large-tensor" (which will lose 
some optimization chances)
Simplifying...
Finish! Here is the difference:
┏━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┓
┃                       ┃ Original Model ┃ Simplified Model ┃
┡━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━┩
│ Add                   │ 393            │ 393              │
│ Cast                  │ 290            │ 2                │
│ Concat                │ 335            │ 334              │
│ Constant              │ 2506           │ 0                │
│ ConstantOfShape       │ 33             │ 32               │
│ Conv                  │ 98             │ 98               │
│ Cos                   │ 1              │ 1                │
│ Div                   │ 262            │ 230              │
│ Equal                 │ 1              │ 1                │
│ Erf                   │ 16             │ 16               │
│ Expand                │ 1              │ 1                │
│ Gather                │ 561            │ 529              │
│ Gemm                  │ 24             │ 24               │
│ InstanceNormalization │ 61             │ 61               │
│ MatMul                │ 224            │ 224              │
│ Mul                   │ 446            │ 445              │
│ Pow                   │ 48             │ 48               │
│ ReduceMean            │ 96             │ 96               │
│ Reshape               │ 411            │ 410              │
│ Resize                │ 3              │ 3                │
│ Shape                 │ 623            │ 590              │
│ Sigmoid               │ 47             │ 47               │
│ Sin                   │ 1              │ 1                │
│ Slice                 │ 34             │ 34               │
│ Softmax               │ 32             │ 32               │
│ Sqrt                  │ 48             │ 48               │
│ Sub                   │ 48             │ 48               │
│ Transpose             │ 192            │ 192              │
│ Unsqueeze             │ 1022           │ 958              │
│ Where                 │ 1              │ 1                │
│ Model Size            │ 1.6GiB         │ 1.6GiB           │
└───────────────────────┴────────────────┴──────────────────┘