TensorRT 10.8.0
|
网络定义中的反量化层。 更多...
#include <NvInfer.h>
公共成员函数 | |
int32_t | getAxis () const noexcept |
获取量化轴。 更多... | |
void | setAxis (int32_t axis) noexcept |
设置量化轴。 更多... | |
void | setToType (DataType toType) noexcept |
设置反量化层输出类型。 更多... | |
DataType | getToType () const noexcept |
返回反量化层输出类型。 更多... | |
![]() | |
LayerType | getType () const noexcept |
返回层的类型。 更多... | |
void | setName (char const *name) noexcept |
设置层的名称。 更多... | |
char const * | getName () const noexcept |
返回层的名称。 更多... | |
int32_t | getNbInputs () const noexcept |
获取层的输入数量。 更多... | |
ITensor * | getInput (int32_t index) const noexcept |
获取与给定索引对应的层输入。 更多... | |
int32_t | getNbOutputs () const noexcept |
获取层的输出数量。 更多... | |
ITensor * | getOutput (int32_t index) const noexcept |
获取与给定索引对应的层输出。 更多... | |
void | setInput (int32_t index, ITensor &tensor) noexcept |
使用特定的张量替换此层的输入。 更多... | |
void | setPrecision (DataType dataType) noexcept |
在弱类型网络中设置此层的首选或必需的计算精度。 更多... | |
DataType | getPrecision () const noexcept |
获取此层的计算精度 更多... | |
bool | precisionIsSet () const noexcept |
是否为此层设置了计算精度 更多... | |
void | resetPrecision () noexcept |
重置此层的计算精度 更多... | |
void | setOutputType (int32_t index, DataType dataType) noexcept |
在弱类型网络中设置此层的输出类型。 更多... | |
DataType | getOutputType (int32_t index) const noexcept |
获取此层的输出类型 更多... | |
bool | outputTypeIsSet (int32_t index) const noexcept |
是否为此层设置了输出类型 更多... | |
void | resetOutputType (int32_t index) noexcept |
重置此层的输出类型 更多... | |
void | setMetadata (char const *metadata) noexcept |
为此层设置元数据。 更多... | |
char const * | getMetadata () const noexcept |
获取层的元数据。 更多... | |
保护成员函数 | |
virtual | ~IDequantizeLayer () noexcept=default |
![]() | |
virtual | ~ILayer () noexcept=default |
![]() | |
INoCopy ()=default | |
virtual | ~INoCopy ()=default |
INoCopy (INoCopy const &other)=delete | |
INoCopy & | operator= (INoCopy const &other)=delete |
INoCopy (INoCopy &&other)=delete | |
INoCopy & | operator= (INoCopy &&other)=delete |
保护属性 | |
apiv::VDequantizeLayer * | mImpl |
![]() | |
apiv::VLayer * | mLayer |
网络定义中的反量化层。
此层接受量化类型输入张量,并使用配置的 scale 和 zeroPt 输入,根据以下公式对输入进行反量化: output
= (input
- zeroPt
) * scale
第一个输入(索引 0)是要量化的张量。第二个(索引 1)和第三个(索引 2)分别是 scale 和 零点。 scale
和 zeroPt
应具有相同的维度,并且秩小于或等于 2。
zeroPt
张量是可选的,如果未设置,则假定为零。其数据类型必须与输入的数据类型相同。 zeroPt
必须仅包含零值系数,因为仅支持对称量化。对于 per-tensor 量化,scale
值必须是标量;对于 per-channel 量化,必须是 1D 张量;对于块量化(仅 DataType::kINT4 支持),则必须与输入张量的秩相同。所有 scale
系数都必须具有正值。1D scale
张量的大小必须与量化轴的大小匹配。对于块量化,scale
张量的形状必须与输入的形状匹配,但一个维度(最后一个或倒数第二个维度)除外,在该维度中发生分块。zeroPt
的大小必须与 scale
的大小匹配。
以 scale
张量结尾的子图必须是构建时常量。相同的限制适用于 zeroPt
。输出类型(如果受约束)必须约束为 DataType::kFLOAT、 DataType::kHALF 或 DataType::kBF16。输入类型(如果受约束)必须约束为 DataType::kINT8、 DataType::kFP8 或 DataType::kINT4。输出大小与输入大小相同。量化轴是相对于输入张量的维度而言的。
IDequantizeLayer 支持 DataType::kINT8、 DataType::kFP8 或 DataType::kINT4 精度,并且在实例化期间将默认为 DataType::kINT8 精度。对于强类型网络,input
数据类型必须与 zeroPt
数据类型相同。
IDequantizeLayer 支持 DataType::kFLOAT、 DataType::kHALF 或 DataType::kBF16 输出。对于强类型网络,output
数据类型是从 scale
数据类型推断出来的。
作为此层操作的示例,想象一个 4D NCHW 激活输入,可以使用单个 scale 系数(称为 per-tensor 量化)对其进行量化:对于 N 中的每个 n:对于 C 中的每个 c:对于 H 中的每个 h:对于 W 中的每个 w: output[n,c,h,w] = (input
[n,c,h,w] - zeroPt
) * scale
仅当输入扎根于 IConstantLayer (即权重)时,才支持 per-channel 反量化。激活不能按通道量化。作为 per-channel 操作的示例,想象一个 4D KCRS 权重输入,并将 K(维度 0)作为量化轴。scale 是一个系数数组,其大小与量化轴相同。对于 K 中的每个 k:对于 C 中的每个 c:对于 R 中的每个 r:对于 S 中的每个 s: output[k,c,r,s] = (input
[k,c,r,s] - zeroPt
[k]) * scale
[k]
仅对于扎根于 IConstantLayer (即权重)且具有 DataType::kINT4 的输入张量,才支持块反量化。作为块操作的示例,想象一个 2D RS 权重输入,其中 R(维度 0)作为分块轴,B 作为块大小。scale 是一个 2D 系数数组,维度为 (R//B, S)。对于 R 中的每个 r:对于 S 中的每个 s: output[r,s] = (input
[r,s] - zeroPt
[r//B, s]) * scale
[r//B, s]
scale
和 zeroPt
子图是
|
protectedvirtualdefaultnoexcept |
|
inlinenoexcept |
获取量化轴。
|
inlinenoexcept |
返回反量化层输出类型。
|
inlinenoexcept |
设置量化轴。
设置量化轴的索引(参考输入张量的维度)。如果 scale 张量具有多个系数,则轴必须是有效轴。如果 scale 张量只有一个系数(per-tensor 量化),则将忽略轴值。
|
inlinenoexcept |
设置反量化层输出类型。
toType | 输出张量的 DataType。 |
设置反量化层的输出类型。有效值是 DataType::kFLOAT 和 DataType::kHALF。如果网络是强类型的,则必须使用 setToType 来设置输出类型,并且使用 setOutputType 是错误的。否则,传递给 setOutputType 和 setToType 的类型必须相同。
|
protected |
版权所有 © 2024 NVIDIA Corporation
隐私政策 | 管理我的隐私 | 请勿出售或分享我的数据 | 服务条款 | 无障碍功能 | 公司政策 | 产品安全 | 联系我们