onnx / optimizer

Actively maintained ONNX Optimizer
Apache License 2.0
647 stars 90 forks source link

Optimizer reports "Unresolved value references" since v0.3.0 #104

Open zhenhuaw-me opened 2 years ago

zhenhuaw-me commented 2 years ago

Via onnxcli https://github.com/zhenhuaw-me/onnxcli/issues/28

The model: https://github.com/zhenhuaw-me/onnxcli/blob/v0.2.0/assets/tests/conv.float32.onnx

Last pass version: v0.2.7

Log

2022-11-13 12:15:29,988 D [testing][test_dispatcher.py:34] Running optimize ./assets/tests/conv.float32.onnx optimized.onnx
2022-11-13 12:15:29,988 D [onnxcli][dispatcher.py:25] Running ['optimize', './assets/tests/conv.float32.onnx', 'optimized.onnx']
2022-11-13 12:15:29,994 I [onnxcli][optimize.py:27] Running <Optimization> on model ./assets/tests/conv.float32.onnx
2022-11-13 12:15:30,483 W [onnxcli][optimize.py:38] No optimization passes specified, running all available passes: ['rename_input_output', 'set_unique_name_for_nodes', 'nop', 'eliminate_nop_cast', 'eliminate_nop_dropout', 'eliminate_nop_flatten', 'extract_constant_to_initializer', 'eliminate_if_with_const_cond', 'eliminate_nop_monotone_argmax', 'eliminate_nop_pad', 'eliminate_nop_expand', 'eliminate_shape_gather', 'eliminate_slice_after_shape', 'eliminate_nop_transpose', 'fuse_add_bias_into_conv', 'fuse_bn_into_conv', 'fuse_consecutive_concats', 'fuse_consecutive_log_softmax', 'fuse_consecutive_reduce_unsqueeze', 'fuse_consecutive_squeezes', 'fuse_consecutive_transposes', 'fuse_matmul_add_bias_into_gemm', 'fuse_pad_into_conv', 'fuse_pad_into_pool', 'fuse_transpose_into_gemm', 'replace_einsum_with_matmul', 'lift_lexical_references', 'split_init', 'split_predict', 'fuse_concat_into_reshape', 'eliminate_nop_reshape', 'eliminate_deadend', 'eliminate_identity', 'eliminate_shape_op', 'eliminate_unused_initializer', 'eliminate_duplicate_initializer']
Traceback (most recent call last):
  File "/Users/zhenhuaw/workspace/ONNX/onnxcli/tests/test_dispatcher.py", line 55, in <module>
    test_dispatch_core()
  File "/Users/zhenhuaw/workspace/ONNX/onnxcli/tests/test_dispatcher.py", line 36, in test_dispatch_core
    dispatch_core(shlex.split(cmd))
  File "/Users/zhenhuaw/workspace/ONNX/onnxcli/onnxcli/dispatcher.py", line 40, in dispatch_core
    args.func(args)
  File "/Users/zhenhuaw/workspace/ONNX/onnxcli/onnxcli/optimize.py", line 44, in run
    optimized = onnxoptimizer.optimize(model, passes)
  File "/Users/zhenhuaw/workspace/toolchain/runtime.git/python/venv/onnx/lib/python3.10/site-packages/onnxoptimizer/__init__.py", line 50, in optimize
    optimized_model_str = C.optimize(model_str, passes)
RuntimeError: Unresolved value references: Conv2D_bias,Variable/read,
HSQ79815 commented 1 year ago

I reproduced this issue when pass is lift_lexical_references

# PYTHONPATH=/root/optimizer/ onnxoptimizer conv.float32.onnx conv.float32_sim.onnx -p lift_lexical_references
Traceback (most recent call last):
  File "/usr/bin/onnxoptimizer", line 33, in <module>
    sys.exit(load_entry_point('onnxoptimizer', 'console_scripts', 'onnxoptimizer')())
  File "/root/optimizer/onnxoptimizer/onnxoptimizer_main.py", line 77, in main
    model = onnxoptimizer.optimize(model=model, passes=passes, fixed_point=args.fixed_point)
  File "/root/optimizer/onnxoptimizer/__init__.py", line 50, in optimize
    optimized_model_str = C.optimize(model_str, passes)
RuntimeError: Unresolved value references: Conv2D_bias,Variable/read,