Skip to content

Commit

Permalink
更新文档
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxinwei committed May 8, 2024
1 parent 96067c8 commit 3ccd620
Show file tree
Hide file tree
Showing 50 changed files with 2,231 additions and 424 deletions.
1 change: 1 addition & 0 deletions doc/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ temp/
*.json
.temp/
api/
.temp/
2 changes: 1 addition & 1 deletion doc/chaos/vta/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# VTA 教程
# VTA 教程(chaos)

官方教程见:[VTA](https://xinetzone.github.io/tvm/docs/topic/vta/index.html)

Expand Down
1 change: 1 addition & 0 deletions doc/read/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ te/index
topi/index
tir/index
op/index
layout/index
attrs/index
expr/index
reflection
Expand Down
171 changes: 171 additions & 0 deletions doc/read/layout/InferCorrectLayoutOutput.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# InferCorrectLayoutOutput"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import set_env"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import tvm\n",
"from tvm import relay\n",
"from tvm.relay.testing.temp_op_attr import TempOpAttr\n",
"from tvm.relay.op import op as _op"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"op_name = \"custom_op\"\n",
"\n",
"_op.register(op_name, r\"code(Add two tensor with inner broadcasting.)code\")\n",
"_op.get(op_name).set_num_inputs(2)\n",
"_op.get(op_name).add_argument(\"data_0\", \"Tensor\", \"The input data tensor.\")\n",
"_op.get(op_name).add_argument(\"data_1\", \"Tensor\", \"The input data tensor.\")\n",
"# 调用默认关系函数\n",
"_op.get(op_name).add_type_rel(\"Identity\")\n",
"_op.get(op_name).set_support_level(1)\n",
"_op.register_pattern(op_name, _op.OpPattern.ELEMWISE)\n",
"_op.register_stateful(op_name, False)\n",
"\n",
"assert _op.get(op_name).name == op_name\n",
"assert _op.get(op_name).num_inputs == 2\n",
"assert _op.get(op_name).get_attr(\"TOpPattern\") == _op.OpPattern.ELEMWISE\n",
"assert _op.get(op_name).get_attr(\"TOpIsStateful\") == False"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[0;31mSignature:\u001b[0m \u001b[0m_op\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mregister_infer_correct_layout\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mop_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minfer_layout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlevel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mSource:\u001b[0m \n",
"\u001b[0;32mdef\u001b[0m \u001b[0mregister_infer_correct_layout\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mop_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minfer_layout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlevel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0;34m\"\"\"Register infer op layout function for an op\u001b[0m\n",
"\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m Parameters\u001b[0m\n",
"\u001b[0;34m ----------\u001b[0m\n",
"\u001b[0;34m op_name : str\u001b[0m\n",
"\u001b[0;34m The name of the operator\u001b[0m\n",
"\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m infer_layout: function (attrs: Attrs, inputs: List[Layout]) -> InferCorrectLayoutOutput\u001b[0m\n",
"\u001b[0;34m The function to infer correct layout\u001b[0m\n",
"\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m level : int\u001b[0m\n",
"\u001b[0;34m The priority level\u001b[0m\n",
"\u001b[0;34m \"\"\"\u001b[0m\u001b[0;34m\u001b[0m\n",
"\u001b[0;34m\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mtvm\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mir\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mregister_op_attr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mop_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"FInferCorrectLayout\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minfer_layout\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlevel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mFile:\u001b[0m /media/pc/data/lxw/ai/tvm/python/tvm/relay/op/op.py\n",
"\u001b[0;31mType:\u001b[0m function"
]
}
],
"source": [
"_op.register_infer_correct_layout??"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"{func}`~tvm.relay.op.op.register_infer_correct_layout` 用于为算子注册推断布局函数。\n",
"\n",
"参数说明:\n",
"- `op_name`:字符串类型,表示算子的名称。\n",
"- `infer_layout`:函数类型,接受两个参数 `attrs` 和 `inputs`,返回 {class}`~tvm.relay.transform.infer_layout_utils.InferCorrectLayoutOutput` 类型的对象。该函数用于推断正确的布局。\n",
"- `level`:整数类型,表示优先级级别。"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<function __main__.infer_layout(attrs: tvm.ir.attrs.Attrs, inputs: list[tvm.tir.data_layout.Layout])>"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from tvm.relay.transform.infer_layout_utils import InferCorrectLayoutOutput\n",
"from tvm.ir import Attrs\n",
"from tvm.tir.data_layout import Layout\n",
"\n",
"def infer_layout(attrs: Attrs, inputs: list[Layout]):\n",
" return InferCorrectLayoutOutput()\n",
"_op.register_infer_correct_layout(op_name, infer_layout)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[0;31mInit signature:\u001b[0m \u001b[0mInferCorrectLayoutOutput\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minput_layouts\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moutput_layouts\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnew_attrs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mDocstring:\u001b[0m An output structure to hold results from FInferCorrectLayout calls.\n",
"\u001b[0;31mFile:\u001b[0m /media/pc/data/lxw/ai/tvm/python/tvm/relay/transform/infer_layout_utils.py\n",
"\u001b[0;31mType:\u001b[0m type\n",
"\u001b[0;31mSubclasses:\u001b[0m "
]
}
],
"source": [
"InferCorrectLayoutOutput?"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "xin",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
6 changes: 6 additions & 0 deletions doc/read/layout/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 数据布局

```{toctree}
InferCorrectLayoutOutput
```

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path
from tvm_book.config.env import set_tvm
TVM_ROOT = Path(__file__).resolve().parents[5]
# TVM_ROOT = Path(__file__).resolve().parents[5]
# print(TVM_ROOT)
# TVM_ROOT = "/media/pc/data/lxw/ai/tvm/"
TVM_ROOT = "/media/pc/data/lxw/ai/tvm/"
set_tvm(TVM_ROOT)
1 change: 0 additions & 1 deletion doc/topics/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

```{toctree}
extension/index
onnxscript/index
```
1 change: 1 addition & 0 deletions doc/tutorials/frontend/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mxnet
tensorflow-tvm/index
pytorch-tvm/index
onnx-tvm/index
onnxscript/index
caffe-tvm/index
relax-fx
```
2 changes: 0 additions & 2 deletions doc/tutorials/frontend/onnx-tvm/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@
onnx-format
onnxruntime-start
torch2onnx/index
torch2onnx-test
test
```
2 changes: 1 addition & 1 deletion doc/tutorials/frontend/onnx-tvm/onnx-format.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@
"之前的模型假设线性回归的系数也是模型的输入。那不太方便。它们应该作为常量或初始化项成为模型本身的一部分,以遵循 onnx 语义。下一个示例修改了前一个示例,将输入 `A` 和 `B` 更改为初始化式。(参见 [array](https://onnx.ai/onnx/api/numpy_helper.html#l-numpy-helper-onnx-array))。\n",
"\n",
"- `onnx.numpy_helper.to_array`: 将 ONNX 转换为 NumPy 数组。\n",
"- `onnx.numpy_helper.from_array`: 将N umPy 数组转换为 ONNX。"
"- `onnx.numpy_helper.from_array`: 将 NumPy 数组转换为 ONNX。"
]
},
{
Expand Down
Loading

0 comments on commit 3ccd620

Please sign in to comment.