---
layout: single
title:  "TVM"
date:   2022-06-29 00:00:00 +0800
categories: [编程开发, DevOps]
tags: [TVM, AI Compiler]
---

## [模型在使用 TVM 优化编译器框架进行转换时的步骤](https://chinese.tvm.wiki/tutorial/introduction.html#an-overview-of-tvm-and-model-optimization)

![](/images/2022/tvm/tvm-overview.png)

```py
from tvm.driver import tvmc
model = tvmc.load('resnet50-v2-7.onnx')
package = tvmc.compile(model, target="llvm")


from tvm.driver import tvmc
model = tvmc.load('sign.onnx') #Step 1: Load
package = tvmc.compile(model, target="llvm") #Step 2: Compile
result = tvmc.run(package, device="cpu") #Step 3: Run
print("Time :", timeit.default_timer() - starttime)


import onnx
import tvm
from tvm import relay
onnx_model = onnx.load("resnet50-v2-7.onnx")
mod, params = relay.frontend.from_onnx(onnx_model, freeze_params=True)
print(relay.transform.DynamicToStatic()(mod))
```

## 参考资料
* [The Deep Learning Compiler: A Comprehensive Survey](https://arxiv.org/pdf/2002.03794v4.pdf)
* [深度学习编译器整理](https://zhuanlan.zhihu.com/p/382015459)
* [一篇关于深度学习编译器架构的综述论文](https://zhuanlan.zhihu.com/p/139552817)
* [Getting Starting using TVMC Python: a high-level API for TVM](https://tvm.apache.org/docs/tutorial/tvmc_python.html)
* [Compile ONNX Models](https://tvm.apache.org/docs/how_to/compile_models/from_onnx.html)
* [Discuss TVM](https://discuss.tvm.apache.org/)
* [Check failed: pval != nullptr == false: Cannot allocate memory symbolic tensor shape [? ? ?]](https://discuss.tvm.apache.org/t/check-failed-pval-nullptr-false-cannot-allocate-memory-symbolic-tensor-shape/8646)
* [How to Deploy TVM Modules](https://github.com/apache/tvm/tree/main/apps/howto_deploy)
