使用Pydot和graphviz画TensorRT的Engine图

使用Pydot和graphviz画TensorRT的Engine图

TensorRT支持很多层的融合,目的是为了优化访存,减少数据在每层之间传输的消耗。

融之后的模型,一般无法通过Netron查看,毕竟TensorRT是闭源的,如果我们想看到融合后的模型长什么样,只要在build engine开启verbose模式即可。

复制代码
./trtexec --explicitBatch --onnx=debug.onnx --saveEngine=debug.trt  --verbose

[V] [TRT] Engine Layer Information:
Layer(Scale): QuantizeLinear_2_quantize_scale_node, Tactic: 0, input[Float(1,3,-17,-18)] -> 255[Int8(1,3,-17,-18)]
Layer(CaskConvolution): conv1.weight + QuantizeLinear_7_quantize_scale_node + Conv_9 + Relu_11, Tactic: 4438325421691896755, 255[Int8(1,3,-17,-18)] -> 267[Int8(1,64,-40,-44)]
Layer(CudaPooling): MaxPool_12, Tactic: -3, 267[Int8(1,64,-40,-44)] -> Reformatted Output Tensor 0 to MaxPool_12[Int8(1,64,-21,-24)]
Layer(Reformat): Reformatting CopyNode for Output Tensor 0 to MaxPool_12, Tactic: 0, Reformatted Output Tensor 0 to MaxPool_12[Int8(1,64,-21,-24)] -> 270[Int8(1,64,-21,-24)]
Layer(CaskConvolution): layer1.0.conv1.weight + QuantizeLinear_20_quantize_scale_node + Conv_22 + Relu_24, Tactic: 4871133328510103657, 270[Int8(1,64,-21,-24)] -> 284[Int8(1,64,-21,-24)]
Layer(CaskConvolution): layer1.0.conv2.weight + QuantizeLinear_32_quantize_scale_node + Conv_34 + Add_42 + Relu_43, Tactic: 4871133328510103657, 284[Int8(1,64,-21,-24)], 270[Int8(1,64,-21,-24)] -> 305[Int8(1,64,-21,-24)]

pyplot代码

https://github.com/pytorch/pytorch/pull/66431/files

engine_layer_visualize.py

这是jerryzh168大神开源的Facebook内部查看engine的工具,使用pydot和graphviz来画神经网络结构图

复制代码
pip install pydot
conda install python-graphviz

需要注意我们需要输入log_file也就是刚才开启Verbose的构建信息,然后profile_file则是使用TensorRT来profile的信息,最简单的可以通过trtexec这样获取到:

复制代码
./trtexec --loadEngine=debug_int8.trt --dumpProfile --shapes=input:1x3x512x512 --exportProfile=debug_profile

然后通过上述代码生成EngineLayers_0.dot

复制代码
import pydot

graphs = pydot.graph_from_dot_file("EngineLayers_0.dot")
graph = graphs[0]
graph.write_png("trt_engine.png")

TensorRT-engine 模型输入是Float而输出是Int8。这个模型是由TensorRT官方提供的pytorch-quantization[1]工具对Pytorch模型进行量化后导出ONNX,然后再由TensorRT-8转化得到的engine,这个engine的精度是INT8。

相关推荐
失散1325 分钟前
深度学习——02 PyTorch
人工智能·pytorch·深度学习
图灵学术计算机论文辅导28 分钟前
傅里叶变换+attention机制,深耕深度学习领域
人工智能·python·深度学习·计算机网络·考研·机器学习·计算机视觉
重启的码农3 小时前
ggml 介绍(4) 计算图 (ggml_cgraph)
c++·人工智能
重启的码农3 小时前
ggml 介绍(5) GGUF 上下文 (gguf_context)
c++·人工智能·神经网络
R-G-B3 小时前
OpenCV Python——报错AttributeError: module ‘cv2‘ has no attribute ‘bgsegm‘,解决办法
人工智能·python·opencv·opencv python·attributeerror·module ‘cv2‘·no attribute
Seeklike3 小时前
diffusers学习--stable diffusion的管线解析
人工智能·stable diffusion·diffusers
数据知道3 小时前
机器翻译:模型微调(Fine-tuning)与调优详解
人工智能·自然语言处理·机器翻译
沫儿笙4 小时前
焊接机器人保护气体效率优化
人工智能·机器人
青岛前景互联信息技术有限公司4 小时前
应急救援智能接处警系统——科技赋能应急,筑牢安全防线
人工智能·物联网·智慧城市
楚韵天工5 小时前
基于多分类的工业异常声检测及应用
人工智能·深度学习·神经网络·目标检测·机器学习·分类·数据挖掘