Tensor RT学习笔记(四)

简介:

构建阶段:
在构建阶段,TensorRT采用网络定义,执行优化并生成推理引擎。
构建阶段可能需要相当长的时间,尤其是在嵌入式平台上运行时。 因此,典型的应用程序将构建一次引擎,然后将其序列化以备后用。
构建阶段在层图上执行以下优化::

  • 消除其输出不使用卷积,偏差和ReLU操作融合的图层
  • 具有足够相似参数和相同源张量的操作聚合(例如,GoogleNet v5初始模块中的1x1卷积)
  • 通过将层输出指向正确的最终目的地来合并连接层。

此外,构建阶段还在虚拟数据上运行图层以从其内核目录中选择最快的,并在适当的情况下执行加权预格式化和内存优化。
执行阶段:
在执行阶段,运行以下任务:

  • 运行时执行优化的引擎。
  • 引擎使用GPU上的输入和输出缓冲区运行推理任务。

命令行包装器( Command Line Wrapper):
样本目录中包含一个名为giexec的TensorRT命令行包装器。 它对基于随机数据的网络进行基准测试和从这些模型生成序列化引擎非常有用。
命令行参数如下所示:

Mandatory params :
--deploy = <file> Caffe deploy file
--output = <name> Output blob name(can be specified
    multiple times)
    Optional params :
--model = <file> Caffe model file(default = no model,
    random weights
    used)
    --batch = N Set batch size(default = 1)
    --device = N Set cuda device to N(default = 0)
    --iterations = N Run N iterations(default = 10)
    --avgRuns = N Set avgRuns to N - perf is measured as an
    average of
    avgRuns(default = 10)
    --workspace = N Set workspace size in megabytes(default =
        16)
    --half2 Run in paired fp16 mode(default = false)
    --int8 Run in int8 mode(default = false)
    --verbose Use verbose logging(default = false)
    --hostTime Measure host time rather than GPU time
    (default =
        false)
    --engine = <file> Generate a serialized GIE engine
    --calib = <file> Read INT8 calibration cache file

例如:

giexec --deploy=mnist.prototxt --model=mnist.caffemodel --
output=prob

如果没有提供模型,则生成随机权重。
TensorRT Lite:
包含在Python API中的是一个高度抽象的界面,称为TensorRT Lite。 TensorRT Lite API在构建引擎和执行推理时处理几乎所有事情,因此用户只需创建引擎并开始处理数据即可。
TensorRT Lite API位于tensorrt.lite中,包含一个名为Engine的类。 引擎构造函数接受模型定义以及输入和输出图层,并构建围绕它的完整引擎以进行推理。
在内部,Lite引擎为您创建记录器,TensorRT引擎,运行时和上下文,然后为引擎分配GPU内存。
自定义记录器,插件,校准器和分析器等功能可以从构造函数传递。
timg

目录
相关文章
|
5月前
|
Docker 容器
求助: 运行模型时报错module 'megatron_util.mpu' has no attribute 'get_model_parallel_rank'
运行ZhipuAI/Multilingual-GLM-Summarization-zh的官方代码范例时,报错AttributeError: MGLMTextSummarizationPipeline: module 'megatron_util.mpu' has no attribute 'get_model_parallel_rank' 环境是基于ModelScope官方docker镜像,尝试了各个版本结果都是一样的。
286 5
|
API 数据格式
TensorFlow2._:model.summary() Output Shape为multiple解决方法
TensorFlow2._:model.summary() Output Shape为multiple解决方法
185 0
TensorFlow2._:model.summary() Output Shape为multiple解决方法
|
10月前
|
数据格式
详解torch.size
详解torch.size
113 0
详解torch.size
|
11月前
|
并行计算 Python
TypeError: can‘t convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory
运行程序,出现报错信息 TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.。
243 0
|
11月前
|
PyTorch 算法框架/工具 异构计算
Pytorch出现RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor)
这个问题的主要原因是输入的数据类型与网络参数的类型不符。
180 0
|
11月前
Expected more than 1 value per channel when training, got input size torch.Size
因为模型中用了batchnomolization,训练中用batch训练的时候当前batch恰好只含一个sample,而由于BatchNorm操作需要多于一个数据计算平均值,因此造成该错误。
693 0
|
PyTorch 算法框架/工具
pytorch报错 RuntimeError: The size of tensor a (25) must match the size of tensor b (50) at non-singleton dimension 1 怎么解决?
这个错误提示表明,在进行某个操作时,张量a和b在第1个非单例维(即除了1以外的维度)上的大小不一致。例如,如果a是一个形状为(5, 5)的张量,而b是一个形状为(5, 10)的张量,则在第二个维度上的大小不匹配。
3063 0
|
TensorFlow 算法框架/工具
ValueError: Negative dimension size caused by subtracting 5 from 1 for ‘{{node le_net5/conv2d/Conv2D
ValueError: Negative dimension size caused by subtracting 5 from 1 for ‘{{node le_net5/conv2d/Conv2D
133 0
|
JSON 数据格式
ValueError: With n_samples=0, test_size=0.15 and train_size=None, the resulting train set will be em
ValueError: With n_samples=0, test_size=0.15 and train_size=None, the resulting train set will be em
423 0
ValueError: With n_samples=0, test_size=0.15 and train_size=None, the resulting train set will be em
成功解决ValueError: With n_samples=0, test_size=0.3 and train_size=None, the resulting train set will be
成功解决ValueError: With n_samples=0, test_size=0.3 and train_size=None, the resulting train set will be
成功解决ValueError: With n_samples=0, test_size=0.3 and train_size=None, the resulting train set will be