onnxslim 0.1.83__tar.gz → 0.1.84__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- onnxslim-0.1.84/.github/ISSUE_TEMPLATE/bug_report.md +30 -0
- onnxslim-0.1.84/.github/ISSUE_TEMPLATE/custom.md +10 -0
- onnxslim-0.1.84/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/PKG-INFO +1 -1
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/pattern/elimination/slice.py +15 -8
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/pattern/fusion/concat_reshape.py +3 -1
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/pattern/fusion/convadd.py +2 -6
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/pattern/fusion/convbn.py +3 -7
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/pattern/fusion/convmul.py +3 -4
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/pattern/fusion/gemm.py +7 -5
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/onnx_graphsurgeon/ir/graph.py +0 -103
- {onnxslim-0.1.83 → onnxslim-0.1.84}/pyproject.toml +6 -4
- onnxslim-0.1.84/tests/test_amd.py +103 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/.codespellignore +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/.github/FUNDING.yml +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/.github/workflows/ci.yml +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/.github/workflows/format.yml +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/.github/workflows/nightly-test.yml +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/.github/workflows/python-publish.yml +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/.gitignore +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/.prettierignore +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/CODE_OF_CONDUCT.md +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/CONTRIBUTING.md +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/LICENSE +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/README.md +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/README_CN.md +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/assets/logo/onnxslim-banner-light.svg +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/assets/logo/onnxslim-banner.svg +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/assets/logo/onnxslim-logo-os-bw.svg +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/assets/logo/onnxslim-logo-os-white.svg +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/assets/logo/onnxslim-logo-os.svg +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/bin/onnxslim +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/docs/_static/style.css +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/docs/_templates/layout.html +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/docs/conf.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/docs/index.rst +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/docs/main/toc.rst +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/docs/requirements.txt +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/examples/Boost-onnx-load-speed-by-10/342/200/22315-percent-with-onnxslim-python-package.ipynb" +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/examples/common_subexpression_elimination/README.md +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/examples/common_subexpression_elimination/cse_demo.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/examples/input_shape_modification/README.md +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/examples/model_inspect/README.md +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/examples/output_modification/README.md +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/format.sh +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/images/after_cse.png +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/images/before_cse.png +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/images/cse.png +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/images/input_shape_modification.jpg +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/images/model_inspect.jpg +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/images/onnxslim.gif +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/images/output_modification.jpg +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/__main__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/argparser.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/cli/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/cli/_main.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/optimization/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/optimization/dead_node_elimination.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/optimization/subexpression_elimination.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/optimization/weight_tying.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/pattern/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/pattern/elimination/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/pattern/elimination/concat.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/pattern/elimination/reshape.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/pattern/elimination/reshape_as.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/pattern/elimination/unsqueeze.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/pattern/fusion/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/pattern/fusion/gelu.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/pattern/fusion/padconv.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/pattern/fusion/reduce.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/pattern/registry.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/aten_ops/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/aten_ops/argmax.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/aten_ops/bitwise_or.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/aten_ops/diagonal.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/aten_ops/embedding.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/aten_ops/group_norm.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/aten_ops/min_max.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/aten_ops/multinomial.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/aten_ops/numpy_t.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/aten_ops/pool2d.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/aten_ops/unfold.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/aten_ops/upsample.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/base.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/context.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/attention/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/attention/attention.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/attention/decoder_masked_mha.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/attention/gated_relative_position_bias.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/attention/longformer_attention.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/attention/multi_head_attention.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/attention/multi_scale_deformable_attn.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/attention/packed_attention.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/attention/packed_multi_head_attention.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/attention/remove_padding.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/attention/restore_padding.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/misc/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/misc/bias_add.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/misc/bias_gelu.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/misc/bias_split_gelu.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/misc/fast_gelu.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/misc/gelu.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/misc/gemm_fast_gelu.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/misc/gemm_float8.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/misc/python_op.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/misc/quick_gelu.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/misc/rotary_embedding.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/normalization/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/normalization/embed_layer_normalization.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/normalization/group_norm.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/normalization/layer_normalization.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/normalization/simplified_layer_normalization.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/normalization/skip_group_norm.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/normalization/skip_layer_normalization.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/contrib_ops/normalization/skip_simplified_layer_normalization.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/registry.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/control_flow/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/control_flow/if_op.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/control_flow/loop.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/control_flow/scan.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/math/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/math/_symbolic_compute.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/math/add.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/math/div.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/math/einsum.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/math/equal.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/math/floor.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/math/matmul.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/math/matmul_integer.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/math/max.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/math/min.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/math/mul.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/math/neg.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/math/reduce_prod.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/math/reduce_sum.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/math/sub.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/math/where.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/misc/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/misc/array_feature_extractor.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/misc/cast.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/misc/category_mapper.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/misc/compress.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/misc/constant.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/misc/constant_of_shape.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/misc/dequantize_linear.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/misc/non_max_suppression.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/misc/non_zero.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/misc/one_hot.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/misc/quantize_linear.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/misc/range.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/misc/relative_position_bias.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/misc/resize.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/misc/scatter_elements.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/misc/softmax_cross_entropy_loss.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/misc/top_k.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/nn/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/nn/all_reduce.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/nn/average_pool.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/nn/batch_normalization.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/nn/conv.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/nn/cum_sum.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/nn/identity.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/nn/max_pool.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/nn/memcpy_from_host.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/nn/memcpy_to_host.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/nn/moe.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/nn/nhwc_conv.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/nn/reciprocal.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/nn/round.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/sequence/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/sequence/concat_from_sequence.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/sequence/sequence_at.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/sequence/sequence_insert.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/sequence/split_to_sequence.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/sequence/zip_map.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/tensor/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/tensor/concat.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/tensor/expand.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/tensor/gather.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/tensor/gather_elements.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/tensor/gather_nd.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/tensor/pad.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/tensor/reshape.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/tensor/shape.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/tensor/size.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/tensor/slice.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/tensor/split.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/tensor/squeeze.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/tensor/tile.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/tensor/transpose.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/standard_ops/tensor/unsqueeze.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/core/shape_inference/utils.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/misc/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/misc/tabulate.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/_sympy/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/_sympy/functions.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/_sympy/numbers.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/_sympy/printers.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/_sympy/solve.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/_sympy/symbol.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/onnx_graphsurgeon/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/onnx_graphsurgeon/exporters/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/onnx_graphsurgeon/exporters/base_exporter.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/onnx_graphsurgeon/exporters/onnx_exporter.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/onnx_graphsurgeon/graph_pattern/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/onnx_graphsurgeon/graph_pattern/graph_pattern.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/onnx_graphsurgeon/importers/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/onnx_graphsurgeon/importers/base_importer.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/onnx_graphsurgeon/importers/onnx_importer.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/onnx_graphsurgeon/ir/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/onnx_graphsurgeon/ir/function.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/onnx_graphsurgeon/ir/node.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/onnx_graphsurgeon/ir/tensor.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/onnx_graphsurgeon/logger/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/onnx_graphsurgeon/logger/logger.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/onnx_graphsurgeon/util/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/onnx_graphsurgeon/util/exception.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/onnx_graphsurgeon/util/misc.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/third_party/symbolic_shape_infer.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/utils.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/onnxslim/version.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/tests/conftest.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/tests/exporters/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/tests/exporters/onnx/__init__.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/tests/exporters/onnx/test_export_cli.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/tests/exporters/onnx/utils_tests.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/tests/test_benchmark.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/tests/test_cli_main.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/tests/test_coverage.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/tests/test_dead_node_elimination.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/tests/test_elimination_patterns.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/tests/test_folder.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/tests/test_fusion_patterns.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/tests/test_modelzoo.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/tests/test_nvidia.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/tests/test_onnx_nets.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/tests/test_onnxslim.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/tests/test_pattern_generator.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/tests/test_pattern_matcher.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/tests/test_shape_folding.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/tests/test_subexpression_elimination.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/tests/test_symbolic_shape_inference.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/tests/test_ultralytics.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/tests/test_utils.py +0 -0
- {onnxslim-0.1.83 → onnxslim-0.1.84}/tests/utils.py +0 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Bug report
|
|
3
|
+
about: Create a report to help us improve
|
|
4
|
+
title: ''
|
|
5
|
+
labels: bug
|
|
6
|
+
assignees: inisis
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
**Describe the bug**
|
|
11
|
+
A clear and concise description of what the bug is.
|
|
12
|
+
|
|
13
|
+
**To Reproduce**
|
|
14
|
+
Steps to reproduce the bug:
|
|
15
|
+
|
|
16
|
+
**Expected behavior**
|
|
17
|
+
A clear and concise description of what you expected to happen.
|
|
18
|
+
|
|
19
|
+
**Screenshots**
|
|
20
|
+
If applicable, add screenshots to help explain your problem.
|
|
21
|
+
|
|
22
|
+
**Environment:**
|
|
23
|
+
run the script and paste the output.
|
|
24
|
+
```
|
|
25
|
+
python -c "import importlib; pkgs=['onnx','onnxruntime','onnxslim']; \
|
|
26
|
+
[print(f'{p}: {importlib.import_module(p).__version__}') if importlib.util.find_spec(p) else print(f'{p}: missing') for p in pkgs]"
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**Additional context**
|
|
30
|
+
Add any other context about the problem here.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Feature request
|
|
3
|
+
about: Suggest an idea for this project
|
|
4
|
+
title: ''
|
|
5
|
+
labels: ''
|
|
6
|
+
assignees: ''
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
**Is your feature request related to a problem? Please describe.**
|
|
11
|
+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
|
12
|
+
|
|
13
|
+
**Describe the solution you'd like**
|
|
14
|
+
A clear and concise description of what you want to happen.
|
|
15
|
+
|
|
16
|
+
**Describe alternatives you've considered**
|
|
17
|
+
A clear and concise description of any alternative solutions or features you've considered.
|
|
18
|
+
|
|
19
|
+
**Additional context**
|
|
20
|
+
Add any other context or screenshots about the feature request here.
|
|
@@ -39,6 +39,16 @@ class SlicePatternMatcher(PatternMatcher):
|
|
|
39
39
|
first_slice_node_axes = first_slice_node_inputs[3].values.tolist()
|
|
40
40
|
first_slice_node_steps = first_slice_node_inputs[4].values.tolist()
|
|
41
41
|
|
|
42
|
+
# Check all users upfront before modifying the graph.
|
|
43
|
+
# If any user has overlapping axes, skip the optimization entirely
|
|
44
|
+
# to avoid corrupting the graph (fixes GitHub issue #277).
|
|
45
|
+
for user_node in first_slice_node_users:
|
|
46
|
+
second_slice_node_inputs = list(user_node.inputs)
|
|
47
|
+
second_slice_node_axes = second_slice_node_inputs[3].values.tolist()
|
|
48
|
+
new_axes = first_slice_node_axes + second_slice_node_axes
|
|
49
|
+
if len(new_axes) != len(set(new_axes)):
|
|
50
|
+
return match_case
|
|
51
|
+
|
|
42
52
|
for user_node in first_slice_node_users:
|
|
43
53
|
second_slice_node = user_node
|
|
44
54
|
second_slice_node_inputs = list(second_slice_node.inputs)
|
|
@@ -52,33 +62,30 @@ class SlicePatternMatcher(PatternMatcher):
|
|
|
52
62
|
new_axes = first_slice_node_axes + second_slice_node_axes
|
|
53
63
|
new_steps = first_slice_node_steps + second_slice_node_steps
|
|
54
64
|
|
|
55
|
-
if len(new_axes) != len(set(new_axes)):
|
|
56
|
-
continue
|
|
57
|
-
|
|
58
65
|
inputs = []
|
|
66
|
+
output_name = second_slice_node.outputs[0].name
|
|
59
67
|
inputs.extend(
|
|
60
68
|
(
|
|
61
69
|
next(iter(first_slice_node.inputs)),
|
|
62
70
|
gs.Constant(
|
|
63
|
-
|
|
71
|
+
output_name + "_starts",
|
|
64
72
|
values=np.array(new_starts, dtype=np.int64),
|
|
65
73
|
),
|
|
66
74
|
gs.Constant(
|
|
67
|
-
|
|
75
|
+
output_name + "_ends",
|
|
68
76
|
values=np.array(new_ends, dtype=np.int64),
|
|
69
77
|
),
|
|
70
78
|
gs.Constant(
|
|
71
|
-
|
|
79
|
+
output_name + "_axes",
|
|
72
80
|
values=np.array(new_axes, dtype=np.int64),
|
|
73
81
|
),
|
|
74
82
|
gs.Constant(
|
|
75
|
-
|
|
83
|
+
output_name + "_steps",
|
|
76
84
|
values=np.array(new_steps, dtype=np.int64),
|
|
77
85
|
),
|
|
78
86
|
)
|
|
79
87
|
)
|
|
80
88
|
outputs = list(second_slice_node.outputs)
|
|
81
|
-
|
|
82
89
|
first_slice_node.outputs.clear()
|
|
83
90
|
second_slice_node.inputs.clear()
|
|
84
91
|
second_slice_node.outputs.clear()
|
|
@@ -36,9 +36,11 @@ class ConcatReshapeMatcher(PatternMatcher):
|
|
|
36
36
|
def rewrite(self, opset=11):
|
|
37
37
|
match_case = {}
|
|
38
38
|
concat_node = self.concat_0
|
|
39
|
+
reshape_node = self.reshape_0
|
|
39
40
|
index = next(idx for idx, i in enumerate(concat_node.inputs) if isinstance(i, gs.Variable))
|
|
41
|
+
output_name = reshape_node.outputs[0].name
|
|
40
42
|
constant = gs.Constant(
|
|
41
|
-
|
|
43
|
+
output_name + "_fixed",
|
|
42
44
|
values=np.array([-1], dtype=np.int64),
|
|
43
45
|
)
|
|
44
46
|
concat_node.inputs.pop(index)
|
|
@@ -44,12 +44,8 @@ class ConvAddMatcher(PatternMatcher):
|
|
|
44
44
|
inputs = []
|
|
45
45
|
inputs.append(next(iter(conv_node.inputs)))
|
|
46
46
|
inputs.append(conv_weight)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
bias_name = f"{weight_name[:-6]}bias"
|
|
50
|
-
else:
|
|
51
|
-
bias_name = f"{weight_name}_bias"
|
|
52
|
-
inputs.append(gs.Constant(bias_name, values=conv_bias))
|
|
47
|
+
output_name = add_node.outputs[0].name
|
|
48
|
+
inputs.append(gs.Constant(output_name + "_bias", values=conv_bias))
|
|
53
49
|
outputs = list(add_node.outputs)
|
|
54
50
|
|
|
55
51
|
conv_node.outputs.clear()
|
|
@@ -52,15 +52,11 @@ class ConvBatchNormMatcher(PatternMatcher):
|
|
|
52
52
|
|
|
53
53
|
inputs = []
|
|
54
54
|
inputs.append(next(iter(conv_transpose_node.inputs)))
|
|
55
|
-
|
|
56
|
-
if weight_name.endswith("weight"):
|
|
57
|
-
bias_name = f"{weight_name[:-6]}bias"
|
|
58
|
-
else:
|
|
59
|
-
bias_name = f"{weight_name}_bias"
|
|
55
|
+
output_name = bn_node.outputs[0].name
|
|
60
56
|
inputs.extend(
|
|
61
57
|
(
|
|
62
|
-
gs.Constant(
|
|
63
|
-
gs.Constant(
|
|
58
|
+
gs.Constant(output_name + "_weight", values=conv_w),
|
|
59
|
+
gs.Constant(output_name + "_bias", values=conv_b),
|
|
64
60
|
)
|
|
65
61
|
)
|
|
66
62
|
outputs = list(bn_node.outputs)
|
|
@@ -38,14 +38,13 @@ class ConvMulMatcher(PatternMatcher):
|
|
|
38
38
|
inputs = []
|
|
39
39
|
inputs.append(next(iter(conv_node.inputs)))
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
inputs.append(gs.Constant(
|
|
41
|
+
output_name = mul_node.outputs[0].name
|
|
42
|
+
inputs.append(gs.Constant(output_name + "_weight", values=new_weight))
|
|
43
43
|
|
|
44
44
|
if len(conv_node.inputs) == 3:
|
|
45
45
|
conv_bias = conv_node.inputs[2].values
|
|
46
46
|
new_bias = conv_bias * mul_constant.squeeze()
|
|
47
|
-
|
|
48
|
-
inputs.append(gs.Constant(bias_name, values=new_bias))
|
|
47
|
+
inputs.append(gs.Constant(output_name + "_bias", values=new_bias))
|
|
49
48
|
|
|
50
49
|
outputs = list(mul_node.outputs)
|
|
51
50
|
|
|
@@ -76,7 +76,7 @@ class MatMulAddPatternMatcher(PatternMatcher):
|
|
|
76
76
|
output_variable.outputs.remove(add_node)
|
|
77
77
|
|
|
78
78
|
matmul_bias_transpose_constant = gs.Constant(
|
|
79
|
-
|
|
79
|
+
f"{matmul_node.name}_weight", values=matmul_bias_variable.values.T
|
|
80
80
|
)
|
|
81
81
|
|
|
82
82
|
inputs = []
|
|
@@ -143,7 +143,7 @@ class MatMulAddPatternMatcher(PatternMatcher):
|
|
|
143
143
|
output_variable.outputs.remove(add_node)
|
|
144
144
|
|
|
145
145
|
matmul_bias_transpose_constant = gs.Constant(
|
|
146
|
-
|
|
146
|
+
f"{matmul_node.name}_weight", values=matmul_bias_variable.values.T
|
|
147
147
|
)
|
|
148
148
|
|
|
149
149
|
inputs = []
|
|
@@ -235,14 +235,15 @@ class GemmMulPatternMatcher(PatternMatcher):
|
|
|
235
235
|
gemm_weight_fused = gemm_weight * mul_weight[:, None]
|
|
236
236
|
else:
|
|
237
237
|
gemm_weight_fused = gemm_weight * mul_weight
|
|
238
|
-
|
|
238
|
+
output_name = reshape_node.outputs[0].name
|
|
239
|
+
gemm_weight_fused_constant = gs.Constant(output_name + "_weight_fused", values=gemm_weight_fused)
|
|
239
240
|
gemm_node.inputs[1] = gemm_weight_fused_constant
|
|
240
241
|
|
|
241
242
|
if gemm_bias_constant:
|
|
242
243
|
gemm_bias = gemm_bias_constant.values
|
|
243
244
|
mul_bias = mul_bias_variable.values
|
|
244
245
|
gemm_bias_fused = gemm_bias * mul_bias
|
|
245
|
-
gemm_bias_fused_constant = gs.Constant(
|
|
246
|
+
gemm_bias_fused_constant = gs.Constant(output_name + "_bias_fused", values=gemm_bias_fused)
|
|
246
247
|
gemm_node.inputs[2] = gemm_bias_fused_constant
|
|
247
248
|
|
|
248
249
|
mul_node.replace_all_uses_with(reshape_node)
|
|
@@ -312,7 +313,8 @@ class GemmAddPatternMatcher(PatternMatcher):
|
|
|
312
313
|
and add_bias.ndim <= 2
|
|
313
314
|
):
|
|
314
315
|
gemm_bias_fused = gemm_bias + add_bias
|
|
315
|
-
|
|
316
|
+
output_name = reshape_node.outputs[0].name
|
|
317
|
+
gemm_bias_fused_constant = gs.Constant(output_name + "_bias_fused", values=gemm_bias_fused)
|
|
316
318
|
gemm_node.inputs[2] = gemm_bias_fused_constant
|
|
317
319
|
else:
|
|
318
320
|
return match_case
|
|
@@ -794,109 +794,6 @@ class Graph:
|
|
|
794
794
|
tensor.to_constant(arr)
|
|
795
795
|
tensor.inputs.clear()
|
|
796
796
|
|
|
797
|
-
# Pass 2: Run shape-tensor cast elision
|
|
798
|
-
def run_cast_elision(node):
|
|
799
|
-
"""Perform cast elision optimization on an ONNX node to eliminate unnecessary cast operations."""
|
|
800
|
-
import onnx
|
|
801
|
-
|
|
802
|
-
# Search for Cast(s) (from int -> float) -> intermediate operator (with float constants) -> Cast(s) (back to int)
|
|
803
|
-
# This pattern is problematic for TensorRT since these operations may be performed on Shape Tensors, which
|
|
804
|
-
# are not allowed to be floating point type. Attempt to fold the pattern here
|
|
805
|
-
VALID_CAST_ELISION_OPS = {
|
|
806
|
-
"Add",
|
|
807
|
-
"Sub",
|
|
808
|
-
"Mul",
|
|
809
|
-
"Div",
|
|
810
|
-
"Max",
|
|
811
|
-
"Min",
|
|
812
|
-
"Equal",
|
|
813
|
-
"Greater",
|
|
814
|
-
"Less",
|
|
815
|
-
"Concat",
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
if node.op not in VALID_CAST_ELISION_OPS:
|
|
819
|
-
return
|
|
820
|
-
|
|
821
|
-
# If the uncasted outputs of this node have any consumers other than "Cast" nodes,
|
|
822
|
-
# then we cannot elide the cast.
|
|
823
|
-
for out_tensor in node.outputs:
|
|
824
|
-
if out_tensor in self.outputs:
|
|
825
|
-
return
|
|
826
|
-
|
|
827
|
-
if any(out_node.op != "Cast" for out_node in out_tensor.outputs):
|
|
828
|
-
return
|
|
829
|
-
|
|
830
|
-
# Get list of input nodes that cast to float32
|
|
831
|
-
inp_casts = [
|
|
832
|
-
inp_node
|
|
833
|
-
for inp_tensor in node.inputs
|
|
834
|
-
for inp_node in inp_tensor.inputs
|
|
835
|
-
if inp_node.op == "Cast" and inp_node.attrs["to"] == onnx.TensorProto.DataType.FLOAT
|
|
836
|
-
]
|
|
837
|
-
|
|
838
|
-
# No cast nodes found, return early
|
|
839
|
-
if not inp_casts:
|
|
840
|
-
return
|
|
841
|
-
|
|
842
|
-
# Ensure that all input cast nodes are casting from the same type
|
|
843
|
-
inp_dtypes = [dtype_to_onnx(inp_cast.inputs[0].dtype) for inp_cast in inp_casts]
|
|
844
|
-
if len(set(inp_dtypes)) != 1:
|
|
845
|
-
return
|
|
846
|
-
|
|
847
|
-
final_type = inp_dtypes[0]
|
|
848
|
-
|
|
849
|
-
# Get list of output nodes that cast to int32 or int64
|
|
850
|
-
out_casts = [
|
|
851
|
-
out_node
|
|
852
|
-
for out_tensor in node.outputs
|
|
853
|
-
for out_node in out_tensor.outputs
|
|
854
|
-
if out_node.op == "Cast"
|
|
855
|
-
and out_node.attrs["to"] in {onnx.TensorProto.DataType.INT32, onnx.TensorProto.DataType.INT64}
|
|
856
|
-
]
|
|
857
|
-
|
|
858
|
-
# No cast node found on outputs, return early
|
|
859
|
-
if not out_casts:
|
|
860
|
-
return
|
|
861
|
-
|
|
862
|
-
# Ensure that all output cast nodes are casting to the same type and that this
|
|
863
|
-
# matches the original type before the inputs were casted.
|
|
864
|
-
out_dtypes = [out_cast.attrs["to"] for out_cast in out_casts]
|
|
865
|
-
if len(set(out_dtypes)) != 1 or out_dtypes[0] != final_type:
|
|
866
|
-
return
|
|
867
|
-
|
|
868
|
-
# If all checks passed, reconnect inputs/outputs to the consumers/producers
|
|
869
|
-
# of the Cast nodes.
|
|
870
|
-
# Note that we need to be careful in how we rebind tensors since they may
|
|
871
|
-
# be used by multiple nodes. Thus, it is not necessarily safe to assume that
|
|
872
|
-
# `cast_node.inputs[0].outputs[0] == cast_node`.
|
|
873
|
-
for index, inp in enumerate(node.inputs):
|
|
874
|
-
if isinstance(inp, Constant):
|
|
875
|
-
inp.values = inp.values.astype(onnx.helper.tensor_dtype_to_np_dtype(final_type))
|
|
876
|
-
|
|
877
|
-
for cast in inp_casts:
|
|
878
|
-
if cast.outputs[0] == inp:
|
|
879
|
-
node.inputs[index] = cast.inputs[0]
|
|
880
|
-
|
|
881
|
-
for index, out in enumerate(node.outputs):
|
|
882
|
-
for cast in out_casts:
|
|
883
|
-
if cast.inputs[0] == out:
|
|
884
|
-
out_tensor = cast.outputs[0]
|
|
885
|
-
out_tensor.inputs.clear() # Disconnect from Cast
|
|
886
|
-
node.outputs[index] = out_tensor
|
|
887
|
-
|
|
888
|
-
if fold_shapes:
|
|
889
|
-
# Perform shape tensor cast elision prior to most other folding
|
|
890
|
-
G_LOGGER.debug(f"Performing shape tensor cast elision in {self.name}")
|
|
891
|
-
try:
|
|
892
|
-
with self.node_ids():
|
|
893
|
-
for node in self.nodes:
|
|
894
|
-
run_cast_elision(node)
|
|
895
|
-
except Exception as err:
|
|
896
|
-
if not error_ok:
|
|
897
|
-
raise err
|
|
898
|
-
G_LOGGER.warning("'{:}' routine failed with: {:}".format("Shape tensor cast elision", err))
|
|
899
|
-
|
|
900
797
|
# Note that most of the remaining passes operate on a clone of the original graph.
|
|
901
798
|
# Pass 3: Find all descendants of constant tensors
|
|
902
799
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "onnxslim"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.84"
|
|
4
4
|
description = "OnnxSlim: A Toolkit to Help Optimize Onnx Model"
|
|
5
5
|
authors = [{ name = "inisis", email = "desmond.yao@buaa.edu.cn" }]
|
|
6
6
|
license = "MIT"
|
|
@@ -45,10 +45,11 @@ exclude = '''
|
|
|
45
45
|
dev = [
|
|
46
46
|
"coverage",
|
|
47
47
|
"pytest-cov",
|
|
48
|
-
"onnx<=1.16.1 ; python_version<'3.
|
|
49
|
-
"onnx>=1.12.0
|
|
48
|
+
"onnx<=1.16.1 ; python_version<'3.11'",
|
|
49
|
+
"onnx>=1.12.0 ; python_version>='3.11'",
|
|
50
50
|
"onnxruntime<1.20.0 ; python_version<'3.10'",
|
|
51
|
-
"onnxruntime>=1.20.0 ; python_version
|
|
51
|
+
"onnxruntime>=1.20.0,<1.22 ; python_version=='3.10'",
|
|
52
|
+
"onnxruntime>=1.20.0 ; python_version>='3.11'",
|
|
52
53
|
"onnxconverter-common",
|
|
53
54
|
"pytest",
|
|
54
55
|
"pytest-xdist",
|
|
@@ -85,6 +86,7 @@ testpaths = [
|
|
|
85
86
|
"tests/test_nvidia.py",
|
|
86
87
|
"tests/test_shape_folding.py",
|
|
87
88
|
"tests/test_coverage.py",
|
|
89
|
+
"tests/test_amd.py",
|
|
88
90
|
]
|
|
89
91
|
addopts = "-n auto" # enables pytest-xdist parallel workers
|
|
90
92
|
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import tempfile
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
import onnxruntime as ort
|
|
6
|
+
import pytest
|
|
7
|
+
|
|
8
|
+
import onnx
|
|
9
|
+
from onnxslim import slim
|
|
10
|
+
from onnxslim.utils import print_model_info_as_table, summarize_model
|
|
11
|
+
|
|
12
|
+
MODELZOO_PATH = "/data/modelzoo/amd"
|
|
13
|
+
|
|
14
|
+
def get_input_shapes(graph):
|
|
15
|
+
input_shapes = {}
|
|
16
|
+
for input in graph.input:
|
|
17
|
+
input_shapes[input.name] = [
|
|
18
|
+
s.dim_value for s in input.type.tensor_type.shape.dim
|
|
19
|
+
]
|
|
20
|
+
return input_shapes
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def load_dummy_data(input_shape, data_size=5):
|
|
24
|
+
"""Generate dummy input dicts."""
|
|
25
|
+
for _ in range(data_size):
|
|
26
|
+
data = {}
|
|
27
|
+
for name, shape in input_shape.items():
|
|
28
|
+
data[name] = np.random.rand(*shape).astype(np.float32)
|
|
29
|
+
yield data
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def run_slim_and_compare(original_path: str, slim_path: str, data_size=5):
|
|
33
|
+
"""
|
|
34
|
+
Compare ORT inference results between original and slim models.
|
|
35
|
+
Slimming must already be done outside this function.
|
|
36
|
+
"""
|
|
37
|
+
# ==== Prepare input shape ====
|
|
38
|
+
model = onnx.load(original_path)
|
|
39
|
+
input_shape = get_input_shapes(model.graph)
|
|
40
|
+
|
|
41
|
+
# fix dynamic dims → 1
|
|
42
|
+
for name, shape in input_shape.items():
|
|
43
|
+
input_shape[name] = [1 if s < 1 else s for s in shape]
|
|
44
|
+
|
|
45
|
+
data_gen = load_dummy_data(input_shape, data_size=data_size)
|
|
46
|
+
|
|
47
|
+
# ==== ORT sessions ====
|
|
48
|
+
opts = ort.SessionOptions()
|
|
49
|
+
opts.graph_optimization_level = ort.GraphOptimizationLevel.ORT_ENABLE_EXTENDED
|
|
50
|
+
opts.log_severity_level = 3
|
|
51
|
+
EP = ["CPUExecutionProvider"]
|
|
52
|
+
|
|
53
|
+
sess_orig = ort.InferenceSession(original_path, sess_options=opts, providers=EP)
|
|
54
|
+
sess_slim = ort.InferenceSession(slim_path, sess_options=opts, providers=EP)
|
|
55
|
+
|
|
56
|
+
# ==== Compare outputs ====
|
|
57
|
+
for inp in data_gen:
|
|
58
|
+
out1 = sess_orig.run([], inp)
|
|
59
|
+
out2 = sess_slim.run([], inp)
|
|
60
|
+
|
|
61
|
+
for a, b in zip(out1, out2):
|
|
62
|
+
if not np.array_equal(a, b):
|
|
63
|
+
return False
|
|
64
|
+
return True
|
|
65
|
+
|
|
66
|
+
class TestModelZoo:
|
|
67
|
+
def test_EliminationSlice(self, request):
|
|
68
|
+
name = request.node.originalname[len("test_") :]
|
|
69
|
+
filename = f"{MODELZOO_PATH}/{name}.onnx"
|
|
70
|
+
|
|
71
|
+
with tempfile.TemporaryDirectory() as tempdir:
|
|
72
|
+
slim_path = os.path.join(tempdir, f"{name}_slim.onnx")
|
|
73
|
+
slim(filename, slim_path)
|
|
74
|
+
ok = run_slim_and_compare(filename, slim_path)
|
|
75
|
+
assert ok, f"onnxslim output mismatch for model {name}!"
|
|
76
|
+
|
|
77
|
+
def test_sub_model(self, request):
|
|
78
|
+
name = request.node.originalname[len("test_") :]
|
|
79
|
+
filename = f"{MODELZOO_PATH}/{name}.onnx"
|
|
80
|
+
|
|
81
|
+
with tempfile.TemporaryDirectory() as tempdir:
|
|
82
|
+
slim_path = os.path.join(tempdir, f"{name}_slim.onnx")
|
|
83
|
+
slim(filename, slim_path)
|
|
84
|
+
|
|
85
|
+
# Check that the slimmed model has exactly 2 Cast nodes
|
|
86
|
+
model_info = summarize_model(slim_path)
|
|
87
|
+
cast_count = model_info.op_type_counts.get("Cast", 0)
|
|
88
|
+
assert cast_count == 2, f"Expected 2 Cast nodes, but found {cast_count}"
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
if __name__ == "__main__":
|
|
92
|
+
import sys
|
|
93
|
+
|
|
94
|
+
sys.exit(
|
|
95
|
+
pytest.main(
|
|
96
|
+
[
|
|
97
|
+
"-p",
|
|
98
|
+
"no:warnings",
|
|
99
|
+
"-sv",
|
|
100
|
+
"tests/test_amd.py",
|
|
101
|
+
]
|
|
102
|
+
)
|
|
103
|
+
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|