本文翻译自 Explicit Versus Implicit Batch

原文地址:
https://docs.nvidia.com/deeplearning/tensorrt/developer-guide/index.html#explicit-implicit-batch

这段时间又开始输出了,尽管写的一般般,但是比我之前的氵文强多了[捂脸笑哭],果然,人只有真的有时间去思索,才能去认真输出,好事多磨诚不欺我。

上次更新时间:June 13, 2022, 可以看下边儿的 Chapter 更新,如有这一章有更新,那本文的翻译就没啥用了

接下来,我复制一段原文,翻译一段原文


TensorRT supports two modes for specifying a network: explicit batch and implicit batch:

TensorRT 有两种指定网络的模式:explicit(显式) batch 模式 和 implicit(隐式) batch 模式

In implicit batch mode, every tensor has an implicit batch dimension and all other dimensions must have constant length. This mode was used by early versions of TensorRT, and is now deprecated but continues to be supported for backwards compatibility.

implicit batch 模式中,每一个张量有一个隐式的batch维度,而所有其他维度必须是一个常数值.
(译者注:我猜是 [-1, 3, 224, 224] 这样的shape的意思)
implicit batch 模式在早期版本的 TensorRT 经常使用,但是现在将被废弃了,不过为了向下兼容,依旧会被支持。

哦,有个新词组:backwards compatibility 向下兼容hhh

In explicit batch mode, all dimensions are explicit and can be dynamic, that is their length can change at execution time. Many new features, such as dynamic shapes and loops, are available only in this mode. It is also required by the ONNX parser.

explicit batch 模式中,所有的维度都是显式的并且是动态的,意思是在执行的时候,每一维度的长度都可以变化.
许多新特性,例如动态shapes与loops, 只有在explicit batch 模式下才可以使用.
值得一提的是,使用 ONNX parser 时,也需要该模式.

For example, consider a network that processes N images of size HxW with 3 channels, in NCHW format. At runtime, the input tensor has dimensions [N,3,H,W]. The two modes differ in how the INetworkDefinition specifies the tensor’s dimensions:

  • In explicit batch mode, the network specifies [N,3,H,W].
  • In implicit batch mode, the network specifies only [3,H,W]. The batch dimension N is implicit.

举个例子,酱紫一个场景:NNN张333通道 H×WH\times WH×W的图片,也就是 NCHW 的格式.
在运行的时候,输入张量的维度为 [N,3,H,W]. 这两种模式在 INetworkDefinition 指定张量维度时是不同的:

  • 显式(explicit batch)模式下,网络被指定为 [N,3,H,W].
  • 隐式(implicit batch)模式下,网络被指定为 [3,H,W],Batch 维度 N 是隐式指定的.

Operations that “talk across a batch” are impossible to express in implicit batch mode because there is no way to specify the batch dimension in the network. Examples of inexpressible operations in implicit batch mode:

  • reducing across the batch dimension
  • reshaping the batch dimension
  • transposing the batch dimension with another dimension

涉及到Batch维度的操作在隐式(implicit batch)模式下是无法操作的,因为在网络中无法指定batch的维度。以下是以下在隐式(implicit batch)模式下,无法表达的操作:

  • reducing across the batch dimension (在batch维度上规约,可能是 [N,3,H,W]->[1,3,H,W])
  • reshaping the batch dimension (可能是 [N,3,H,W]->[X,3,H,W])
  • transposing the batch dimension with another dimension (可能是 [N,3,H,W]->[3,N,H,W])

The exception is that a tensor can be broadcast across the entire batch, through the ITensor::setBroadcastAcrossBatch method for network inputs, and implicit broadcasting for other tensors.

当然,也有例外。通过对模型输入使用 ITensor::setBroadcastAcrossBatch 方法和其他张量使用隐式广播,一个张量可以在整个Batch中广播
(我缓缓打出一个问号,我也不太懂这是什么意思…)

Explicit batch mode erases the limitations - the batch axis is axis 0. A more accurate term for explicit batch would be “batch oblivious,” because in this mode, TensorRT attaches no special semantic meaning to the leading axis, except as required by specific operations. Indeed in explicit batch mode there might not even be a batch dimension (such as a network that handles only a single image) or there might be multiple batch dimensions of unrelated lengths (such as comparison of all possible pairs drawn from two batches).

显式批处理模式(Explicit batch mode)消除了限制—— Batch 轴是 axis 0.

显式批处理的更准确术语是“batch oblivious”,因为在这种模式下,TensorRT 对Batch引导轴没有特殊的语义含义(意思是,直接看成一个整体的张量,Batch维度没有那个语义),除非特定操作需要。

事实上,在显式批处理模式下,可能甚至没有Batch的维度(例如,只处理单张照片),或者可能存在长度不相关的多个Batch维度(例如比较从两个批处理中提取的所有可能对)。

The choice of explicit versus implicit batch must be specified when creating the INetworkDefinition, using a flag. Here is the C++ code for explicit batch mode:

IBuilder* builder = ...;
INetworkDefinition* network = builder->createNetworkV2(1U << static_cast<uint32_t>(NetworkDefinitionCreationFlag::kEXPLICIT_BATCH)))

For implicit batch, use createNetwork or pass a 0 to createNetworkV2.

在创建 INetworkDefinition 时,必须使用flag指定显式还是隐式批处理。 这是显式批处理模式的 C++ 代码:

IBuilder* builder = ...;
INetworkDefinition* network = builder->createNetworkV2(1U << static_cast<uint32_t>(NetworkDefinitionCreationFlag::kEXPLICIT_BATCH)))

当隐式初始Batch时,使用方法createNetwork 或者给 createNetworkV2方法传入 0

Here is the Python code for explicit batch mode:

builder = trt.Builder(...)
builder.create_network(1 << int(trt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH))

For implicit batch, omit the argument or pass a 0.

这里是显式Batch处理模式的Python代码:

builder = trt.Builder(...)
builder.create_network(1 << int(trt.NetworkDefinitionCreationFlag.EXPLICIT_BATCH))

对于,隐式Batch处理模式,忽略(不传入)参数或者传入一个0即可.

[翻译] TensorRT 中的 Explicit 与 Implicit Batch相关推荐

  1. C#中的Explicit和Implicit了解一下吧

    今天在研究公司项目框架的时候看到了下面的用法,public static implicit operator JsonData(int data);.貌似很久没用过这种隐式转换的写法了,因此重新温习一 ...

  2. 7.TensorRT中文版开发教程-----TensorRT中的INT8量化详解

    7. 如何使用TensorRT中的INT8 点击此处加入NVIDIA开发者计划 7.1. Introduction to Quantization TensorRT 支持使用 8 位整数来表示量化的浮 ...

  3. .net转换关键字:operator、explicit与implicit

    operator.explicit与implicit 很少用到,但也不能不知道,发现这篇写很好,转一篇 operator operator 关键字用于在类或结构声明中声明运算符.运算符声明可以采用下列 ...

  4. operator、explicit与implicit

    说这个之前先说下什么叫隐式转换和显示转换 1.所谓隐式转换,就是系统默认的转换,其本质是小存储容量数据类型自动转换为大存储容量数据类型. 例如:float f = 1.0: double d=f:这样 ...

  5. 深入理解C++中的explicit关键字

    深入理解C++中的explicit关键字 kezunhai@gmail.com http://blog.csdn.net/kezunhai C++中的explicit关键字只能用于修饰只有一个参数的构 ...

  6. VC++工作笔记0003---C++中的explicit关键字

    技术交流QQ群[JAVA,C++,Python,.NET,BigData,AI]:170933152 个人理解: 这个的作用,其实就是,防止隐式转换,因为如果有隐式转换的话,那么用起来,感觉就怪怪的, ...

  7. C++中的explicit

    explicit 前言 0x00 explicit 前言 C++中, 一个类的构造函数(或者除了第一个参数外其余参数都有默认值的多参构造函数), 承担了两个角色. 1.是个构造器 2.是个默认且隐含的 ...

  8. C++ explicit和implicit

    一.类类型转换 首先,明确什么是类类型转换, 内置类型存在定义了几种自动转换的规则,同样地,类也有定义隐式的转换规则. 若构造函数没有声明explicit且只接受一个实参,则它可以进行隐式的类类型转换 ...

  9. C++学习(八十四)explicit和implicit

    在编程过程中, 我们习惯上使用explicit或者implicit关键字实现构造函数的显式或者隐式显示. explicit关键字:只能修饰只有一个参数的构造函数,或者有多个参数,但是除第一个参数外其他 ...

最新文章

  1. LCS最长公共子序列和LIS最长上升子序列——例题剖析
  2. Spring Data JPA教程第一部分:配置
  3. VxWorks下几种定时延时方法的小结
  4. mysql 事务日志备份_事务日志备份与恢复 5
  5. redis高级命令2
  6. nodejs cluster_NodeJS下好用的Redis客户端ioredis,再推荐一个Redis可视化工具
  7. 同步带轮介绍_Synchroflex丨红色GENIII同步带丨Mulco
  8. LeetCode 852 Peak Index in a Mountain Array 解题报告
  9. c语言错误码2,平方根2.我做过C语言的一些错误
  10. Ubuntu环境下,反编译工具Apktool,Dex2jar,jd-gul,luyten安装使用
  11. VUE中nextTick( )函数思维导图
  12. CV520国产替代Ci521 13.56MHz 非接触式读写器芯片
  13. (二)注释(comment)详解
  14. python基础之字符串(七)
  15. 好用免费的电脑摄像头录视频软件分享!
  16. Auto CAD中“旋转”命令怎么使用?
  17. c8051f310烧录_C8051F烧录器-C8051F系列烧录工具下载v1.0.0.1 官方最新版-西西软件下载...
  18. 阿米洛键盘使用手册2021-02-22
  19. #ex8 C语言标准实验报告
  20. CTS测试CtsWindowManagerDeviceTestCases模块的testShowWhenLockedImeActivityAndShowSoftInput测试fail项解决方法

热门文章

  1. 在vs2013中编译soui3和一个例子
  2. Watch OS开发笔记
  3. java水果忍者7723_水果忍者java手机版下载|
  4. 80老翁谈人生(222):谈信访工作法制化
  5. 盟军敢死队2 - 3D导航网格浏览器
  6. 关于Qos中常用的CIR、PIR、CBS、PBS、EBS的解释以及用法关系
  7. 传说她是清华大学校花或重庆工商大学校花
  8. 怎么样查杀主页劫持木马,劫持浏览器首页的驱动木马解决方法
  9. 天线理论知识2——宽带天线介绍
  10. 企业管理中,如何组建数据团队