Skip to content

Commit

Permalink
更新文档
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxinwei committed Sep 11, 2024
1 parent 8b9c17e commit f4f3c1f
Show file tree
Hide file tree
Showing 35 changed files with 23 additions and 99 deletions.
1 change: 0 additions & 1 deletion doc/temp-tutorials/intro/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# TVM 快速上手

```{toctree}
env
packed-func
trace
custom-op
Expand Down
1 change: 0 additions & 1 deletion doc/temp-tutorials/intro/env.md → doc/tutorials/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ python -m invoke config --cuda
python -m invoke make
```


配置前端框架(包含 CUDA+CUDNN):

```bash
Expand Down
1 change: 1 addition & 0 deletions doc/tutorials/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
```{toctree}
:maxdepth: 7
env
demo
IRModule
e2e-opt
Expand Down
4 changes: 1 addition & 3 deletions src/tvm_book/__init__.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
'''TVM Book
'''
__version__ = '0.0.21'
"""TVM: Open Deep Learning Compiler Stack."""
3 changes: 2 additions & 1 deletion tests/set_env.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
from pathlib import Path
ROOT = Path(".").resolve().parents[0]
ROOT = Path(__file__).resolve().parents[1]
print(ROOT)
sys.path.extend([f"{ROOT}/tests", f"{ROOT}/src"])
# # from tools.tag_span import _create_span, _set_span, _verify_structural_equal_with_span
from tools.torch_utils import verify_model
109 changes: 16 additions & 93 deletions tests/test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/media/pc/data/lxw/ai/tvm-book\n"
]
}
],
"source": [
"import set_env"
]
Expand All @@ -23,12 +31,9 @@
"outputs": [],
"source": [
"import torch\n",
"from torch import fx\n",
"from torch.nn import Module\n",
"# import tvm.testing\n",
"from tvm.relax.frontend.torch import from_fx\n",
"from tvm.contrib.msc.core.frontend import translate\n",
"from tvm.contrib.msc.core import utils as msc_utils"
"\n",
"path = \"/media/pc/data/board/arria10/lxw/tasks/tools/npuusertools/models/pytorch/resnet18/resnet18.pt\"\n",
"m = torch.jit.load(path)"
]
},
{
Expand All @@ -37,98 +42,16 @@
"metadata": {},
"outputs": [],
"source": [
"class Conv2D1(Module):\n",
" def __init__(self):\n",
" super().__init__()\n",
" self.conv = torch.nn.Conv2d(3, 6, 7, bias=True)\n",
"\n",
" def forward(self, data):\n",
" return self.conv(data)"
"from tvm.relay.frontend.pytorch import from_pytorch"
]
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div class=\"highlight\" style=\"background: \"><pre style=\"line-height: 125%;\"><span></span><span style=\"color: #007979; font-style: italic\"># from tvm.script import ir as I</span>\n",
"<span style=\"color: #007979; font-style: italic\"># from tvm.script import relax as R</span>\n",
"\n",
"<span style=\"color: #AA22FF\">@I</span><span style=\"color: #AA22FF; font-weight: bold\">.</span>ir_module\n",
"<span style=\"color: #008000; font-weight: bold\">class</span> <span style=\"color: #0000FF; font-weight: bold\">Module</span>:\n",
" <span style=\"color: #AA22FF\">@R</span><span style=\"color: #AA22FF; font-weight: bold\">.</span>function\n",
" <span style=\"color: #008000; font-weight: bold\">def</span> <span style=\"color: #0000FF\">main</span>(inp_0: R<span style=\"color: #AA22FF; font-weight: bold\">.</span>Tensor((<span style=\"color: #008000\">1</span>, <span style=\"color: #008000\">3</span>, <span style=\"color: #008000\">10</span>, <span style=\"color: #008000\">10</span>), dtype<span style=\"color: #AA22FF; font-weight: bold\">=</span><span style=\"color: #BA2121\">&quot;float32&quot;</span>)) <span style=\"color: #AA22FF; font-weight: bold\">-&gt;</span> R<span style=\"color: #AA22FF; font-weight: bold\">.</span>Tensor((<span style=\"color: #008000\">1</span>, <span style=\"color: #008000\">6</span>, <span style=\"color: #008000\">4</span>, <span style=\"color: #008000\">4</span>), dtype<span style=\"color: #AA22FF; font-weight: bold\">=</span><span style=\"color: #BA2121\">&quot;float32&quot;</span>):\n",
" <span style=\"color: #008000; font-weight: bold\">with</span> R<span style=\"color: #AA22FF; font-weight: bold\">.</span>dataflow():\n",
" lv: R<span style=\"color: #AA22FF; font-weight: bold\">.</span>Tensor((<span style=\"color: #008000\">1</span>, <span style=\"color: #008000\">6</span>, <span style=\"color: #008000\">4</span>, <span style=\"color: #008000\">4</span>), dtype<span style=\"color: #AA22FF; font-weight: bold\">=</span><span style=\"color: #BA2121\">&quot;float32&quot;</span>) <span style=\"color: #AA22FF; font-weight: bold\">=</span> R<span style=\"color: #AA22FF; font-weight: bold\">.</span>nn<span style=\"color: #AA22FF; font-weight: bold\">.</span>conv2d(inp_0, metadata[<span style=\"color: #BA2121\">&quot;relax.expr.Constant&quot;</span>][<span style=\"color: #008000\">0</span>], strides<span style=\"color: #AA22FF; font-weight: bold\">=</span>[<span style=\"color: #008000\">1</span>, <span style=\"color: #008000\">1</span>], padding<span style=\"color: #AA22FF; font-weight: bold\">=</span>[<span style=\"color: #008000\">0</span>, <span style=\"color: #008000\">0</span>, <span style=\"color: #008000\">0</span>, <span style=\"color: #008000\">0</span>], dilation<span style=\"color: #AA22FF; font-weight: bold\">=</span>[<span style=\"color: #008000\">1</span>, <span style=\"color: #008000\">1</span>], groups<span style=\"color: #AA22FF; font-weight: bold\">=</span><span style=\"color: #008000\">1</span>, data_layout<span style=\"color: #AA22FF; font-weight: bold\">=</span><span style=\"color: #BA2121\">&quot;NCHW&quot;</span>, kernel_layout<span style=\"color: #AA22FF; font-weight: bold\">=</span><span style=\"color: #BA2121\">&quot;OIHW&quot;</span>, out_layout<span style=\"color: #AA22FF; font-weight: bold\">=</span><span style=\"color: #BA2121\">&quot;NCHW&quot;</span>, out_dtype<span style=\"color: #AA22FF; font-weight: bold\">=</span><span style=\"color: #BA2121\">&quot;float32&quot;</span>)\n",
" lv1: R<span style=\"color: #AA22FF; font-weight: bold\">.</span>Tensor((<span style=\"color: #008000\">1</span>, <span style=\"color: #008000\">6</span>, <span style=\"color: #008000\">1</span>, <span style=\"color: #008000\">1</span>), dtype<span style=\"color: #AA22FF; font-weight: bold\">=</span><span style=\"color: #BA2121\">&quot;float32&quot;</span>) <span style=\"color: #AA22FF; font-weight: bold\">=</span> R<span style=\"color: #AA22FF; font-weight: bold\">.</span>reshape(metadata[<span style=\"color: #BA2121\">&quot;relax.expr.Constant&quot;</span>][<span style=\"color: #008000\">1</span>], R<span style=\"color: #AA22FF; font-weight: bold\">.</span>shape([<span style=\"color: #008000\">1</span>, <span style=\"color: #008000\">6</span>, <span style=\"color: #008000\">1</span>, <span style=\"color: #008000\">1</span>]))\n",
" lv2: R<span style=\"color: #AA22FF; font-weight: bold\">.</span>Tensor((<span style=\"color: #008000\">1</span>, <span style=\"color: #008000\">6</span>, <span style=\"color: #008000\">4</span>, <span style=\"color: #008000\">4</span>), dtype<span style=\"color: #AA22FF; font-weight: bold\">=</span><span style=\"color: #BA2121\">&quot;float32&quot;</span>) <span style=\"color: #AA22FF; font-weight: bold\">=</span> R<span style=\"color: #AA22FF; font-weight: bold\">.</span>add(lv, lv1)\n",
" gv: R<span style=\"color: #AA22FF; font-weight: bold\">.</span>Tensor((<span style=\"color: #008000\">1</span>, <span style=\"color: #008000\">6</span>, <span style=\"color: #008000\">4</span>, <span style=\"color: #008000\">4</span>), dtype<span style=\"color: #AA22FF; font-weight: bold\">=</span><span style=\"color: #BA2121\">&quot;float32&quot;</span>) <span style=\"color: #AA22FF; font-weight: bold\">=</span> lv2\n",
" R<span style=\"color: #AA22FF; font-weight: bold\">.</span>output(gv)\n",
" <span style=\"color: #008000; font-weight: bold\">return</span> gv\n",
"\n",
"<span style=\"color: #007979; font-style: italic\"># Metadata omitted. Use show_meta=True in script() method to show it.</span>\n",
"</pre></div>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"(tvm.contrib.msc.core.ir.graph.MSCGraph,\n",
" {'inputs': [{'name': 'inp_0',\n",
" 'shape': [1, 3, 10, 10],\n",
" 'dtype': 'float32',\n",
" 'layout': 'NCHW'}],\n",
" 'outputs': [{'name': 'conv2d',\n",
" 'shape': [1, 6, 4, 4],\n",
" 'dtype': 'float32',\n",
" 'layout': 'NCHW'}],\n",
" 'nodes': {'total': 2, 'input': 1, 'msc.conv2d_bias': 1}})"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"input_info = [([1, 3, 10, 10], \"float32\")]\n",
"torch_model = Conv2D1()\n",
"graph_model = fx.symbolic_trace(torch_model)\n",
"with torch.no_grad():\n",
" mod = from_fx(graph_model, input_info)\n",
"mod.show()\n",
"graph, _ = translate.from_relax(mod)\n",
"inspect = graph.inspect()\n",
"type(graph), inspect "
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"tvm.contrib.msc.core.ir.graph.MSCGraph"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"type(graph)"
"mod, params = from_pytorch(m, [(\"x\", (1, 3, 224, 224))])"
]
},
{
Expand Down
3 changes: 3 additions & 0 deletions tests/test_src/tvm_book/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'''TVM Book
'''
__version__ = '0.0.21'
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit f4f3c1f

Please sign in to comment.