使用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。

相关推荐
吴佳浩15 小时前
大模型量化部署终极指南:让700亿参数的AI跑进你的显卡
人工智能·python·gpu
跨境卫士苏苏15 小时前
亚马逊AI广告革命:告别“猜心”,迎接“共创”时代
大数据·人工智能·算法·亚马逊·防关联
珠海西格电力15 小时前
零碳园区工业厂房光伏一体化(BIPV)基础规划
大数据·运维·人工智能·智慧城市·能源
土星云SaturnCloud16 小时前
不止是替代:从机械风扇的可靠性困局,看服务器散热技术新范式
服务器·网络·人工智能·ai
小马爱打代码16 小时前
Spring AI:搭建自定义 MCP Server:获取 QQ 信息
java·人工智能·spring
你们补药再卷啦16 小时前
ai(三)环境资源管理
人工智能·语言模型·电脑
飞哥数智坊17 小时前
GLM-4.6V 初探:国产 AI 能边写边自己配图了
人工智能·chatglm (智谱)
杰克逊的日记17 小时前
大模型的原理是什么
人工智能·大模型·gpu·算力
智算菩萨17 小时前
AI在智能制造中的落地:从预测维护到自适应生产调度
人工智能·制造
云和数据.ChenGuang17 小时前
AI 算力竞争下的昇腾硬件定位
人工智能