ait-surgeon


Nameait-surgeon JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://gitee.com/ascend/ait
Summaryauto optimizer
upload_time2024-04-07 10:41:21
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseApache-2.0
keywords auto optimizer
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # auto-optimizer工具指南

## 介绍

auto-optimizer(自动调优工具)使能ONNX模型在昇腾芯片的优化,并提供基于ONNX的改图功能。

**软件架构**

![architecture](./docs/img/architecture.png)

auto-optimizer主要通过graph_optimizer、graph_refactor接口提供ONNX模型自动调优能力。

接口详细介绍请参见如下手册:

- [x]  graph_optimizer:基于知识库的自动改图优化。同时支持自定义知识库,详细接口请参考[knowledge](docs/knowledge_optimizer/knowledge_optimizer_framework.md)
- [x]  graph_refactor:改图API。[graph_refactor](auto_optimizer/graph_refactor/README.md)



## 工具安装

```shell
git clone https://gitee.com/ascend/ait.git
cd ait/ait/debug/surgeon

# it's recommended to upgrade pip and install wheel

# is's also recommended to use conda/venv/... to manage python enviornments
# for example: `python3 -m venv .venv && source .venv/bin/activate`

# is's also recommended to use `python3 -m pip` to avoid python env issue

python3 -m pip install --upgrade pip
python3 -m pip install wheel

# installation
# optional features: inference, simplify

# without any optional feature
python3 -m pip install .

# with inference and simplify feature
python3 -m pip install .[simplify]
```

- simplify:提供onnx.simplify接口。

## 工具使用

### 命令格式说明

auto-optimizer工具可通过auto_optimizer可执行文件方式启动,若安装工具时未提示Python的HATH变量问题,或手动将Python安装可执行文件的目录加入PATH变量,则可以直接使用如下命令格式:

```bash
auto_optimizer <COMMAND> [OPTIONS] [ARGS]
```

或直接使用如下命令格式:

```bash
python3 -m auto_optimizer <COMMAND> [OPTIONS] [ARGS]
```

其中<COMMAND>为auto_optimizer执行模式参数,取值为list、evaluate、optimize和extract;[OPTIONS]和[ARGS]为evaluate和optimize命令的额外参数,详细介绍请参见后续“evaluate命令”和“optimize命令”章节。

### 使用流程

auto-optimizer工具建议按照list、evaluate和optimize的顺序执行。如需切分子图,可使用extract命令导出子图。

操作流程如下:

1. 执行**list**命令列举当前支持自动调优的所有知识库。
2. 执行**evaluate**命令搜索可以被指定知识库优化的ONNX模型。
3. 执行**optimize**命令使用指定的知识库来优化指定的ONNX模型。
4. 执行**extract**命令对模型进行子图切分。

### list命令

命令示例如下:

```bash
python3 -m auto_optimizer list
```

输出示例如下:

```bash
Available knowledges:
   0 KnowledgeConv1d2Conv2d
   1 KnowledgeMergeConsecutiveSlice
   2 KnowledgeTransposeLargeInputConv
   3 KnowledgeMergeConsecutiveConcat
   4 KnowledgeTypeCast
   5 KnowledgeSplitQKVMatmul
   6 KnowledgeSplitLargeKernelConv
   7 KnowledgeResizeModeToNearest
   8 KnowledgeTopkFix
   9 KnowledgeMergeCasts
  10 KnowledgeEmptySliceFix 
  11 KnowledgeDynamicReshape
  12 KnowledgeGatherToSplit
  13 KnowledgeAvgPoolSplit
  14 KnowledgeBNFolding
  15 KnowledgeModifyReflectionPad
  16 KnowledgeBigKernel
```

列举的知识库按照“序号”+“知识库名称”的格式展示,**evaluate**或**optimize**命令通过**knowledges**参数指定知识库时,可指定知识库序号或名称。关于具体知识库的详细信息,请参见[知识库文档](docs/knowledge_optimizer/knowledge_optimizer_rules.md)。

注意:序号是为了方便手动调用存在的,由于知识库可能存在被删除或修改等情况,序号可能会变化。

### evaluate命令

命令格式如下:

```bash
python3 -m auto_optimizer evaluate [OPTIONS] PATH
```

evaluate可简写为eva。

参数说明:

| 参数    | 说明                                                         | 是否必选 |
| ------- | ------------------------------------------------------------ | -------- |
| OPTIONS | 额外参数。可取值:<br/>    -k/--knowledges:知识库列表。可指定知识库名称或序号,以英文逗号“,”分隔。默认启用除修复性质以外的所有知识库。<br/>    -r/--recursive:在PATH为文件夹时是否递归搜索。默认关闭。<br/>    -v/--verbose:打印更多信息,目前只有搜索进度。默认关闭。<br/>    -p/--processes: 使用multiprocess并行搜索,指定进程数量。默认1。<br/>    --help:工具使用帮助信息。 | 否       |
| PATH    | evaluate的搜索目标,可以是.onnx文件或者包含.onnx文件的文件夹。 | 是       |

命令示例及输出如下:

```bash
python3 -m auto_optimizer evaluate aasist_bs1_ori.onnx
```

```
2023-04-27 14:37:10,364 - auto-optimizer-logger - INFO - aasist_bs1_ori.onnx    KnowledgeConv1d2Conv2d,KnowledgeMergeConsecutiveSlice,KnowledgeTransposeLargeInputConv,KnowledgeTypeCast,KnowledgeMergeCasts
```

### optimize命令

命令格式如下:

```bash
python3 -m auto_optimizer optimize [OPTIONS] INPUT_MODEL OUTPUT_MODEL
```

optimize可简写为opt。

参数说明:

| 参数         | 说明                                                         | 是否必选 |
| ------------ | ------------------------------------------------------------ | -------- |
| OPTIONS      | 额外参数。可取值:<br/>    -k/--knowledges:知识库列表。可指定知识库名称或序号,以英文逗号“,”分隔。默认启用除修复性质以外的所有知识库。<br/>    -bk/--big-kernel:transform类模型大kernel优化的开关,当开关开启时会启用大kernel优化知识库。关于大kernel优化的介绍请参考[示例](../../../examples/cli/debug/surgeon/06_big_kernel_optimize/README.md)<br/>    -as/--attention-start-node:第一个attention结构的起始节点,与-bk配合使用,当启用大kernel优化开关时,需要提供该参数。<br/>    -ae/--attention-end-node:第一个attention结构的结束节点,与-bk配合使用,当启用大kernel优化开关时,需要提供该参数。<br/>    -t/--infer-test:当启用这个选项时,通过对比优化前后的推理速度来决定是否使用某知识库进行调优,保证可调优的模型均为正向调优。启用该选项需要安装额外依赖[inference],并且需要安装CANN。<br/>    -s/--soc:使用的昇腾芯片版本。默认为Ascend310P3。仅当启用infer-test选项时有意义。<br/>    -d/--device:NPU设备ID。默认为0。仅当启用infer-test选项时有意义。<br/>    -l/--loop:测试推理速度时推理次数。仅当启用infer-test选项时有意义。默认为100。<br/>    --threshold:推理速度提升阈值。仅当知识库的优化带来的提升超过这个值时才使用这个知识库,可以为负,负值表示接受负优化。默认为0,即默认只接受推理性能有提升的优化。仅当启用infer-test选项时有意义。<br/>    --input-shape:静态Shape图输入形状,ATC转换参数,可以省略。仅当启用infer-test选项时有意义。<br/>    --input-shape-range:动态Shape图形状范围,ATC转换参数。仅当启用infer-test选项时有意义。<br/>    --dynamic-shape:动态Shape图推理输入形状,推理用参数。仅当启用infer-test选项时有意义。<br/>    --output-size:动态Shape图推理输出实际size,推理用参数。仅当启用infer-test选项时有意义。<br/>    --help:工具使用帮助信息。 | 否       |
| INPUT_MODEL  | 输入ONNX待优化模型,必须为.onnx文件。                        | 是       |
| OUTPUT_MODEL | 输出ONNX模型名称,用户自定义,必须为.onnx文件。优化完成后在当前目录生成优化后ONNX模型文件。 | 是       |

命令示例及输出如下:

```bash
python3 -m auto_optimizer optimize aasist_bs1_ori.onnx aasist_bs1_ori_out.onnx
```

```bash
2023-04-27 14:31:33,378 - auto-optimizer-logger - INFO - Optimization success
2023-04-27 14:31:33,378 - auto-optimizer-logger - INFO - Applied knowledges:
2023-04-27 14:31:33,378 - auto-optimizer-logger - INFO -   KnowledgeConv1d2Conv2d
2023-04-27 14:31:33,378 - auto-optimizer-logger - INFO -   KnowledgeMergeConsecutiveSlice
2023-04-27 14:31:33,378 - auto-optimizer-logger - INFO -   KnowledgeTransposeLargeInputConv
2023-04-27 14:31:33,378 - auto-optimizer-logger - INFO -   KnowledgeTypeCast
2023-04-27 14:31:33,378 - auto-optimizer-logger - INFO -   KnowledgeMergeCasts
2023-04-27 14:31:33,378 - auto-optimizer-logger - INFO - Path: aasist_bs1_ori.onnx -> aasist_bs1_ori_out.onnx
```

### extract命令
命令格式如下:

```bash
python3 -m auto_optimizer extract [OPTIONS] INPUT_MODEL OUTPUT_MODEL START_NODE_NAME1,START_NODE_NAME2 END_NODE_NAME1, END_NODE_NAME2
```

extract 可简写为ext

参数说明:

| 参数                    | 说明                                                                                  | 是否必选 |
|-----------------------|-------------------------------------------------------------------------------------|------|
| OPTIONS               | 额外参数。可取值:<br/>    -c/--is-check-subgraph:是否校验子图。启用这个选项时,会校验切分后的子图。                  | 否    |
| INPUT_MODEL           | 输入ONNX待优化模型,必须为.onnx文件。                                                             | 是    |
| OUTPUT_MODEL          | 切分后的子图ONNX模型名称,用户自定义,必须为.onnx文件。                                                    | 是    |
| START_NODE_NAME1,2... | 起始节点名称。可指定多个输入节点,节点之间使用","分隔。                                                       | 是    |
| END_NODE_NAME1,2...   | 结束节点名称。可指定多个输出节点,节点之间使用","分隔                                                        | 是    |
| SUBGRAPH_INPUT_SHAPE  | 额外参数。可指定截取子图之后的输入shape。多节点的输入shape指定按照以下格式,"input1:n1,c1,h1,w1;input2:n2,c2,h2,w2"。 | 否    |
| SUBGRAPH_INPUT_DTYPE  | 额外参数。可指定截取子图之后的输入dtype。多节点的输入dtype指定按照以下格式,"input1:dtype1;input2:dtype2"。           | 否    |
使用特别说明:为保证子图切分功能正常使用且不影响推理性能,请勿指定存在**父子关系**的输入或输出节点作为切分参数。

命令示例及输出如下:

```bash
python3 -m auto_optimizer extract origin_model.onnx sub_model.onnx "s_node1,s_node2" "e_node1,e_node2" --subgraph_input_shape="input1:1,3,224,224" --subgraph_input_dtype="input1:float16"
```

```bash
2023-04-27 14:32:33,378 - auto-optimizer-logger - INFO - Extract the model completed, model was saved in sub_model.onnx
```
## 许可证

[Apache License 2.0](LICENSE)

## 免责声明

auto-optimizer仅提供基于ONNX的改图及调优参考,不对其质量或维护负责。
如果您遇到了问题,Gitee/Ascend/auto-optimizer提交issue,我们将根据您的issue跟踪解决。
衷心感谢您对我们社区的理解和贡献。

            

Raw data

            {
    "_id": null,
    "home_page": "https://gitee.com/ascend/ait",
    "name": "ait-surgeon",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "auto optimizer",
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/21/43/da5d6ccf414c66510ccc8abfedc4db00e26ada0c53ac44f15d3cc7bdb60c/ait-surgeon-0.1.1.zip",
    "platform": null,
    "description": "# auto-optimizer\u5de5\u5177\u6307\u5357\n\n## \u4ecb\u7ecd\n\nauto-optimizer\uff08\u81ea\u52a8\u8c03\u4f18\u5de5\u5177\uff09\u4f7f\u80fdONNX\u6a21\u578b\u5728\u6607\u817e\u82af\u7247\u7684\u4f18\u5316\uff0c\u5e76\u63d0\u4f9b\u57fa\u4e8eONNX\u7684\u6539\u56fe\u529f\u80fd\u3002\n\n**\u8f6f\u4ef6\u67b6\u6784**\n\n![architecture](./docs/img/architecture.png)\n\nauto-optimizer\u4e3b\u8981\u901a\u8fc7graph_optimizer\u3001graph_refactor\u63a5\u53e3\u63d0\u4f9bONNX\u6a21\u578b\u81ea\u52a8\u8c03\u4f18\u80fd\u529b\u3002\n\n\u63a5\u53e3\u8be6\u7ec6\u4ecb\u7ecd\u8bf7\u53c2\u89c1\u5982\u4e0b\u624b\u518c\uff1a\n\n- [x]  graph_optimizer\uff1a\u57fa\u4e8e\u77e5\u8bc6\u5e93\u7684\u81ea\u52a8\u6539\u56fe\u4f18\u5316\u3002\u540c\u65f6\u652f\u6301\u81ea\u5b9a\u4e49\u77e5\u8bc6\u5e93\uff0c\u8be6\u7ec6\u63a5\u53e3\u8bf7\u53c2\u8003[knowledge](docs/knowledge_optimizer/knowledge_optimizer_framework.md)\n- [x]  graph_refactor\uff1a\u6539\u56feAPI\u3002[graph_refactor](auto_optimizer/graph_refactor/README.md)\n\n\n\n## \u5de5\u5177\u5b89\u88c5\n\n```shell\ngit clone https://gitee.com/ascend/ait.git\ncd ait/ait/debug/surgeon\n\n# it's recommended to upgrade pip and install wheel\n\n# is's also recommended to use conda/venv/... to manage python enviornments\n# for example: `python3 -m venv .venv && source .venv/bin/activate`\n\n# is's also recommended to use `python3 -m pip` to avoid python env issue\n\npython3 -m pip install --upgrade pip\npython3 -m pip install wheel\n\n# installation\n# optional features: inference, simplify\n\n# without any optional feature\npython3 -m pip install .\n\n# with inference and simplify feature\npython3 -m pip install .[simplify]\n```\n\n- simplify\uff1a\u63d0\u4f9bonnx.simplify\u63a5\u53e3\u3002\n\n## \u5de5\u5177\u4f7f\u7528\n\n### \u547d\u4ee4\u683c\u5f0f\u8bf4\u660e\n\nauto-optimizer\u5de5\u5177\u53ef\u901a\u8fc7auto_optimizer\u53ef\u6267\u884c\u6587\u4ef6\u65b9\u5f0f\u542f\u52a8\uff0c\u82e5\u5b89\u88c5\u5de5\u5177\u65f6\u672a\u63d0\u793aPython\u7684HATH\u53d8\u91cf\u95ee\u9898\uff0c\u6216\u624b\u52a8\u5c06Python\u5b89\u88c5\u53ef\u6267\u884c\u6587\u4ef6\u7684\u76ee\u5f55\u52a0\u5165PATH\u53d8\u91cf\uff0c\u5219\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u683c\u5f0f\uff1a\n\n```bash\nauto_optimizer <COMMAND> [OPTIONS] [ARGS]\n```\n\n\u6216\u76f4\u63a5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u683c\u5f0f\uff1a\n\n```bash\npython3 -m auto_optimizer <COMMAND> [OPTIONS] [ARGS]\n```\n\n\u5176\u4e2d<COMMAND>\u4e3aauto_optimizer\u6267\u884c\u6a21\u5f0f\u53c2\u6570\uff0c\u53d6\u503c\u4e3alist\u3001evaluate\u3001optimize\u548cextract\uff1b[OPTIONS]\u548c[ARGS]\u4e3aevaluate\u548coptimize\u547d\u4ee4\u7684\u989d\u5916\u53c2\u6570\uff0c\u8be6\u7ec6\u4ecb\u7ecd\u8bf7\u53c2\u89c1\u540e\u7eed\u201cevaluate\u547d\u4ee4\u201d\u548c\u201coptimize\u547d\u4ee4\u201d\u7ae0\u8282\u3002\n\n### \u4f7f\u7528\u6d41\u7a0b\n\nauto-optimizer\u5de5\u5177\u5efa\u8bae\u6309\u7167list\u3001evaluate\u548coptimize\u7684\u987a\u5e8f\u6267\u884c\u3002\u5982\u9700\u5207\u5206\u5b50\u56fe\uff0c\u53ef\u4f7f\u7528extract\u547d\u4ee4\u5bfc\u51fa\u5b50\u56fe\u3002\n\n\u64cd\u4f5c\u6d41\u7a0b\u5982\u4e0b\uff1a\n\n1. \u6267\u884c**list**\u547d\u4ee4\u5217\u4e3e\u5f53\u524d\u652f\u6301\u81ea\u52a8\u8c03\u4f18\u7684\u6240\u6709\u77e5\u8bc6\u5e93\u3002\n2. \u6267\u884c**evaluate**\u547d\u4ee4\u641c\u7d22\u53ef\u4ee5\u88ab\u6307\u5b9a\u77e5\u8bc6\u5e93\u4f18\u5316\u7684ONNX\u6a21\u578b\u3002\n3. \u6267\u884c**optimize**\u547d\u4ee4\u4f7f\u7528\u6307\u5b9a\u7684\u77e5\u8bc6\u5e93\u6765\u4f18\u5316\u6307\u5b9a\u7684ONNX\u6a21\u578b\u3002\n4. \u6267\u884c**extract**\u547d\u4ee4\u5bf9\u6a21\u578b\u8fdb\u884c\u5b50\u56fe\u5207\u5206\u3002\n\n### list\u547d\u4ee4\n\n\u547d\u4ee4\u793a\u4f8b\u5982\u4e0b\uff1a\n\n```bash\npython3 -m auto_optimizer list\n```\n\n\u8f93\u51fa\u793a\u4f8b\u5982\u4e0b\uff1a\n\n```bash\nAvailable knowledges:\n   0 KnowledgeConv1d2Conv2d\n   1 KnowledgeMergeConsecutiveSlice\n   2 KnowledgeTransposeLargeInputConv\n   3 KnowledgeMergeConsecutiveConcat\n   4 KnowledgeTypeCast\n   5 KnowledgeSplitQKVMatmul\n   6 KnowledgeSplitLargeKernelConv\n   7 KnowledgeResizeModeToNearest\n   8 KnowledgeTopkFix\n   9 KnowledgeMergeCasts\n  10 KnowledgeEmptySliceFix \n  11 KnowledgeDynamicReshape\n  12 KnowledgeGatherToSplit\n  13 KnowledgeAvgPoolSplit\n  14 KnowledgeBNFolding\n  15 KnowledgeModifyReflectionPad\n  16 KnowledgeBigKernel\n```\n\n\u5217\u4e3e\u7684\u77e5\u8bc6\u5e93\u6309\u7167\u201c\u5e8f\u53f7\u201d+\u201c\u77e5\u8bc6\u5e93\u540d\u79f0\u201d\u7684\u683c\u5f0f\u5c55\u793a\uff0c**evaluate**\u6216**optimize**\u547d\u4ee4\u901a\u8fc7**knowledges**\u53c2\u6570\u6307\u5b9a\u77e5\u8bc6\u5e93\u65f6\uff0c\u53ef\u6307\u5b9a\u77e5\u8bc6\u5e93\u5e8f\u53f7\u6216\u540d\u79f0\u3002\u5173\u4e8e\u5177\u4f53\u77e5\u8bc6\u5e93\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u89c1[\u77e5\u8bc6\u5e93\u6587\u6863](docs/knowledge_optimizer/knowledge_optimizer_rules.md)\u3002\n\n\u6ce8\u610f\uff1a\u5e8f\u53f7\u662f\u4e3a\u4e86\u65b9\u4fbf\u624b\u52a8\u8c03\u7528\u5b58\u5728\u7684\uff0c\u7531\u4e8e\u77e5\u8bc6\u5e93\u53ef\u80fd\u5b58\u5728\u88ab\u5220\u9664\u6216\u4fee\u6539\u7b49\u60c5\u51b5\uff0c\u5e8f\u53f7\u53ef\u80fd\u4f1a\u53d8\u5316\u3002\n\n### evaluate\u547d\u4ee4\n\n\u547d\u4ee4\u683c\u5f0f\u5982\u4e0b\uff1a\n\n```bash\npython3 -m auto_optimizer evaluate [OPTIONS] PATH\n```\n\nevaluate\u53ef\u7b80\u5199\u4e3aeva\u3002\n\n\u53c2\u6570\u8bf4\u660e\uff1a\n\n| \u53c2\u6570    | \u8bf4\u660e                                                         | \u662f\u5426\u5fc5\u9009 |\n| ------- | ------------------------------------------------------------ | -------- |\n| OPTIONS | \u989d\u5916\u53c2\u6570\u3002\u53ef\u53d6\u503c\uff1a<br/>    -k/--knowledges\uff1a\u77e5\u8bc6\u5e93\u5217\u8868\u3002\u53ef\u6307\u5b9a\u77e5\u8bc6\u5e93\u540d\u79f0\u6216\u5e8f\u53f7\uff0c\u4ee5\u82f1\u6587\u9017\u53f7\u201c,\u201d\u5206\u9694\u3002\u9ed8\u8ba4\u542f\u7528\u9664\u4fee\u590d\u6027\u8d28\u4ee5\u5916\u7684\u6240\u6709\u77e5\u8bc6\u5e93\u3002<br/>    -r/--recursive\uff1a\u5728PATH\u4e3a\u6587\u4ef6\u5939\u65f6\u662f\u5426\u9012\u5f52\u641c\u7d22\u3002\u9ed8\u8ba4\u5173\u95ed\u3002<br/>    -v/--verbose\uff1a\u6253\u5370\u66f4\u591a\u4fe1\u606f\uff0c\u76ee\u524d\u53ea\u6709\u641c\u7d22\u8fdb\u5ea6\u3002\u9ed8\u8ba4\u5173\u95ed\u3002<br/>    -p/--processes: \u4f7f\u7528multiprocess\u5e76\u884c\u641c\u7d22\uff0c\u6307\u5b9a\u8fdb\u7a0b\u6570\u91cf\u3002\u9ed8\u8ba41\u3002<br/>    --help\uff1a\u5de5\u5177\u4f7f\u7528\u5e2e\u52a9\u4fe1\u606f\u3002 | \u5426       |\n| PATH    | evaluate\u7684\u641c\u7d22\u76ee\u6807\uff0c\u53ef\u4ee5\u662f.onnx\u6587\u4ef6\u6216\u8005\u5305\u542b.onnx\u6587\u4ef6\u7684\u6587\u4ef6\u5939\u3002 | \u662f       |\n\n\u547d\u4ee4\u793a\u4f8b\u53ca\u8f93\u51fa\u5982\u4e0b\uff1a\n\n```bash\npython3 -m auto_optimizer evaluate aasist_bs1_ori.onnx\n```\n\n```\n2023-04-27 14:37:10,364 - auto-optimizer-logger - INFO - aasist_bs1_ori.onnx    KnowledgeConv1d2Conv2d,KnowledgeMergeConsecutiveSlice,KnowledgeTransposeLargeInputConv,KnowledgeTypeCast,KnowledgeMergeCasts\n```\n\n### optimize\u547d\u4ee4\n\n\u547d\u4ee4\u683c\u5f0f\u5982\u4e0b\uff1a\n\n```bash\npython3 -m auto_optimizer optimize [OPTIONS] INPUT_MODEL OUTPUT_MODEL\n```\n\noptimize\u53ef\u7b80\u5199\u4e3aopt\u3002\n\n\u53c2\u6570\u8bf4\u660e\uff1a\n\n| \u53c2\u6570         | \u8bf4\u660e                                                         | \u662f\u5426\u5fc5\u9009 |\n| ------------ | ------------------------------------------------------------ | -------- |\n| OPTIONS      | \u989d\u5916\u53c2\u6570\u3002\u53ef\u53d6\u503c\uff1a<br/>    -k/--knowledges\uff1a\u77e5\u8bc6\u5e93\u5217\u8868\u3002\u53ef\u6307\u5b9a\u77e5\u8bc6\u5e93\u540d\u79f0\u6216\u5e8f\u53f7\uff0c\u4ee5\u82f1\u6587\u9017\u53f7\u201c,\u201d\u5206\u9694\u3002\u9ed8\u8ba4\u542f\u7528\u9664\u4fee\u590d\u6027\u8d28\u4ee5\u5916\u7684\u6240\u6709\u77e5\u8bc6\u5e93\u3002<br/>    -bk/--big-kernel\uff1atransform\u7c7b\u6a21\u578b\u5927kernel\u4f18\u5316\u7684\u5f00\u5173\uff0c\u5f53\u5f00\u5173\u5f00\u542f\u65f6\u4f1a\u542f\u7528\u5927kernel\u4f18\u5316\u77e5\u8bc6\u5e93\u3002\u5173\u4e8e\u5927kernel\u4f18\u5316\u7684\u4ecb\u7ecd\u8bf7\u53c2\u8003[\u793a\u4f8b](../../../examples/cli/debug/surgeon/06_big_kernel_optimize/README.md)<br/>    -as/--attention-start-node\uff1a\u7b2c\u4e00\u4e2aattention\u7ed3\u6784\u7684\u8d77\u59cb\u8282\u70b9\uff0c\u4e0e-bk\u914d\u5408\u4f7f\u7528\uff0c\u5f53\u542f\u7528\u5927kernel\u4f18\u5316\u5f00\u5173\u65f6\uff0c\u9700\u8981\u63d0\u4f9b\u8be5\u53c2\u6570\u3002<br/>    -ae/--attention-end-node\uff1a\u7b2c\u4e00\u4e2aattention\u7ed3\u6784\u7684\u7ed3\u675f\u8282\u70b9\uff0c\u4e0e-bk\u914d\u5408\u4f7f\u7528\uff0c\u5f53\u542f\u7528\u5927kernel\u4f18\u5316\u5f00\u5173\u65f6\uff0c\u9700\u8981\u63d0\u4f9b\u8be5\u53c2\u6570\u3002<br/>    -t/--infer-test\uff1a\u5f53\u542f\u7528\u8fd9\u4e2a\u9009\u9879\u65f6\uff0c\u901a\u8fc7\u5bf9\u6bd4\u4f18\u5316\u524d\u540e\u7684\u63a8\u7406\u901f\u5ea6\u6765\u51b3\u5b9a\u662f\u5426\u4f7f\u7528\u67d0\u77e5\u8bc6\u5e93\u8fdb\u884c\u8c03\u4f18\uff0c\u4fdd\u8bc1\u53ef\u8c03\u4f18\u7684\u6a21\u578b\u5747\u4e3a\u6b63\u5411\u8c03\u4f18\u3002\u542f\u7528\u8be5\u9009\u9879\u9700\u8981\u5b89\u88c5\u989d\u5916\u4f9d\u8d56[inference]\uff0c\u5e76\u4e14\u9700\u8981\u5b89\u88c5CANN\u3002<br/>    -s/--soc\uff1a\u4f7f\u7528\u7684\u6607\u817e\u82af\u7247\u7248\u672c\u3002\u9ed8\u8ba4\u4e3aAscend310P3\u3002\u4ec5\u5f53\u542f\u7528infer-test\u9009\u9879\u65f6\u6709\u610f\u4e49\u3002<br/>    -d/--device\uff1aNPU\u8bbe\u5907ID\u3002\u9ed8\u8ba4\u4e3a0\u3002\u4ec5\u5f53\u542f\u7528infer-test\u9009\u9879\u65f6\u6709\u610f\u4e49\u3002<br/>    -l/--loop\uff1a\u6d4b\u8bd5\u63a8\u7406\u901f\u5ea6\u65f6\u63a8\u7406\u6b21\u6570\u3002\u4ec5\u5f53\u542f\u7528infer-test\u9009\u9879\u65f6\u6709\u610f\u4e49\u3002\u9ed8\u8ba4\u4e3a100\u3002<br/>    --threshold\uff1a\u63a8\u7406\u901f\u5ea6\u63d0\u5347\u9608\u503c\u3002\u4ec5\u5f53\u77e5\u8bc6\u5e93\u7684\u4f18\u5316\u5e26\u6765\u7684\u63d0\u5347\u8d85\u8fc7\u8fd9\u4e2a\u503c\u65f6\u624d\u4f7f\u7528\u8fd9\u4e2a\u77e5\u8bc6\u5e93\uff0c\u53ef\u4ee5\u4e3a\u8d1f\uff0c\u8d1f\u503c\u8868\u793a\u63a5\u53d7\u8d1f\u4f18\u5316\u3002\u9ed8\u8ba4\u4e3a0\uff0c\u5373\u9ed8\u8ba4\u53ea\u63a5\u53d7\u63a8\u7406\u6027\u80fd\u6709\u63d0\u5347\u7684\u4f18\u5316\u3002\u4ec5\u5f53\u542f\u7528infer-test\u9009\u9879\u65f6\u6709\u610f\u4e49\u3002<br/>    --input-shape\uff1a\u9759\u6001Shape\u56fe\u8f93\u5165\u5f62\u72b6\uff0cATC\u8f6c\u6362\u53c2\u6570\uff0c\u53ef\u4ee5\u7701\u7565\u3002\u4ec5\u5f53\u542f\u7528infer-test\u9009\u9879\u65f6\u6709\u610f\u4e49\u3002<br/>    --input-shape-range\uff1a\u52a8\u6001Shape\u56fe\u5f62\u72b6\u8303\u56f4\uff0cATC\u8f6c\u6362\u53c2\u6570\u3002\u4ec5\u5f53\u542f\u7528infer-test\u9009\u9879\u65f6\u6709\u610f\u4e49\u3002<br/>    --dynamic-shape\uff1a\u52a8\u6001Shape\u56fe\u63a8\u7406\u8f93\u5165\u5f62\u72b6\uff0c\u63a8\u7406\u7528\u53c2\u6570\u3002\u4ec5\u5f53\u542f\u7528infer-test\u9009\u9879\u65f6\u6709\u610f\u4e49\u3002<br/>    --output-size\uff1a\u52a8\u6001Shape\u56fe\u63a8\u7406\u8f93\u51fa\u5b9e\u9645size\uff0c\u63a8\u7406\u7528\u53c2\u6570\u3002\u4ec5\u5f53\u542f\u7528infer-test\u9009\u9879\u65f6\u6709\u610f\u4e49\u3002<br/>    --help\uff1a\u5de5\u5177\u4f7f\u7528\u5e2e\u52a9\u4fe1\u606f\u3002 | \u5426       |\n| INPUT_MODEL  | \u8f93\u5165ONNX\u5f85\u4f18\u5316\u6a21\u578b\uff0c\u5fc5\u987b\u4e3a.onnx\u6587\u4ef6\u3002                        | \u662f       |\n| OUTPUT_MODEL | \u8f93\u51faONNX\u6a21\u578b\u540d\u79f0\uff0c\u7528\u6237\u81ea\u5b9a\u4e49\uff0c\u5fc5\u987b\u4e3a.onnx\u6587\u4ef6\u3002\u4f18\u5316\u5b8c\u6210\u540e\u5728\u5f53\u524d\u76ee\u5f55\u751f\u6210\u4f18\u5316\u540eONNX\u6a21\u578b\u6587\u4ef6\u3002 | \u662f       |\n\n\u547d\u4ee4\u793a\u4f8b\u53ca\u8f93\u51fa\u5982\u4e0b\uff1a\n\n```bash\npython3 -m auto_optimizer optimize aasist_bs1_ori.onnx aasist_bs1_ori_out.onnx\n```\n\n```bash\n2023-04-27 14:31:33,378 - auto-optimizer-logger - INFO - Optimization success\n2023-04-27 14:31:33,378 - auto-optimizer-logger - INFO - Applied knowledges:\n2023-04-27 14:31:33,378 - auto-optimizer-logger - INFO -   KnowledgeConv1d2Conv2d\n2023-04-27 14:31:33,378 - auto-optimizer-logger - INFO -   KnowledgeMergeConsecutiveSlice\n2023-04-27 14:31:33,378 - auto-optimizer-logger - INFO -   KnowledgeTransposeLargeInputConv\n2023-04-27 14:31:33,378 - auto-optimizer-logger - INFO -   KnowledgeTypeCast\n2023-04-27 14:31:33,378 - auto-optimizer-logger - INFO -   KnowledgeMergeCasts\n2023-04-27 14:31:33,378 - auto-optimizer-logger - INFO - Path: aasist_bs1_ori.onnx -> aasist_bs1_ori_out.onnx\n```\n\n### extract\u547d\u4ee4\n\u547d\u4ee4\u683c\u5f0f\u5982\u4e0b\uff1a\n\n```bash\npython3 -m auto_optimizer extract [OPTIONS] INPUT_MODEL OUTPUT_MODEL START_NODE_NAME1,START_NODE_NAME2 END_NODE_NAME1, END_NODE_NAME2\n```\n\nextract \u53ef\u7b80\u5199\u4e3aext\n\n\u53c2\u6570\u8bf4\u660e\uff1a\n\n| \u53c2\u6570                    | \u8bf4\u660e                                                                                  | \u662f\u5426\u5fc5\u9009 |\n|-----------------------|-------------------------------------------------------------------------------------|------|\n| OPTIONS               | \u989d\u5916\u53c2\u6570\u3002\u53ef\u53d6\u503c\uff1a<br/>    -c/--is-check-subgraph\uff1a\u662f\u5426\u6821\u9a8c\u5b50\u56fe\u3002\u542f\u7528\u8fd9\u4e2a\u9009\u9879\u65f6\uff0c\u4f1a\u6821\u9a8c\u5207\u5206\u540e\u7684\u5b50\u56fe\u3002                  | \u5426    |\n| INPUT_MODEL           | \u8f93\u5165ONNX\u5f85\u4f18\u5316\u6a21\u578b\uff0c\u5fc5\u987b\u4e3a.onnx\u6587\u4ef6\u3002                                                             | \u662f    |\n| OUTPUT_MODEL          | \u5207\u5206\u540e\u7684\u5b50\u56feONNX\u6a21\u578b\u540d\u79f0\uff0c\u7528\u6237\u81ea\u5b9a\u4e49\uff0c\u5fc5\u987b\u4e3a.onnx\u6587\u4ef6\u3002                                                    | \u662f    |\n| START_NODE_NAME1,2... | \u8d77\u59cb\u8282\u70b9\u540d\u79f0\u3002\u53ef\u6307\u5b9a\u591a\u4e2a\u8f93\u5165\u8282\u70b9\uff0c\u8282\u70b9\u4e4b\u95f4\u4f7f\u7528\",\"\u5206\u9694\u3002                                                       | \u662f    |\n| END_NODE_NAME1,2...   | \u7ed3\u675f\u8282\u70b9\u540d\u79f0\u3002\u53ef\u6307\u5b9a\u591a\u4e2a\u8f93\u51fa\u8282\u70b9\uff0c\u8282\u70b9\u4e4b\u95f4\u4f7f\u7528\",\"\u5206\u9694                                                        | \u662f    |\n| SUBGRAPH_INPUT_SHAPE  | \u989d\u5916\u53c2\u6570\u3002\u53ef\u6307\u5b9a\u622a\u53d6\u5b50\u56fe\u4e4b\u540e\u7684\u8f93\u5165shape\u3002\u591a\u8282\u70b9\u7684\u8f93\u5165shape\u6307\u5b9a\u6309\u7167\u4ee5\u4e0b\u683c\u5f0f\uff0c\"input1:n1,c1,h1,w1;input2:n2,c2,h2,w2\"\u3002 | \u5426    |\n| SUBGRAPH_INPUT_DTYPE  | \u989d\u5916\u53c2\u6570\u3002\u53ef\u6307\u5b9a\u622a\u53d6\u5b50\u56fe\u4e4b\u540e\u7684\u8f93\u5165dtype\u3002\u591a\u8282\u70b9\u7684\u8f93\u5165dtype\u6307\u5b9a\u6309\u7167\u4ee5\u4e0b\u683c\u5f0f\uff0c\"input1:dtype1;input2:dtype2\"\u3002           | \u5426    |\n\u4f7f\u7528\u7279\u522b\u8bf4\u660e\uff1a\u4e3a\u4fdd\u8bc1\u5b50\u56fe\u5207\u5206\u529f\u80fd\u6b63\u5e38\u4f7f\u7528\u4e14\u4e0d\u5f71\u54cd\u63a8\u7406\u6027\u80fd\uff0c\u8bf7\u52ff\u6307\u5b9a\u5b58\u5728**\u7236\u5b50\u5173\u7cfb**\u7684\u8f93\u5165\u6216\u8f93\u51fa\u8282\u70b9\u4f5c\u4e3a\u5207\u5206\u53c2\u6570\u3002\n\n\u547d\u4ee4\u793a\u4f8b\u53ca\u8f93\u51fa\u5982\u4e0b\uff1a\n\n```bash\npython3 -m auto_optimizer extract origin_model.onnx sub_model.onnx \"s_node1,s_node2\" \"e_node1,e_node2\" --subgraph_input_shape=\"input1:1,3,224,224\" --subgraph_input_dtype=\"input1:float16\"\n```\n\n```bash\n2023-04-27 14:32:33,378 - auto-optimizer-logger - INFO - Extract the model completed, model was saved in sub_model.onnx\n```\n## \u8bb8\u53ef\u8bc1\n\n[Apache License 2.0](LICENSE)\n\n## \u514d\u8d23\u58f0\u660e\n\nauto-optimizer\u4ec5\u63d0\u4f9b\u57fa\u4e8eONNX\u7684\u6539\u56fe\u53ca\u8c03\u4f18\u53c2\u8003\uff0c\u4e0d\u5bf9\u5176\u8d28\u91cf\u6216\u7ef4\u62a4\u8d1f\u8d23\u3002\n\u5982\u679c\u60a8\u9047\u5230\u4e86\u95ee\u9898\uff0cGitee/Ascend/auto-optimizer\u63d0\u4ea4issue\uff0c\u6211\u4eec\u5c06\u6839\u636e\u60a8\u7684issue\u8ddf\u8e2a\u89e3\u51b3\u3002\n\u8877\u5fc3\u611f\u8c22\u60a8\u5bf9\u6211\u4eec\u793e\u533a\u7684\u7406\u89e3\u548c\u8d21\u732e\u3002\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "auto optimizer",
    "version": "0.1.1",
    "project_urls": {
        "Homepage": "https://gitee.com/ascend/ait"
    },
    "split_keywords": [
        "auto",
        "optimizer"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2143da5d6ccf414c66510ccc8abfedc4db00e26ada0c53ac44f15d3cc7bdb60c",
                "md5": "36b97498e2a61fb265021bff660a3fae",
                "sha256": "92a21856fe0e4033bcb6a3120d20a5552116f9153751bb38423c31aa51d1a6ba"
            },
            "downloads": -1,
            "filename": "ait-surgeon-0.1.1.zip",
            "has_sig": false,
            "md5_digest": "36b97498e2a61fb265021bff660a3fae",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 164493,
            "upload_time": "2024-04-07T10:41:21",
            "upload_time_iso_8601": "2024-04-07T10:41:21.267663Z",
            "url": "https://files.pythonhosted.org/packages/21/43/da5d6ccf414c66510ccc8abfedc4db00e26ada0c53ac44f15d3cc7bdb60c/ait-surgeon-0.1.1.zip",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-07 10:41:21",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "ait-surgeon"
}
        
Elapsed time: 0.20909s